[cairo-commit] 8 commits - src/cairo-gl-surface.c src/cairo-xlib-display.c src/cairo-xlib-private.h src/cairo-xlib-screen.c

Benjamin Otte company at kemper.freedesktop.org
Fri Apr 23 13:38:56 PDT 2010


 src/cairo-gl-surface.c   |   22 ++++++--------
 src/cairo-xlib-display.c |   70 +++++++++++++++++++++++++++--------------------
 src/cairo-xlib-private.h |    4 +-
 src/cairo-xlib-screen.c  |   23 ++++++++++-----
 4 files changed, 68 insertions(+), 51 deletions(-)

New commits:
commit 1687c7b7d3074de8eeea1a5c339df9a12cc38da2
Author: Benjamin Otte <otte at redhat.com>
Date:   Fri Apr 23 22:22:28 2010 +0200

    xlib: Fix display closing to work properly
    
    Previously we free()'d the cairo_device's memory which was not good at
    all. Now the code causes cairo_device_finish() instead.

diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index 6dd62cc..0b6fbeb 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -108,6 +108,14 @@ _cairo_xlib_display_discard_screens (cairo_xlib_display_t *display)
 }
 
 static void
+_cairo_xlib_display_finish (void *abstract_display)
+{
+    cairo_xlib_display_t *display = abstract_display;
+
+    display->display = NULL;
+}
+
+static void
 _cairo_xlib_display_destroy (void *abstract_display)
 {
     cairo_xlib_display_t *display = abstract_display;
@@ -201,22 +209,23 @@ _cairo_xlib_close_display (Display *dpy, XExtCodes *codes)
     if (display == NULL)
 	return 0;
 
-    /* protect the notifies from triggering XErrors */
-    XSync (dpy, False);
-    old_handler = XSetErrorHandler (_noop_error_handler);
+    if (! cairo_device_acquire (&display->base)) {
+      /* protect the notifies from triggering XErrors */
+      XSync (dpy, False);
+      old_handler = XSetErrorHandler (_noop_error_handler);
 
-    if (cairo_device_acquire (&display->base)) {
-	_cairo_xlib_display_notify (display);
-	_cairo_xlib_call_close_display_hooks (display);
-	_cairo_xlib_display_discard_screens (display);
+      _cairo_xlib_display_notify (display);
+      _cairo_xlib_call_close_display_hooks (display);
+      _cairo_xlib_display_discard_screens (display);
 
-	/* catch any that arrived before marking the display as closed */
-	_cairo_xlib_display_notify (display);
-	cairo_device_release (&display->base);
-    }
+      /* catch any that arrived before marking the display as closed */
+      _cairo_xlib_display_notify (display);
 
-    XSync (dpy, False);
-    XSetErrorHandler (old_handler);
+      XSync (dpy, False);
+      XSetErrorHandler (old_handler);
+
+      cairo_device_release (&display->base);
+    }
 
     /*
      * Unhook from the global list
@@ -250,7 +259,7 @@ static const cairo_device_backend_t _cairo_xlib_device_backend = {
     NULL,
 
     NULL, /* flush */
-    NULL, /* finish */
+    _cairo_xlib_display_finish,
     _cairo_xlib_display_destroy,
 };
 
commit 637564c562de21c17c36d192d3ab1b3fe069754b
Author: Benjamin Otte <otte at redhat.com>
Date:   Fri Apr 23 22:10:32 2010 +0200

    xlib: Fix screen device handling
    
    Add a _cairo_xlib_device_create() function that could easily be exported
    as a replacement for _cairo_xlib_display_get(). This function returns a
    cairo_device_t instead of a cairo_xlib_display_t because the display
    isn't acquired.

diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index b0a5828..6dd62cc 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -254,15 +254,22 @@ static const cairo_device_backend_t _cairo_xlib_device_backend = {
     _cairo_xlib_display_destroy,
 };
 
-cairo_status_t
-_cairo_xlib_display_get (Display *dpy,
-			 cairo_xlib_display_t **out)
+/**
+ * cairo_xlib_device_create:
+ * @dpy: the display to create the device for
+ *
+ * Gets the device belonging to @dpy, or creates it if it doesn't exist yet.
+ *
+ * Returns: the device belonging to @dpy
+ **/
+cairo_device_t *
+_cairo_xlib_device_create (Display *dpy)
 {
     cairo_xlib_display_t *display;
     cairo_xlib_display_t **prev;
+    cairo_device_t *device;
     XExtCodes *codes;
     const char *env;
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
     /* There is an apparent deadlock between this mutex and the
      * mutex for the display, but it's actually safe. For the
@@ -284,18 +291,14 @@ _cairo_xlib_display_get (Display *dpy,
 		display->next = _cairo_xlib_display_list;
 		_cairo_xlib_display_list = display;
 	    }
-	    break;
+            device = cairo_device_reference (&display->base);
+	    goto UNLOCK;
 	}
     }
 
-    if (display != NULL) {
-        cairo_device_reference (&display->base);
-	goto UNLOCK;
-    }
-
     display = malloc (sizeof (cairo_xlib_display_t));
     if (unlikely (display == NULL)) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
 	goto UNLOCK;
     }
 
@@ -326,9 +329,8 @@ _cairo_xlib_display_get (Display *dpy,
 
     codes = XAddExtension (dpy);
     if (unlikely (codes == NULL)) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
 	free (display);
-	display = NULL;
 	goto UNLOCK;
     }
 
@@ -433,10 +435,11 @@ _cairo_xlib_display_get (Display *dpy,
     display->next = _cairo_xlib_display_list;
     _cairo_xlib_display_list = display;
 
+    device = &display->base;
+
 UNLOCK:
     CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex);
-    *out = display;
-    return status;
+    return device;
 }
 
 void
diff --git a/src/cairo-xlib-private.h b/src/cairo-xlib-private.h
index 550520d..d8acf9a 100644
--- a/src/cairo-xlib-private.h
+++ b/src/cairo-xlib-private.h
@@ -112,8 +112,8 @@ struct _cairo_xlib_screen {
     cairo_array_t visuals;
 };
 
-cairo_private cairo_status_t
-_cairo_xlib_display_get (Display *display, cairo_xlib_display_t **out);
+cairo_private cairo_device_t *
+_cairo_xlib_device_create (Display *display);
 
 cairo_private void
 _cairo_xlib_display_add_screen (cairo_xlib_display_t *display,
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index 2831aca..810e484 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -307,7 +307,6 @@ _cairo_xlib_screen_destroy (cairo_xlib_screen_t *info)
 
         cairo_device_release (&display->base);
     }
-    cairo_device_destroy (info->device);
 
     _cairo_array_fini (&info->visuals);
 
@@ -320,12 +319,20 @@ _cairo_xlib_screen_get (Display *dpy,
 			cairo_xlib_screen_t **out)
 {
     cairo_xlib_display_t *display;
+    cairo_device_t *device;
     cairo_xlib_screen_t *info;
     cairo_status_t status;
 
-    status = _cairo_xlib_display_get (dpy, &display);
-    if (likely (status == CAIRO_STATUS_SUCCESS))
-	status = _cairo_xlib_display_get_screen (display, screen, &info);
+    device = _cairo_xlib_device_create (dpy);
+    status = device->status;
+    if (unlikely (status))
+        goto CLEANUP_DEVICE;
+
+    status =  _cairo_xlib_display_acquire (device, &display);
+    if (unlikely (status))
+        goto CLEANUP_DEVICE;
+
+    status = _cairo_xlib_display_get_screen (display, screen, &info);
     if (unlikely (status))
 	goto CLEANUP_DISPLAY;
 
@@ -341,7 +348,7 @@ _cairo_xlib_screen_get (Display *dpy,
     }
 
     CAIRO_REFERENCE_COUNT_INIT (&info->ref_count, 2); /* Add one for display cache */
-    info->device = &display->base;
+    info->device = device;
     info->screen = screen;
     info->has_render = FALSE;
     info->has_font_options = FALSE;
@@ -366,10 +373,12 @@ _cairo_xlib_screen_get (Display *dpy,
     _cairo_xlib_display_add_screen (display, info);
 
     *out = info;
-    return CAIRO_STATUS_SUCCESS;
 
   CLEANUP_DISPLAY:
-    cairo_device_destroy ((cairo_device_t *) display);
+    cairo_device_release (&display->base);
+
+  CLEANUP_DEVICE:
+    cairo_device_destroy (device);
     return status;
 }
 
commit 49b52a8946cbd5f785f71069313e4a204358887b
Author: Benjamin Otte <otte at redhat.com>
Date:   Thu Apr 22 21:56:31 2010 +0200

    gl: Make drawing to windows work again
    
    The correct MIN/MAG_FILTER wasn't set.

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 24a5142..1c1982c 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -822,6 +822,8 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
 	glGenTextures (1, &tex);
 	glActiveTexture (GL_TEXTURE0);
 	glBindTexture (ctx->tex_target, tex);
+	glTexParameteri (ctx->tex_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri (ctx->tex_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	glTexImage2D (ctx->tex_target, 0, internal_format, width, height, 0,
 		      format, type, src->data + src_y * src->stride + src_x * cpp);
 
commit 3efbc0c5c850d0cb5c5af5bcabbc7293670ea355
Author: Benjamin Otte <otte at redhat.com>
Date:   Tue Apr 20 21:58:59 2010 +0200

    gl: Only unref a surface if it exists
    
    Note: This will likely work for NULL clones, but I prefer not
    dereferencing NULLs. That gives people a wrong understanding of the code
    (i.e. me).

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 1f6fd9b..24a5142 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -881,7 +881,8 @@ fail:
 
     _cairo_gl_context_release (ctx);
 
-    cairo_surface_destroy (&clone->base);
+    if (clone)
+        cairo_surface_destroy (&clone->base);
 
     return CAIRO_STATUS_SUCCESS;
 }
commit 64662be4ef3851d21658e5fdb2efb6806b45eba8
Author: Benjamin Otte <otte at redhat.com>
Date:   Thu Apr 22 22:05:03 2010 +0200

    gl: Use GLfloat instead of float in gl*Array() functions

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index b878235..1f6fd9b 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -797,7 +797,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
 	}
     } else {
 	GLuint tex;
-	float vertices[8], texcoords[8];
+	GLfloat vertices[8], texcoords[8];
 
 	if (ctx->using_glsl) {
 	    cairo_gl_shader_program_t *program;
@@ -857,11 +857,11 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
 	    texcoords[7] = height;
 	}
 
-	glVertexPointer (2, GL_FLOAT, sizeof (float) * 2, vertices);
+        glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 2, vertices);
 	glEnableClientState (GL_VERTEX_ARRAY);
 
 	glClientActiveTexture (GL_TEXTURE0);
-	glTexCoordPointer (2, GL_FLOAT, sizeof (float) * 2, texcoords);
+	glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 2, texcoords);
 	glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
 	glDrawArrays (GL_QUADS, 0, 4);
commit e4f84f97b2f5d37bc1fb7dd510df733053ffe624
Author: Benjamin Otte <otte at redhat.com>
Date:   Tue Apr 20 21:33:50 2010 +0200

    gl: Don't acquire the gl context twice

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 8152d25..b878235 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -798,11 +798,6 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
     } else {
 	GLuint tex;
 	float vertices[8], texcoords[8];
-	cairo_gl_context_t *ctx;
-
-	status = _cairo_gl_context_acquire (dst->base.device, &ctx);
-	if (unlikely (status))
-	    goto fail;
 
 	if (ctx->using_glsl) {
 	    cairo_gl_shader_program_t *program;
@@ -879,8 +874,6 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
 	    _cairo_gl_use_program (NULL);
 	glDeleteTextures (1, &tex);
 	glDisable (ctx->tex_target);
-
-	_cairo_gl_context_release (ctx);
     }
 
 fail:
commit e40a2d1f5eeea139e29c27e38495b9c0bf9e39a1
Author: Benjamin Otte <otte at redhat.com>
Date:   Thu Apr 22 22:03:29 2010 +0200

    gl: Use correct type when uploading images

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index f366102..8152d25 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -767,7 +767,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
 	glTexParameteri (ctx->tex_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	glTexSubImage2D (ctx->tex_target, 0,
 			 dst_x, dst_y, width, height,
-			 format, GL_UNSIGNED_BYTE,
+			 format, type,
 			 src->data + src_y * src->stride + src_x * cpp);
 
 	/* If we just treated some rgb-only data as rgba, then we have to
commit 55cf323f963bbcc11bcc290eaf71656e1ba91efd
Author: Benjamin Otte <otte at redhat.com>
Date:   Thu Apr 22 21:58:01 2010 +0200

    gl: fix typo in comment

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 8067e9e..f366102 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1356,7 +1356,7 @@ _cairo_gl_pattern_texture_setup (cairo_gl_composite_operand_t *operand,
 
 
     /* Translate the matrix from
-     * (unnormalized src -> unnormalized src) to
+     * (unnormalized dst -> unnormalized src) to
      * (unnormalized dst -> normalized src)
      */
     if (ctx->tex_target == GL_TEXTURE_RECTANGLE_EXT) {


More information about the cairo-commit mailing list