[sugar] Cairo tile engine, and accessing 565 buffers from cairo and C

Carl Worth cworth at redhat.com
Tue Apr 17 00:25:51 EDT 2007


On Mon, 16 Apr 2007 16:59:18 -0700, Don Hopkins wrote:
> I want to draw RGB tiles (alpha is not necessary) on the screen as fast
> as possible, double buffering them in 16 bit X images,

OK, so it sounds like all you need to use are 16-bit cairo xlib
surfaces, (created with cairo_surface_create_similar with
CAIRO_CONTENT_COLOR from an existing xlib surface).

>                                      Is that a valid assumption, or is
> there a fast path for drawing a surface clipped through a rectangle?

Drawing a single rectangle, (if pixel aligned---that is, just using
integer coordinates and an identity transformation), has lots of
fast-path treatment in cairo, so please take advantage of it. You can
do that with either:

	cairo_rectangle
	cairo_clip

to setup the clipping and then cairo_paint to do the painting, or
just:

	cairo_rectangle
	cairo_fill

to draw the part you want. Either way you should be hitting the same
path in cairo to ask the X server to do very efficient things.

> Currently the tile surfaces are 24 bit RGB surfaces, that I create by
> calling create_similar on the 24 bit RGB tile set I read in from a png
> file.

OK, so that's giving you image surfaces, and that's causing the slow
conversion when drawing to X. So the best would be to do that just
once, (get your data uploaded into an xlib surface, and then draw from
there).

> xHow do I create an cairo xlib surface from Python? Is there a supported
> way to call cairo_xlib_surface_create from Python?

Every cairo function should be callable from python, but I don't know
if there are python bindings for the xlib stuff you need, (like
XCreatePixmap to create the pixmap to pass to
cairo_xlib_surface_create). Fortunately, though you can just use the
GTK+ bindings.

> Is there an easy way to get ahold of the cairo surface from a cairo
> context, or from a gdk drawable, from Python?

For a cairo context you can call cairo_get_target, (probably
context.get_target in python), to get the surface it's targeting. So
that should give you the surface you need from which you can call
create_similar. And for the case of a gdk drawable you can call
gdk_cairo_create, and then cairo_get_target. (I do think it's a little
annoying that GTK+ doesn't have a direct way to create a cairo surface
from a GDK drawable, but the gdk_cairo_create;cairo_get_target
approach works fine---even if its not quite obvious).

Anyway, I hope that all works out well for you. And I'm looking
forward to hearing what kinds of performance improvements you get from
using cairo xlib surfaces of the desired depth.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.laptop.org/pipermail/devel/attachments/20070416/86efc2bd/attachment.sig>


More information about the Devel mailing list