diff options
author | nisanthmp <nisanth.mp@samsung.com> | 2015-12-02 12:57:34 +0530 |
---|---|---|
committer | nisanthmp <nisanth.mp@samsung.com> | 2015-12-18 13:20:33 +0530 |
commit | 629101d0a6e2af32727ca0b14acaceddb0897e6c (patch) | |
tree | 9c6820465caf673ca40d5b1a9f91c1cd90dd003a /src/cairo-gl-gradient.c | |
parent | ca3e6d75aaf63e5f77bc31975d77a20cbc5407ca (diff) | |
download | cairo-629101d0a6e2af32727ca0b14acaceddb0897e6c.tar.gz cairo-629101d0a6e2af32727ca0b14acaceddb0897e6c.tar.bz2 cairo-629101d0a6e2af32727ca0b14acaceddb0897e6c.zip |
Pattern/GL: Avoid texture creation for radial gradients
with 2 color stops
When there are only two color stops in the gradient, we can avoid
creating textures before hand, and directly calculate the gradient color
in the fragment shader. This speeds up gradient pattern rendering.
Change-Id: I758b7bc8f37293edbe546fcc4a55f71a7f3c55ae
Signed-off-by: nisanthmp <nisanth.mp@samsung.com>
Diffstat (limited to 'src/cairo-gl-gradient.c')
-rw-r--r-- | src/cairo-gl-gradient.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/src/cairo-gl-gradient.c b/src/cairo-gl-gradient.c index b204b0ba4..a6084ce84 100644 --- a/src/cairo-gl-gradient.c +++ b/src/cairo-gl-gradient.c @@ -233,7 +233,8 @@ cairo_int_status_t _cairo_gl_gradient_create (cairo_gl_context_t *ctx, unsigned int n_stops, const cairo_gradient_stop_t *stops, - cairo_gl_gradient_t **gradient_out) + cairo_gl_gradient_t **gradient_out, + cairo_pattern_type_t pat_type) { unsigned long hash; cairo_gl_gradient_t *gradient; @@ -269,36 +270,38 @@ _cairo_gl_gradient_create (cairo_gl_context_t *ctx, gradient->stops = gradient->stops_embedded; memcpy (gradient->stops_embedded, stops, n_stops * sizeof (cairo_gradient_stop_t)); - ctx->dispatch.GenTextures (1, &gradient->tex); - _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); - ctx->dispatch.BindTexture (ctx->tex_target, gradient->tex); - - data = _cairo_malloc_ab (tex_width, sizeof (uint32_t)); - if (unlikely (data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup_gradient; + if (pat_type != CAIRO_PATTERN_TYPE_RADIAL || n_stops != 2) { + ctx->dispatch.GenTextures (1, &gradient->tex); + _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); + ctx->dispatch.BindTexture (ctx->tex_target, gradient->tex); + + data = _cairo_malloc_ab (tex_width, sizeof (uint32_t)); + if (unlikely (data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup_gradient; + } + + status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width); + if (unlikely (status)) + goto cleanup_data; + + /* + * In OpenGL ES 2.0 no format conversion is allowed i.e. 'internalFormat' + * must match 'format' in glTexImage2D. + */ + if (_cairo_gl_get_flavor (&ctx->dispatch) == CAIRO_GL_FLAVOR_ES2 || + _cairo_gl_get_flavor (&ctx->dispatch) == CAIRO_GL_FLAVOR_ES3) + internal_format = GL_BGRA; + else + internal_format = GL_RGBA; + + ctx->dispatch.TexImage2D (ctx->tex_target, 0, internal_format, + tex_width, 1, 0, + GL_BGRA, GL_UNSIGNED_BYTE, data); + + free (data); } - status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width); - if (unlikely (status)) - goto cleanup_data; - - /* - * In OpenGL ES 2.0 no format conversion is allowed i.e. 'internalFormat' - * must match 'format' in glTexImage2D. - */ - if (_cairo_gl_get_flavor (&ctx->dispatch) == CAIRO_GL_FLAVOR_ES2 || - _cairo_gl_get_flavor (&ctx->dispatch) == CAIRO_GL_FLAVOR_ES3) - internal_format = GL_BGRA; - else - internal_format = GL_RGBA; - - ctx->dispatch.TexImage2D (ctx->tex_target, 0, internal_format, - tex_width, 1, 0, - GL_BGRA, GL_UNSIGNED_BYTE, data); - - free (data); - /* we ignore errors here and just return an uncached gradient */ if (unlikely (_cairo_cache_insert (&ctx->gradients, &gradient->cache_entry))) CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 1); |