[cairo] Notification when a surface gets dirtied

Federico Mena Quintero federico at ximian.com
Thu Nov 17 10:45:38 PST 2005


Hi,

Short story:  I'd like to have a way to get notified when a surface gets
written to.  For example,

  typedef (* SurfaceModifiedFunc) (cairo_surface_t *surface,
                                   Rectangle        dirty_rect,
                                   void            *user_data);

  void cairo_surface_set_dirty_notify_func (cairo_surface_t    *surface,
                                            SurfaceModifiedFunc callback,
                                            void               *user_data);

Does that make sense?  It's similar in spirit to XDAMAGE, but for Cairo surfaces.

Long story:  I'm doing some brainstorming on how to make it easy for
newbie programmers to write programs for X, or GTK+ in particular.
Novice programmers have a *terrible* time wrapping their minds around
the fact that you must wait for an ExposeEvent to paint their stuff;
they really want something like this:

  w = create_window (640, 480);
  fill_rectangle (w, 0, 0, 640, 480, make_color (white));
  draw_line (w, 50, 50, 100, 100, make_color (red));
  show_window (w);

I.e. they want very simple, retained graphics.

I don't have anything implemented yet, but my current plan is to add a
way for Cairo to notify me when a surface is dirtied, so that I can then
repaint my window at a reasonable time.

That "reasonable time", of course, is an interesting question.  I don't
know yet what that API for newbies would look like.  The event loop is
obviously a good place to repaint the window internally.  Also, the
dirty-notification function could repaint every N milliseconds to
preserve the illusion that the screen gets updated more or less as soon
as you issue a drawing call.

  Federico



More information about the cairo mailing list