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

"Henry (Yu) Song - SISA" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <3955FA337689574EB32F94B12A7E6E9E0B4E10B8@ex10mail>
Author: Henry Song <[email protected]>
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;
 }
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.