summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Song <henry.song@samsung.com>2013-01-22 14:54:38 -0800
committerMartin Robinson <mrobinson@igalia.com>2013-01-25 14:09:18 -0800
commit1e3424cfd1fea3f9aa2b1c8af4bb72239a94f365 (patch)
tree8d415da7ad21c9bc611d9bf6c09493dd997fdd2c
parenta44b8bd70683a92d862b11c2d7359ce2b0a6a968 (diff)
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.
-rw-r--r--src/cairo-gl-glyphs.c16
-rw-r--r--src/cairo-gl-private.h6
-rw-r--r--src/cairo-gl-surface.c38
3 files changed, 45 insertions, 15 deletions
diff --git a/src/cairo-gl-glyphs.c b/src/cairo-gl-glyphs.c
index 03aeb67a..3f65248d 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 9366309a..a75afa7e 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 4ca876cd..922f2343 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)