[cairo] Scrolling/Copying

Carl Worth cworth at cworth.org
Thu Jun 23 07:26:33 PDT 2005


On Thu, 23 Jun 2005 12:45:34 GMT,  wrote:
> I'm writing a GUI library (illumination.sourceforge.net). I recently started 
> adding support for Cairo as a backend driver. Naturally I have some 
> scrolling widgets that I implemented using XCopyArea for copying the 
> visible, moving areas to reduce drawing overhead by avoiding a complete 
> redraw. Now I'm searching for an equivalent method using Cairo. How would I 
> do this? Create a surface from a visible area and draw it back? Would this 
> be performant? Is there a better solution? 

Currently, the answer I give to "What's the fastest way to do foo in
cairo?" is that that's not the right question to ask. Instead, you
should just write your code in whatever way seems most natural, and
then let us know if things aren't as fast as you expect, so we can fix
that.

So, let's say you've got a cairo_surface_t *surface and you want to
copy a rectangle, (x1,y1,width,height) to a position (x2,y2) on a
cairo_t *cr.

I would write something like the following code to do that:

	cairo_set_source_surface (cr, x2 - x1, y2 - y1);
	cairo_rectangle (cr, x2, y2, width, height);
	cairo_fill (cr);

And if you wanted to copy the entire surface, you could replace
cairo_rectangle;cairo_fill with cairo_paint(cr).

But there are several other ways that would express the same thing,
(eg. one might use cairo_translate to do the positioning). Try
whichever seems most natural, and let us know if things are slower
than they should be, (eg. we know that code like this should end up
just calling XCopyArea).

-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.freedesktop.org/archives/cairo/attachments/20050623/75833a82/attachment.pgp


More information about the cairo mailing list