From 5045155de6fa7fcafc345365320f97d6a87ee063 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 9 Jan 2012 09:43:31 +0000 Subject: [PATCH] xlib: Do not upload inplace if the image does not match the surface format Currently we perform the conversion using XPutPixel which is hideously slow and so it is faster to create a new surface that matches the format correctly, upload and allow X to perform the conversion. In other words disable the "fast" path for format mismatches. Based on a patch by Ginn Chen Bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=716462 Signed-off-by: Chris Wilson --- src/cairo-xlib-core-compositor.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cairo-xlib-core-compositor.c b/src/cairo-xlib-core-compositor.c index fe871ab40..191c9b93f 100644 --- a/src/cairo-xlib-core-compositor.c +++ b/src/cairo-xlib-core-compositor.c @@ -268,6 +268,19 @@ static cairo_bool_t image_upload_box (cairo_box_t *box, void *closure) x, y) == CAIRO_STATUS_SUCCESS; } +static cairo_bool_t +surface_matches_image_format (cairo_xlib_surface_t *surface, + cairo_image_surface_t *image) +{ + cairo_format_masks_t format; + + return (_pixman_format_to_masks (image->pixman_format, &format) && + (format.alpha_mask == surface->a_mask || surface->a_mask == 0) && + (format.red_mask == surface->r_mask || surface->r_mask == 0) && + (format.green_mask == surface->g_mask || surface->g_mask == 0) && + (format.blue_mask == surface->b_mask || surface->b_mask == 0)) +} + static cairo_status_t upload_image_inplace (cairo_xlib_surface_t *dst, const cairo_pattern_t *source, @@ -291,6 +304,9 @@ upload_image_inplace (cairo_xlib_surface_t *dst, if (image->depth != dst->depth) return CAIRO_INT_STATUS_UNSUPPORTED; + if (! surface_matches_image_format (dst, image)) + return CAIRO_INT_STATUS_UNSUPPORTED; + /* XXX subsurface */ if (! _cairo_matrix_is_integer_translation (&source->matrix,