[PATCH] Finish devices after their finish callback returns

Uli Schlachter psychon at znc.in
Wed Feb 9 10:41:03 PST 2011


The problem is that the finish callback might still have to work with the
device, so it can't be made unusable yet. This is in contrast to what
cairo_surface_finish() does, but when finishing a surface it's quite unlikely
that its cairo_surface_t still has to be passed around to functions outside of
the backend.

This "fixes" some problems with the xcb-surface-source test where
_cairo_surface_snapshot()-style snapshot breaks when the underlying
cairo_device_t is finished. (In the following backtrace, cairo_device_acquire
fails because the device's ->finished member is TRUE)

 #0  cairo_device_acquire (device=0x690f70) at cairo-device.c:414
 #1  0x00007ffff7b884fb in _cairo_xcb_connection_acquire (surface=0x69c610, use_shm=<value optimized out>, image_out=0x7fffffffcc58) at cairo-xcb-private.h:246
 #2  _get_image (surface=0x69c610, use_shm=<value optimized out>, image_out=0x7fffffffcc58) at cairo-xcb-surface.c:425
 #3  0x00007ffff7b893cf in _cairo_xcb_surface_acquire_source_image (abstract_surface=0x69c610, image_out=0x7fffffffcce8, image_extra=0x7fffffffcce0)
     at cairo-xcb-surface.c:561
 #4  0x00007ffff7b601d4 in _cairo_surface_acquire_source_image (surface=0x690f70, image_out=0x7fffffffcce8, image_extra=0x0) at cairo-surface.c:1458
 #5  0x00007ffff7b65dcf in _cairo_surface_snapshot_copy_on_write (surface=<value optimized out>) at cairo-surface-snapshot.c:125
 #6  0x00007ffff7b609b1 in _cairo_surface_detach_snapshot (snapshot=0x690f70) at cairo-surface.c:330
 #7  0x00007ffff7b606dc in _cairo_surface_detach_snapshots (surface=0x69c610) at cairo-surface.c:315
 #8  cairo_surface_flush (surface=0x69c610) at cairo-surface.c:1126
 #9  0x00007ffff7b6074d in cairo_surface_finish (surface=0x690f70) at cairo-surface.c:718
 #10 0x00007ffff7b881ff in _cairo_xcb_screen_finish (screen=0x691920) at cairo-xcb-screen.c:61
 #11 0x00007ffff7b8629c in _device_finish (device=0x690f70) at cairo-xcb-connection.c:546
 #12 0x0000000000446f7c in cleanup (data=0x69c370) at xcb-surface-source.c:47
 #13 0x00007ffff7b1e56a in _cairo_user_data_array_fini (array=0x693628) at cairo-array.c:390
 #14 0x00007ffff7b60868 in cairo_surface_destroy (surface=0x693600) at cairo-surface.c:651
 #15 0x0000000000447599 in draw (cr=0x7ffff7ddc288, width=<value optimized out>, height=<value optimized out>) at surface-source.c:149
 #16 0x000000000040c1c3 in cairo_test_for_target (ctx=0x7fffffffe640, target=0x669668, dev_offset=<value optimized out>, similar=<value optimized out>)
     at cairo-test.c:984
 #17 0x000000000040d997 in _cairo_test_context_run_for_target (ctx=<value optimized out>, target=<value optimized out>, similar=<value optimized out>,
     dev_offset=<value optimized out>) at cairo-test.c:1617
 #18 0x000000000040ee09 in _cairo_test_runner_draw (argc=<value optimized out>, argv=<value optimized out>) at cairo-test-runner.c:269
 #19 main (argc=<value optimized out>, argv=<value optimized out>) at cairo-test-runner.c:924

Signed-off-by: Uli Schlachter <psychon at znc.in>
---
 src/cairo-device.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/cairo-device.c b/src/cairo-device.c
index a32b971..bbedba7 100644
--- a/src/cairo-device.c
+++ b/src/cairo-device.c
@@ -296,10 +296,10 @@ cairo_device_finish (cairo_device_t *device)
 
     cairo_device_flush (device);
 
-    device->finished = TRUE;
-
     if (device->backend->finish != NULL)
 	device->backend->finish (device);
+
+    device->finished = TRUE;
 }
 slim_hidden_def (cairo_device_finish);
 
-- 
1.7.2.3


--------------060203060304070003090603
Content-Type: application/octet-stream;
 name="0001-Finish-devices-after-their-finish-callback-returns.patch.sig"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*0="0001-Finish-devices-after-their-finish-callback-returns.patc";
 filename*1="h.sig"

iQEcBAABCAAGBQJNUusiAAoJECLkKOvLj8sG0ksH/ArZHVKfSlg88jbmDBbHoAsJd/V2vlN5
N+G2vU2cAIlEpwbJZyMD8M9AFGgiwweq04pHgzOhcNb2oHYVTpLRO4l8YtzAUk5+nZWUb3In
5mZHK1Mfnb33Up6ZWnRvkW73iIaOu7pgWIoZ6ePa+6meDa7sqojWfStPtgdSe+jyiXjbRrKm
AW8wavGSLc514+yuyPzjJ33ZdprbUI9UkWNxbKOTa80AUHr6Vq/PUH+S4+jCI1Pm9DpOGFH9
Wc6Wjq/Mxy1YOQZ1M79pus+1QVCbezcK0pgtd5o/gXehRTBOZePWxA1m4pR/pIbb90xGmUP0
gjyJ1/bxLhB82zkFQRDWWZk=
--------------060203060304070003090603--


More information about the cairo mailing list