[cairo] API proposal: Damage Tracking

Gerdus van Zyl gerdusvanzyl at gmail.com
Thu May 1 01:00:41 PDT 2008


Would it not be too slow with many objects since cairo needs to compute the
geometry to extract a rectangle? Something related I would really like is
cairo_end_damage_tracking_mask that returns a hit mask for intersection
testing (eg. mouse click).
I have always though cairo could do with a semi-official separate minimal
scenegraph since the above scenario is so common.

~Gerdus

On Thu, May 1, 2008 at 2:58 AM, Soeren Sandmann <sandmann at daimi.au.dk>
wrote:

> Hi,
>
> In a canvas/toolkit type project I am playing around with, I need the
> ability to track the 'damage' done by painting with a cairo context.
>
> This is useful to generate repaint areas, ie., the area that the
> application needs to repaint. When something happens that causes a
> canvas item to change it appearance, damage tracking would allow the
> application to simply do this:
>
>        static void
>        invalidate (Item *item, cairo_t *cr)
>        {
>                cairo_begin_damage_tracking (cr);
>
>                <paint the item>
>
>                damaged = cairo_end_damage_tracking (cr);
>
>                add_to_repaint_region (damaged);
>
>                free (damaged);
>        }
>
>        void
>        on_event ()
>        {
>                cairo_t *cr = create_cr();
>
>                /* Invalidate old position */
>                invalidate (item, cr);
>
>                <update item information>
>
>                /* Invalidate new position */
>                invalidate (item, cr);
>
>                cairo_destroy();
>        }
>
> The big benefit is that this frees the application from keeping track
> of the exact region that is covering the item. Instead it can just
> compute it as needed.
>
> Currently the best an application can do is call
> cairo_stroke/fill_extents() after before each paint operation, but (a)
> this is inconvenient, (b) the extent rectangles are too pessimistic in
> many cases, and (c) it may not be possible to do if the painting is
> being done by a library.
>
> So I am proposing this new API:
>
>        void                        cairo_begin_damage_tracking (cr);
>        cairo_rectangle_list_t *    cairo_end_damage_tracking (cr);
>
> Cairo would keep track of a stack of rectangle lists corresponding to
> the nesting level. Whenever cairo_end_damage_tracking() is called, a
> the topmost list is returned after a copy of it was unioned with the
> next list on the stack.
>
> Open question: In the proposal above, nothing is actually painted when
> tracking damage. I think it could potentially be useful to allow
> damage tracking and painting to go on at the same time, say for
> applications that would like to keep track of the last thing they
> painted.
>
> A way to accomplish that would be to simply have
> begin_damage_tracking() not turn off painting, but then also provide
> begin/end_disable_painting() calls.
>
>
> Soren
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080501/7590d426/attachment-0001.htm 


More information about the cairo mailing list