[cairo] GL invert image for non-texture GL surface that does not support GLX_MESA_pack_invert

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Tue Mar 13 13:21:44 PDT 2012


Author: Henry Song <henry.song at samsung.com>
Date:   Tue Mar 13 11:22:37 2012 -0700

    gl invert non-texture image when map_to_image for non-texture gl surface
    that does not support GLX_MESA_pack_invert extension

diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 35ea149..bcc3d57 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1088,6 +1088,32 @@ _cairo_gl_surface_map_to_image (void      *abstract_surface,
 	    _cairo_surface_create_in_error (status);
     }
 
+    /* We must invert image if it is non-texture surface and it does
+     * not support GL_MESA_pack_invert
+     */
+    if (! _cairo_gl_surface_is_texture (surface) && ! invert) {
+	cairo_t *inv_cr = NULL;
+
+	int inv_width = cairo_image_surface_get_width (&image->base);
+	int inv_height = cairo_image_surface_get_height (&image->base);
+	cairo_format_t inv_format = cairo_image_surface_get_format (&image->base);
+	int inv_stride = cairo_format_stride_for_width (inv_format,
+							inv_width);
+
+	cairo_image_surface_t *inv_image = (cairo_image_surface_t *)
+		cairo_image_surface_create_for_data (NULL, inv_format,
+						     inv_width,
+						     inv_height,
+						     -inv_stride);
+	inv_cr = cairo_create (&inv_image->base);
+	cairo_set_source_surface (inv_cr, &image->base, 0, 0);
+	cairo_paint (inv_cr);
+	
+	cairo_destroy (inv_cr);
+	cairo_surface_destroy (&image->base);
+	image = inv_image;
+    }
+
     return &image->base;
 }


More information about the cairo mailing list