From 4cb181d985adbbf79e80ff695adc908810b41544 Mon Sep 17 00:00:00 2001 From: Henry Song Date: Tue, 29 Jan 2013 17:53:38 +0000 Subject: [PATCH] gl: do not force flush everytime uploading a glyph image to glyph cache In normal cases, we want to flush pending operations reading from the texture before modifying its contents. However during uploading of glyphs into the glyph cache, we repeatedly modify the texture as we construct the vbo (whilst referencing it for that operation). We track unused areas in the glyph cache so that if we run out of space, we can explicitly flush the pending glyphs and start afresh and avoid having to flush the operation in common case. --- src/cairo-gl-glyphs.c | 2 +- src/cairo-gl-private.h | 3 ++- src/cairo-gl-spans-compositor.c | 2 +- src/cairo-gl-surface-legacy.c | 7 ++++--- src/cairo-gl-surface.c | 16 ++++++++++------ src/cairo-gl-traps-compositor.c | 9 ++++++--- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/cairo-gl-glyphs.c b/src/cairo-gl-glyphs.c index 3f65248de..34b5d72f3 100644 --- a/src/cairo-gl-glyphs.c +++ b/src/cairo-gl-glyphs.c @@ -134,7 +134,7 @@ _cairo_gl_glyph_cache_add_glyph (cairo_gl_context_t *ctx, status = _cairo_gl_surface_draw_image (cache->surface, glyph_surface, 0, 0, glyph_surface->width, glyph_surface->height, - node->x, node->y); + node->x, node->y, FALSE); if (unlikely (status)) return status; diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h index 2b254f989..cc17c709c 100644 --- a/src/cairo-gl-private.h +++ b/src/cairo-gl-private.h @@ -437,7 +437,8 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, cairo_image_surface_t *src, int src_x, int src_y, int width, int height, - int dst_x, int dst_y); + int dst_x, int dst_y, + cairo_bool_t force_flush); static cairo_always_inline cairo_bool_t _cairo_gl_device_has_glsl (cairo_device_t *device) diff --git a/src/cairo-gl-spans-compositor.c b/src/cairo-gl-spans-compositor.c index 92e57797d..c5d97aa7d 100644 --- a/src/cairo-gl-spans-compositor.c +++ b/src/cairo-gl-spans-compositor.c @@ -311,7 +311,7 @@ draw_image_boxes (void *_dst, status = _cairo_gl_surface_draw_image (dst, image, x + dx, y + dy, w, h, - x, y); + x, y, TRUE); if (unlikely (status)) return status; } diff --git a/src/cairo-gl-surface-legacy.c b/src/cairo-gl-surface-legacy.c index 61bdd1fa7..92b27c905 100644 --- a/src/cairo-gl-surface-legacy.c +++ b/src/cairo-gl-surface-legacy.c @@ -77,7 +77,8 @@ _cairo_gl_surface_release_dest_image (void *abstract_surface, status = _cairo_gl_surface_draw_image (abstract_surface, image, 0, 0, image->width, image->height, - image_rect->x, image_rect->y); + image_rect->x, image_rect->y, + TRUE); /* as we created the image, its format should be directly applicable */ assert (status == CAIRO_STATUS_SUCCESS); @@ -126,7 +127,7 @@ _cairo_gl_surface_clone_similar (void *abstract_surface, status = _cairo_gl_surface_draw_image (clone, image_src, src_x, src_y, width, height, - 0, 0); + 0, 0, TRUE); if (status) { cairo_surface_destroy (&clone->base); return status; @@ -236,7 +237,7 @@ _cairo_gl_surface_composite (cairo_operator_t op, status = _cairo_gl_surface_draw_image (dst, image, dx, dy, width, height, - dst_x, dst_y); + dst_x, dst_y, TRUE); if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; } diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c index 922f23439..1d7515a41 100644 --- a/src/cairo-gl-surface.c +++ b/src/cairo-gl-surface.c @@ -840,7 +840,8 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, cairo_image_surface_t *src, int src_x, int src_y, int width, int height, - int dst_x, int dst_y) + int dst_x, int dst_y, + cairo_bool_t force_flush) { GLenum internal_format, format, type; cairo_bool_t has_alpha, needs_swap; @@ -882,9 +883,11 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, cpp = PIXMAN_FORMAT_BPP (src->pixman_format) / 8; - status = _cairo_gl_surface_flush (&dst->base, 0); - if (unlikely (status)) - goto FAIL; + if (force_flush) { + status = _cairo_gl_surface_flush (&dst->base, 0); + if (unlikely (status)) + goto FAIL; + } if (_cairo_gl_surface_is_texture (dst)) { void *data_start = src->data + src_y * src->stride + src_x * cpp; @@ -951,7 +954,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, src, src_x, src_y, width, height, - 0, 0); + 0, 0, force_flush); if (status == CAIRO_INT_STATUS_SUCCESS) { cairo_surface_pattern_t tmp_pattern; cairo_rectangle_int_t r; @@ -1231,7 +1234,8 @@ _cairo_gl_surface_unmap_image (void *abstract_surface, 0, 0, image->width, image->height, image->base.device_transform_inverse.x0, - image->base.device_transform_inverse.y0); + image->base.device_transform_inverse.y0, + TRUE); cairo_surface_finish (&image->base); cairo_surface_destroy (&image->base); diff --git a/src/cairo-gl-traps-compositor.c b/src/cairo-gl-traps-compositor.c index 9589ffcb8..548162be4 100644 --- a/src/cairo-gl-traps-compositor.c +++ b/src/cairo-gl-traps-compositor.c @@ -96,7 +96,8 @@ draw_image_boxes (void *_dst, status = _cairo_gl_surface_draw_image (dst, image, x + dx, y + dy, w, h, - x, y); + x, y, + TRUE); if (unlikely (status)) return status; } @@ -345,7 +346,8 @@ traps_to_operand (void *_dst, (cairo_image_surface_t *)image, 0, 0, extents->width, extents->height, - 0, 0); + 0, 0, + TRUE); cairo_surface_destroy (image); if (unlikely (status)) @@ -456,7 +458,8 @@ tristrip_to_surface (void *_dst, (cairo_image_surface_t *)image, 0, 0, extents->width, extents->height, - 0, 0); + 0, 0, + TRUE); cairo_surface_destroy (image); if (unlikely (status)) { cairo_surface_destroy (mask);