[cairo] Does Cairo Use Hardware Acceleration?

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Tue Oct 9 22:02:25 PDT 2012


Let me answer your questions one-by-one

1. build cairo GL - yes, you need to build from source "./configure --prefix=your_install_directory --enable-gl=yes"

2. cairo GL on windows - there is a binding of wgl and cairo.  However, it has not been (to best of my knowledge) paid as much attention as on other platforms.  So it is very likely it is not optimized, for example, cairo_gl_device_set_thread_aware() has no effect on wgl.  In addition, I believe OpenGL on windows only expose GL 1.0 API, other GL calls must go through getprocaddress(), this makes cairo/gl not compilable at this moment (someone on the mailing mentioned/fixed it, but I did not keep a close eye on it).

3. cairo GL on OSX - there is no native binding to apple's objc-based opengl context.  The only way is running cairo under the X that uses glx.  You need to use macport to get mesa driver, and other utlilities, such as pixman, fontconfig, freetype, libz, among others.  There is, however, a quartz backend for cairo that you can use.  However, cairo quartz may not be as fast as GL backend and extend_pad/reflect does not work because quartz does not support them.   

4. compiling/linking with cairo - I will use Linux as example - "gcc -o app app.c `pkg-config --libs --cflags cairo gtk+-2.0` should do it

5. pango-cairo - I don't know about it, maybe someone else knows?

6. gtk/gdk with cairo - the provided gtk API for cairo are all software based.  However, you can roll your own dice:

  /* create a 480x800 window gl surface in cairo */
   cairo_surface_t *window_surface = cairo_gl_surface_create_for_window (device,
                GDK_WINDOW_XID (gtk_widget_get_window(widget)), 480, 800);
 /* once you done drawing, swap buffer */
   cairo_gl_surface_swapbuffers (window_surface);

Hope these help

Henry
________________________________________
From: cairo-bounces+henry.song=samsung.com at cairographics.org [cairo-bounces+henry.song=samsung.com at cairographics.org] on behalf of Anthony Walter [sysrpl at gmail.com]
Sent: Tuesday, October 09, 2012 8:43 PM
To: Henry (Yu) Song - SISA
Cc: cairo at cairographics.org
Subject: Re: [cairo] Does Cairo Use Hardware Acceleration?

Thank you for that useful information. It's interesting that you
mention cairo_gl_surface. I did some google searching on that function
and found little information about it. I've done a bit of OpenGL
development  before including creating and managing GL contexts, so
some of what you mentioned is familiar to me.

My source code Cairo import unit doesn't define any OpenGL related
routines. I am going to go ahead an assume I would need to build Cairo
from source with the proper flags to enable an OpenGL render path. Can
you tell me if the Cairo OpenGL render path would work on Windows and
OSX in addition to Linux? Also, when building Cairo is the result and
only dependency I need either libcairo.so or libcairo.a or a static
lib on Linux, and libcairo.dll on Windows?

Also, I am using Pango with the Pango-Cairo bridge functions such as
"pango_cairo_create_layout". Does  Pango work equally well with an
OpenGL based Cairo context?

As for my current work, so far I am using a Gtk+ window and creating a
cairo context with the GdkDrawable* passed to the expose event like
so:

  cr = gdk_cairo_create(drawable);
  //.. cairo draw code here
  cairo_destroy(cr);

Or alternately painting to the window using a loop where I invoke code
similar to the following:

  GdkRegion* region = gdk_drawable_get_clip_region(drawable);
  gdk_window_begin_paint_region(drawable, region);
  gdk_region_destroy(region);
  cr = gdk_cairo_create(drawable);
  //.. cairo draw code here
  cairo_destroy(cr);
  gdk_window_end_paint(drawable);

I am running Ubuntu 12.04 with compositing effects on and proprietary
drivers installed. My test laptop has an Nvidia 8600M video card in
it, which was a mid range mobile graphics card in 2008. The rendering
seems to vary with scene complexity and some effects or rendering
types seem to slow down the render more than others.

>From what you said, it sounds like possible hardware is not being used
with approach, but maybe it is? Could anyone shed a more definitive
light on the two paths I described above?

Thanks again.
--
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list