[cairo-commit] src/cairo-xlib-surface.c

Carl Worth cworth at kemper.freedesktop.org
Mon Mar 19 15:11:04 PDT 2007


 src/cairo-xlib-surface.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

New commits:
diff-tree eb472a9d9cbaea754907a261b459693b9c27ac79 (from d27c42cc3fcd4376fc69aa68d997e6077c3eca90)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Mar 19 13:13:41 2007 -0700

    xlib: Prefer surface->format over surface->visual for identifying masks
    
    The original test for 'if (surface->visual)' dates back to a very old
    assumption that if the xlib surface was created with an XRenderFormat
    that the surface->visual field would be set to NULL. This assumption
    was broken years ago with the following commit:
    
    	0c05b23b3165ec6908c28f56b3446cf43dff44a2
    
    This fixes the crash reported here:
    
    	BadMatch when running gnome-terminal with the murrine-0.51 gtk engine
    	https://bugs.freedesktop.org/show_bug.cgi?id=10250

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 49bdaae..7f1392d 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -610,24 +610,27 @@ _get_image_surface (cairo_xlib_surface_t
     _swap_ximage_to_native (ximage);
 
     /*
-     * Compute the pixel format masks from either a visual or a
-     * XRenderFormat, failing we assume the drawable is an
-     * alpha-only pixmap as it could only have been created
-     * that way through the cairo_xlib_surface_create_for_bitmap
-     * function.
+     * Compute the pixel format masks from either a XrenderFormat or
+     * else from a visual; failing that we assume the drawable is an
+     * alpha-only pixmap as it could only have been created that way
+     * through the cairo_xlib_surface_create_for_bitmap function.
      */
-    if (surface->visual) {
+    if (surface->xrender_format) {
+	masks.bpp = ximage->bits_per_pixel;
+	masks.red_mask =   (unsigned long) surface->xrender_format->direct.redMask
+	    << surface->xrender_format->direct.red;
+	masks.green_mask = (unsigned long) surface->xrender_format->direct.greenMask
+	    << surface->xrender_format->direct.green;
+	masks.blue_mask =  (unsigned long) surface->xrender_format->direct.blueMask
+	    << surface->xrender_format->direct.blue;
+	masks.alpha_mask = (unsigned long) surface->xrender_format->direct.alphaMask
+	    << surface->xrender_format->direct.alpha;
+    } else if (surface->visual) {
 	masks.bpp = ximage->bits_per_pixel;
 	masks.alpha_mask = 0;
 	masks.red_mask = surface->visual->red_mask;
 	masks.green_mask = surface->visual->green_mask;
 	masks.blue_mask = surface->visual->blue_mask;
-    } else if (surface->xrender_format) {
-	masks.bpp = ximage->bits_per_pixel;
-	masks.red_mask = (unsigned long)surface->xrender_format->direct.redMask << surface->xrender_format->direct.red;
-	masks.green_mask = (unsigned long)surface->xrender_format->direct.greenMask << surface->xrender_format->direct.green;
-	masks.blue_mask = (unsigned long)surface->xrender_format->direct.blueMask << surface->xrender_format->direct.blue;
-	masks.alpha_mask = (unsigned long)surface->xrender_format->direct.alphaMask << surface->xrender_format->direct.alpha;
     } else {
 	masks.bpp = ximage->bits_per_pixel;
 	masks.red_mask = 0;


More information about the cairo-commit mailing list