For repetitive drawing named savepoints would be great, so the initial configuration could be saved and repeatedly restored later, without additional cairo_save(). API proposal: cairo_savepoint_t* cairo_save_named (cairo_t *cr); cairo_restore_named (cairo_savepoint_t *savepoint); /* maybe free() would be sufficient */ cairo_destroy_savepoint (cairo_savepoint_t *savepoint);
Can you should us an snippet of how this will be used?
/* widget initialisation code, realize() or somesuch */ /* set up cairo */ ... self->savepoint = cairo_save_named (self->cr); /* drawing code, e.g. expose () */ for (r = 0; r < rows; r++) { for (c = 0; c < cols; c++) { x = c * self->tile_width; y = r * self->tile_height; /* no longer needed cairo_save (self->cr); */ cairo_translate (self->cr, x, y); rsvg_cairo_render (self->cr, self->svgh); cairo_restore_named (self->cr, self->savepoint); } }
I think what you need is a cairo_copy that clones cairo_t objects. cairo_save: malloc + copy cairo_restore: free cairo_restore_named: copy cairo_copy: copy
it seems that cairo_copy() is deprecated in HEAD
Basically I take that as a sign that your proposal will be rejected either. cairo_copy is a cleaner API than savepoints afterall...
Actually, cairo_copy had some huge problems and that's why we removed it. I've always known we needed a real solution for the use case and I had often imagined adding: cairo_gstate_t * cairo_get_gstate (cairo_t *cr); void cairo_set_gstate (cairo_t *cr, cairo_gstate_t *gstate); but I've never been satisfied enough with that interface to actually implement. But, now, Robert, you've made a fantastic suggestion. I really like the insight that the desired action here is a variant of save/restore. Here's the API I think I would like: cairo_state_t * cairo_save_state (cairo_t *cr); void cairo_restore_state (cairo_t *cr, cairo_state_t *state); We should talk about this on the cairo@cairographics.org mailing list. I like this enough that I'll draft a message there if nobody beats me to it. -Carl
Moved to todo.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.