From 11f9c1963e796e6947f686acef54decefa3f4fcd Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 19 Mar 2007 13:13:41 -0700 Subject: [PATCH] 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 is an attempt to fix a cairo crash reported here: BadMatch when running gnome-terminal with the murrine-0.51 gtk engine https://bugs.freedesktop.org/show_bug.cgi?id=10250 --- src/cairo-xlib-surface.c | 27 +++++++++++++++------------ 1 files changed, 15 insertions(+), 12 deletions(-) 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 *surface, _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; -- 1.5.0.rc1.gf4b6c