[cairo-commit] src/cairo-gl-glyphs.c src/cairo-gl-private.h src/cairo-gl-surface.c

Martin Robinson mrobinson at kemper.freedesktop.org
Fri Jan 25 14:41:41 PST 2013


 src/cairo-gl-glyphs.c  |   16 ++++++++--------
 src/cairo-gl-private.h |    6 ++++++
 src/cairo-gl-surface.c |   38 +++++++++++++++++++++++++++++++-------
 3 files changed, 45 insertions(+), 15 deletions(-)

New commits:
commit 1e3424cfd1fea3f9aa2b1c8af4bb72239a94f365
Author: Henry Song <henry.song at samsung.com>
Date:   Tue Jan 22 14:54:38 2013 -0800

    gl: Use GL_ALPHA textures for CAIRO_CONTENT_ALPHA glyph caching
    
    It's safe to us GL_ALPHA for glyph caching surfaces, since Cairo only
    uses them for texture uploading. This saves a little bit of memory.

diff --git a/src/cairo-gl-glyphs.c b/src/cairo-gl-glyphs.c
index 03aeb67..3f65248 100644
--- a/src/cairo-gl-glyphs.c
+++ b/src/cairo-gl-glyphs.c
@@ -199,16 +199,16 @@ cairo_gl_context_get_glyph_cache (cairo_gl_context_t *ctx,
     }
 
     if (unlikely (cache->surface == NULL)) {
-        cairo_surface_t *surface;
+	cairo_surface_t *surface;
 
-        surface = cairo_gl_surface_create (&ctx->base,
-                                           content,
-                                           GLYPH_CACHE_WIDTH,
-                                           GLYPH_CACHE_HEIGHT);
-        if (unlikely (surface->status))
-            return surface->status;
+	surface = _cairo_gl_surface_create_scratch_for_caching (ctx,
+							        content,
+							        GLYPH_CACHE_WIDTH,
+							        GLYPH_CACHE_HEIGHT);
+	if (unlikely (surface->status))
+	    return surface->status;
 
-        _cairo_surface_release_device_reference (surface);
+	_cairo_surface_release_device_reference (surface);
 
 	cache->surface = (cairo_gl_surface_t *)surface;
 	cache->surface->operand.texture.attributes.has_component_alpha =
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 9366309..a75afa7 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -785,6 +785,12 @@ _cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
 				  int			height);
 
 cairo_private cairo_surface_t *
+_cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx,
+					      cairo_content_t content,
+					      int width,
+					      int height);
+
+cairo_private cairo_surface_t *
 _cairo_gl_pattern_to_source (cairo_surface_t *dst,
 			     const cairo_pattern_t *pattern,
 			     cairo_bool_t is_mask,
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 4ca876c..922f234 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -424,11 +424,12 @@ _cairo_gl_surface_create_scratch_for_texture (cairo_gl_context_t   *ctx,
     return &surface->base;
 }
 
-cairo_surface_t *
-_cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
-				  cairo_content_t	content,
-				  int			width,
-				  int			height)
+static cairo_surface_t *
+_create_scratch_internal (cairo_gl_context_t *ctx,
+			  cairo_content_t content,
+			  int width,
+			  int height,
+			  cairo_bool_t for_caching)
 {
     cairo_gl_surface_t *surface;
     GLenum format;
@@ -456,8 +457,13 @@ _cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
 	format = GL_RGBA;
 	break;
     case CAIRO_CONTENT_ALPHA:
-	/* We want to be trying GL_ALPHA framebuffer objects here. */
-	format = GL_RGBA;
+	/* When using GL_ALPHA, compositing doesn't work properly, but for
+	 * caching surfaces, we are just uploading pixel data, so it isn't
+	 * an issue. */
+	if (for_caching)
+	    format = GL_ALPHA;
+	else
+	    format = GL_RGBA;
 	break;
     case CAIRO_CONTENT_COLOR:
 	/* GL_RGB is almost what we want here -- sampling 1 alpha when
@@ -478,6 +484,24 @@ _cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
     return &surface->base;
 }
 
+cairo_surface_t *
+_cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
+				  cairo_content_t	content,
+				  int			width,
+				  int			height)
+{
+    return _create_scratch_internal (ctx, content, width, height, FALSE);
+}
+
+cairo_surface_t *
+_cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx,
+					      cairo_content_t content,
+					      int width,
+					      int height)
+{
+    return _create_scratch_internal (ctx, content, width, height, TRUE);
+}
+
 static cairo_status_t
 _cairo_gl_surface_clear (cairo_gl_surface_t  *surface,
                          const cairo_color_t *color)


More information about the cairo-commit mailing list