Re: cairo drawing commands to gdk_invalidate_region

Thanks, but this is not what I am looking for.

Here is a description of my flow, which might e.g. be used to draw a rubber band box:
  1. motion event calls update()
  2. update() calls draw() in order to get regions to expose.
  3. update() calls gdk_invalidate_region() based on output from draw
  4. exposure-event callback calls draw() to carry out the drawing for each region
I.e. draw() is called twice with different purposes. (That's part of the beauty of the generic cairo_t structure). The first call in 2 should be used to determine where we are drawing. The second call in 4 is used to do the drawing.

update() holds a list of rectangle corresponding to the old draw() and the new draw() and expose both of these. (The exposure of the old commands are needed to restore the background).

Your example indeed shows how to carry out the drawing as response of a exposure-event (point 4 above), but doesn't answer my question of what regions to invalidate (point 2-3).

Meanwhile I already have working code in which the user chooses what regions to expose, but I would like to make it automatic to make this unnecessary. Note that I assume that exposing the entire widget for each motion event is too slow.


On Tue, Aug 17, 2010 at 11:14, Claudio Saavedra <csaavedra gnome org> wrote:
On Tue, 2010-08-17 at 10:35 +0300, Dov Grobgeld wrote:
> Assume I have a routine:
>     int draw(cairo_t *cr)
> used to draw an overlay in a GdkWindow.
> In order to minimize redrawing, I would like to get the minimal (up to
> some accuracy to be determined) set of GdkRegion's that encompasses
> all the drawing of draw().
> I thought of doing this by creating a low resolution cairo image
> surface that I pass to draw() and check if pixels are "dirty" in which
> case it indicates that the corresponding rectangle in the source
> GdkWindow needs to redrawn.
> Is there a better method?

Just call

 gdk_cairo_region (cr, event->region);
 cairo_clip (cr);

right after creating the context, and after that, draw as if you didn't
need to care about the dirty regions at all. The clipping will take care
of the rest. This assumes that you only draw as a response to your
expose-event handler, of course.


Claudio Saavedra <csaavedra gnome org>

gtk-devel-list mailing list
gtk-devel-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]