Bug 5686 - RFE - named savepoints
Summary: RFE - named savepoints
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 1.0.2
Hardware: x86 (IA32) Linux (All)
: high enhancement
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-23 03:53 UTC by Robert Staudinger
Modified: 2008-10-08 05:48 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Robert Staudinger 2006-01-23 03:53:38 UTC
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);
Comment 1 Behdad Esfahbod 2006-01-23 04:16:08 UTC
Can you should us an snippet of how this will be used?
Comment 2 Robert Staudinger 2006-01-23 05:26:45 UTC
/* 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);
  }
}
Comment 3 Behdad Esfahbod 2006-01-23 05:37:44 UTC
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
Comment 4 Robert Staudinger 2006-01-23 06:05:51 UTC
it seems that cairo_copy() is deprecated in HEAD
Comment 5 Behdad Esfahbod 2006-01-23 06:22:10 UTC
Basically I take that as a sign that your proposal will be rejected either. 
cairo_copy is a cleaner API than savepoints afterall...
Comment 6 Carl Worth 2006-01-24 13:08:43 UTC
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
Comment 7 Chris Wilson 2008-10-08 05:48:10 UTC
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.