[cairo-commit] 2 commits - src/cairo-device.c src/cairo-surface.c test/gl-surface-source.c

Chris Wilson ickle at kemper.freedesktop.org
Thu May 6 09:07:12 PDT 2010


 src/cairo-device.c       |    9 +++++++--
 src/cairo-surface.c      |    4 ++--
 test/gl-surface-source.c |   26 +++++++++++---------------
 3 files changed, 20 insertions(+), 19 deletions(-)

New commits:
commit 91dfee420c3e9d85e5cd4f2cec6dc708c0e471a2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu May 6 17:03:56 2010 +0100

    device: Reorder finalization so that user data is destroyed last.
    
    As the user is likely to attach the underlying resources to the device
    for automatic collection upon finalization, it is important that the
    user data is then destroy last (so that those resources are still
    available in the surface and device cleanup routines).

diff --git a/src/cairo-device.c b/src/cairo-device.c
index 1e5bf0f..f8a499e 100644
--- a/src/cairo-device.c
+++ b/src/cairo-device.c
@@ -182,6 +182,8 @@ slim_hidden_def (cairo_device_finish);
 void
 cairo_device_destroy (cairo_device_t *device)
 {
+    cairo_user_data_array_t user_data;
+
     if (device == NULL ||
 	CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count))
     {
@@ -194,12 +196,15 @@ cairo_device_destroy (cairo_device_t *device)
 
     cairo_device_finish (device);
 
-    _cairo_user_data_array_fini (&device->user_data);
-
     assert (device->mutex_depth == 0);
     CAIRO_MUTEX_FINI (device->mutex);
 
+    user_data = device->user_data;
+
     device->backend->destroy (device);
+
+    _cairo_user_data_array_fini (&user_data);
+
 }
 slim_hidden_def (cairo_device_destroy);
 
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index e676b92..cf7e054 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -592,11 +592,11 @@ cairo_surface_destroy (cairo_surface_t *surface)
     /* paranoid check that nobody took a reference whilst finishing */
     assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count));
 
-    cairo_device_destroy (surface->device);
-
     _cairo_user_data_array_fini (&surface->user_data);
     _cairo_user_data_array_fini (&surface->mime_data);
 
+    cairo_device_destroy (surface->device);
+
     free (surface);
 }
 slim_hidden_def(cairo_surface_destroy);
commit 2658d7ef5f8f7e06929f4b1cae64e5312db24ec4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu May 6 17:02:39 2010 +0100

    test/gl-surface-source: Attach GLXContext to device user data.
    
    As we actually use the GLXContext to create the device, we only want to
    free those resources upon the final unreference of the device (and not
    the initial surface).

diff --git a/test/gl-surface-source.c b/test/gl-surface-source.c
index 60f8591..09d4d9c 100644
--- a/test/gl-surface-source.c
+++ b/test/gl-surface-source.c
@@ -32,8 +32,6 @@
 struct closure {
     Display *dpy;
     GLXContext ctx;
-
-    cairo_device_t *device;
 };
 
 static void
@@ -41,9 +39,6 @@ cleanup (void *data)
 {
     struct closure *arg = data;
 
-    cairo_device_finish (arg->device);
-    cairo_device_destroy (arg->device);
-
     glXDestroyContext (arg->dpy, arg->ctx);
     XCloseDisplay (arg->dpy);
 
@@ -65,6 +60,7 @@ create_source_surface (int size)
     XVisualInfo *visinfo;
     GLXContext ctx;
     struct closure *arg;
+    cairo_device_t *device;
     cairo_surface_t *surface;
     Display *dpy;
 
@@ -89,21 +85,21 @@ create_source_surface (int size)
     arg = xmalloc (sizeof (struct closure));
     arg->dpy = dpy;
     arg->ctx = ctx;
-    arg->device = cairo_glx_device_create (dpy, ctx);
-    surface = cairo_gl_surface_create (arg->device,
-				       CAIRO_CONTENT_COLOR_ALPHA,
-				       size, size);
-
-    if (cairo_surface_set_user_data (surface,
-				     (cairo_user_data_key_t *) create_source_surface,
-				     arg,
-				     cleanup))
+    device = cairo_glx_device_create (dpy, ctx);
+    if (cairo_device_set_user_data (device,
+				    (cairo_user_data_key_t *) cleanup,
+				    arg,
+				    cleanup))
     {
-	cairo_surface_destroy (surface);
 	cleanup (arg);
 	return NULL;
     }
 
+    surface = cairo_gl_surface_create (device,
+				       CAIRO_CONTENT_COLOR_ALPHA,
+				       size, size);
+    cairo_device_destroy (device);
+
     return surface;
 }
 


More information about the cairo-commit mailing list