OpenGL vs Cairo (performance, scaling quality)

#1

nosmoothing-opengl-cairo
Sample: https://ibb.co/cCCXjb2
I read a little before posting about it.
On sample is a bitmap scaled down, where first image is no smoothing (terrible), second is OpenGL (bad), third is Cairo (perfect).
On other hand, when using Cairo, it is unacceptably slow, while OpenGL is fast enough.
Additionally, when checking memory usage (RAM on windows target), Cairo version process used 40 MB, while OpenGL 60 MB (maybe uses some more caching in RAM that improves performance, or maybe just libraries are larger).
I read that Cairo works in software mode, so uses CPU instead of GPU, but when I go to Cairo official website, then I read “Cairo is designed to produce consistent output on all output media while taking advantage of display hardware acceleration when available”.
My question is, are there some extra parameters during compilation that can affect Cairo or OpenGL, or maybe some access from haxe code to change something in a runtine (I already have antialiasing=“4” in project.xml, stage.quality = StageQuality.BEST;, and tried lower FPS stage.frameRate = 24;)?
Is there a way to force Cairo to use hardware acceleration so it will work much faster, or force OpenGL to scale in better quality by using higher antialiasing or something?
Technically, original Flash had both, performance and scaling quality, at least in my cases.
Maybe I missed something, and yes, I know that images can be prepared in various sizes in graphic editor, but I asking about dynamic scaling part only.
Any tips?
I am still a big fan of Haxe + OpenFL!

0 Likes

#2

OpenGL uses a linear smoothing algorithm (when bitmap.smoothing is true) which looks best when objects are scaled 1 > (scale) > 0.5. Smaller or larger scales do not work as well.

You can try shrinking the size in software first:

var bitmapData = new BitmapData(newWidth, newHeight, true, 0);
var matrix = new Matrix();
matrix.scale(newScale, newScale);
bitmapData.draw(bitmap, matrix);

bitmap.bitmapData = bitmapData;

…then allow the rendering to continue with OpenGL?

Cairo supports an OpenGL backend that we have not tested. There may be ways to experiment with accelerating Cairo if we used different Cairo surface types or built the library differently – I would be happy to chat if someone is digging deeper into these things

0 Likes