[cairo] Does Cairo Use Hardware Acceleration?

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Tue Oct 9 18:57:28 PDT 2012

The short and definite answer to your question is yes - cairo can use GL backend if you use cairo_gl_surface.  

Now the long answer

1. depending on your driver quality and how you use gl_surface, you might not see performance boost vs. image-backend, reasons for that varies from driver to driver.  The most important is because of GL context switches, unlike mesa-based driver, proprietary drivers usually have very expensive gl context switches (glXMakeCurrent) - thus you are advised to add cairo_gl_device_set_thread_aware (device, FALSE) to avoid unnecessary context switch if-and-only-if your app meets the following conditions

    A. Your app is not multi-threading that multiple threads will access a same GL context
    B. You generate a GL Context that that only cairo is the only one that uses that GL context - if you mix cairo/gl and raw gl calls, you cannot set thread aware to false.

2. Now once that is done, you need also consider your driver supports MSAA vs non-MSAA (glxinfo -v | grep multiSample to get idea of driver MSAA supports).  If your driver does not support MSAA, you are likely using a slow path for rendering in GL, and you might see slow performance vs image-based cairo. 

3. If your driver supports MSAA, then you need to add GLX_SAMPLES, n (where n can be 2, 4, 8, 16), GLX_SAMPL_BUFFERS, 1, and GLX_STENCIL_SIZE, 1 to your glx attributes when you initialize GL context.

4. There is now two paths in cairo/gl supprt - one is using span/traps compositor that line-scanning of geometries which is slow.  The second path is msaa compositor that takes advantage of MSAA capability of driver.  Unfortunately, msaa compositor has not been entriely upstreamed.  If you want to get it,  please visit http://code.google.com/p/cairogles - we are trying to sync it with cairo-1.12.4 at this moment, so please use release-1.12.4 branch once you checked out.  It has a little problem with gles, but I think GL works fine.

5. To use msaa compositor, please set your env CAIRO_GL_COMPOSITOR=msaa - we hope once it is upstreamed, it can be a default compositor.

Since you mentioned you are using nvidia driver (not nouveau) - I am pretty sure that you should use msaa compositor that can give quite fast performance (I don't have nvidia, but on fglrx it is fast).

Now you also mention that gnome - gnome uses cairo, but I am not sure it uses cairo_image_surface or cairo_gl_surface - I think it is the former, in that case, you won't see acceleration.

Your last question - how much of graphics acceleration other API uses? - I am not sure I understand it.  I can be of help if you clarify though.

Hope this helps

From: cairo-bounces+hsong=sisa.samsung.com at cairographics.org [cairo-bounces+hsong=sisa.samsung.com at cairographics.org] on behalf of Anthony Walter [sysrpl at gmail.com]
Sent: Tuesday, October 09, 2012 5:59 PM
To: cairo at cairographics.org
Subject: [cairo] Does Cairo Use Hardware Acceleration?

My question mirrored here with videos: http://www.codebot.org/cross/?doc=9588

I am working on an open source project that provides a unified and
simplified cross platform 2D vector animation programming interface.
It is powered by different back ends on different platforms. On
Windows it uses Direct2D when available with a fallback to GDI+. On
Linux when Gnome is available it user uses Cairo (I am also
considering a QPainter back end for KDE). On OSX and iOS the my API
implementation uses Quartz 2D.

My question is related to describing the various back ends to other
programmers using my system.

Would I be truthful if I were to describe to users of my API that the
Cairo implementation is hardware accelerated?

That is, does Cairo on a Linux distribution, such as Ubuntu 12.04,
with proprietary Nvidia drivers installed and the correct hardware
installed make much of the GPU (OpenGL) any if at all? And if so,
which portions, functions, percentage of Cairo use the GPU to
accelerate rendering? the more information I can get, the better
documentation I can provide to users of my project, and I'd be very
appreciative of your honest assessment of Cairo's performance using
different hardware.

The answers you give me might help me better describe how Cairo works.
I don't want to start off the release of my open source project by
feeding users of my project bad information. Also, if anyone can feed
me some links or information about how much of graphics hardware the
other API users, I'd appreciate that as well.

Thank you.
cairo mailing list
cairo at cairographics.org

More information about the cairo mailing list