[patch] gl/traps: ensure RGBA surface before upload image to texture for GLES2

"Henry (Yu) Song - SISA" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <3955FA337689574EB32F94B12A7E6E9E246DF2EB@sisaex01sj>
From 5f5ef3030db287dd2a925b80a22cf3012c5b84d9 Mon Sep 17 00:00:00 2001
From: Henry Song <[email protected]>
Date: Thu, 27 Sep 2012 12:19:40 -0700
Subject: [PATCH] gl/traps: we need to create RGBA format image when uploading
 it to texture for GLES2.

---
 src/cairo-gl-traps-compositor.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/cairo-gl-traps-compositor.c b/src/cairo-gl-traps-compositor.c
index a87fd16..13b1d4f 100644
--- a/src/cairo-gl-traps-compositor.c
+++ b/src/cairo-gl-traps-compositor.c
@@ -50,6 +50,7 @@
 #include "cairo-image-surface-private.h"
 #include "cairo-spans-compositor-private.h"
 #include "cairo-surface-backend-private.h"
+#include "cairo-surface-offset-private.h"
 
 static cairo_int_status_t
 acquire (void *abstract_dst)
@@ -281,6 +282,8 @@ traps_to_operand (void *_dst,
     pixman_format_code_t pixman_format;
     pixman_image_t *pixman_image;
     cairo_surface_t *image, *mask;
+    cairo_surface_t *orig_image = NULL; 
+    cairo_surface_t *rgba_image = NULL;
     cairo_surface_pattern_t pattern;
     cairo_status_t status;
 
@@ -300,12 +303,43 @@ traps_to_operand (void *_dst,
 	return image->status;
     }
 
+    /* GLES2 only supports RGB/RGBA when uploading */
+    if (_cairo_gl_get_flavor () == CAIRO_GL_FLAVOR_ES) {
+	cairo_pattern_t *pat = cairo_pattern_create_for_surface (image);
+	int image_width = ((cairo_image_surface_t *) image)->width;
+	int image_height = ((cairo_image_surface_t *) image)->height;
+	pixman_format_code_t rgba_format = PIXMAN_r8g8b8a8;
+
+	if (_cairo_is_little_endian ())
+	    rgba_format = PIXMAN_a8b8g8r8;
+
+	rgba_image = 
+	    _cairo_image_surface_create_with_pixman_format (NULL,
+							    rgba_format,
+							    image_width,
+							    image_height,
+							    -1);
+	status = _cairo_surface_offset_paint (rgba_image, 0, 0,
+					      CAIRO_OPERATOR_SOURCE,
+					      pat, NULL);
+	if (unlikely (status)) {
+	    cairo_surface_destroy (image);
+	    cairo_surface_destroy (rgba_image);
+	    return status;
+	}
+	
+	orig_image = image;
+	image = rgba_image;
+    }
+
     mask = _cairo_surface_create_similar_scratch (_dst,
 						  CAIRO_CONTENT_COLOR_ALPHA,
 						  extents->width,
 						  extents->height);
     if (unlikely (mask->status)) {
 	cairo_surface_destroy (image);
+	if (orig_image)
+	    cairo_surface_destroy (orig_image);
 	return mask->status;
     }
 
@@ -315,6 +349,9 @@ traps_to_operand (void *_dst,
 					   extents->width, extents->height,
 					   0, 0);
     cairo_surface_destroy (image);
+    if (orig_image)
+	cairo_surface_destroy (orig_image);
+
     if (unlikely (status))
 	goto error;
 
-- 
1.7.9.5
-- 
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.