[cairo] Does Cairo Use Hardware Acceleration?
chris at chris-wilson.co.uk
Wed Oct 10 02:42:07 PDT 2012
On Tue, 9 Oct 2012 20:59:33 -0400, Anthony Walter <sysrpl at gmail.com> wrote:
> 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?
Yes. cairo supports a number of backends, which it uses is under your
cairo-image: pure CPU rasterisation
cairo-gl: use OpenGL for GPU compositing and some rasterisation, depends
upon driver quality
cairo-xlib: use XRender to send commands to X which uses the GPU for
compositing and some rasterisation, depends upon driver quality
cairo-quartz: use Quartz to offload some commands to the GPU
cairo-win32: uses image + GDI blitting, one day should have a d2d
On the Linux desktop, both Nvidia and Intel have very good XRender
drivers which are much faster than trying to feed cairo through OpenGL.
fglrx (catalyst) is not good at cairo-gl or cairo-xlib. The open source
EXA drivers (nouveau and radeon) are more or less equally bad at cairo-gl
Depending on the mix of operations, using a cairo-image and SHM
transport provides a very good baseline for performance.
> 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.
cairo uses XRender to talk to X. This means cairo has to convert paths
into trapezoids, which is computationally very expensive. Then Nvidia
uses a trapezoid shader along with shaders to describe the sources to
composite that onto the destination using the GPU. So more or less
everything after converting the path into geometry is accelerated by
Nvidia. Both Nvidia and Intel would like to feed the path to X so that
we can offload the geometry generation as well.
cairo-gl has some more flexibility and can offload more of the geometry
generation (or rather bypass such generation by using alternative
algorithms). cairo-gl also uses shaders to describe all the source
patterns, within the OpenGL limits. It does not yet try to split
operations that exceed those limits (and so will incur sw fallbacks in
those surprisingly regular corner-cases).
> 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.
QPainter is taking the approach of dropping acceleration on X and using
their own CPU raster engine. (For their sakes, I hope it is much
improved since the last time I looked at it.)
Basically, it already sounds like you have invented your own Cairo, and
would make an invaluable contributor :) Please do have a look at what
Cairo offers and your suggestions are very welcome.
Chris Wilson, Intel Open Source Technology Centre
More information about the cairo