[cairo-commit] 3 commits - src/cairo-gl-composite.c src/cairo-gl-glyphs.c src/cairo-gl-private.h src/cairo-gl-surface.c
Benjamin Otte
company at kemper.freedesktop.org
Mon May 17 09:58:29 PDT 2010
src/cairo-gl-composite.c | 5 -
src/cairo-gl-glyphs.c | 2
src/cairo-gl-private.h | 2
src/cairo-gl-surface.c | 223 ++++++++++-------------------------------------
4 files changed, 53 insertions(+), 179 deletions(-)
New commits:
commit 7f22372edf10f5eab53ea132d9226f6d5b49eb9a
Author: Benjamin Otte <otte at redhat.com>
Date: Mon May 17 14:20:17 2010 +0200
gl: Get rid of src and mask argument to composite_init()
This was thought of as a way to detect self-painting, but it's better to
check that later in _begin() - when we check it.
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 8491821..c492d2c 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -1370,8 +1370,6 @@ _cairo_gl_composite_init (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup,
cairo_operator_t op,
cairo_gl_surface_t *dst,
- const cairo_pattern_t *src,
- const cairo_pattern_t *mask,
cairo_bool_t assume_component_alpha,
const cairo_rectangle_int_t *rect)
{
diff --git a/src/cairo-gl-glyphs.c b/src/cairo-gl-glyphs.c
index d9107bc..7d187c5 100644
--- a/src/cairo-gl-glyphs.c
+++ b/src/cairo-gl-glyphs.c
@@ -287,7 +287,7 @@ _render_glyphs (cairo_gl_surface_t *dst,
_cairo_scaled_font_freeze_cache (scaled_font);
status = _cairo_gl_composite_init (ctx, &setup,
- op, dst, source, NULL,
+ op, dst,
TRUE, glyph_extents);
if (unlikely (status))
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 1f03d41..2a1007e 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -277,8 +277,6 @@ _cairo_gl_composite_init (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup,
cairo_operator_t op,
cairo_gl_surface_t *dst,
- const cairo_pattern_t *src,
- const cairo_pattern_t *mask,
cairo_bool_t has_component_alpha,
const cairo_rectangle_int_t *rect);
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index b7bf14a..531159b 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -971,7 +971,7 @@ _cairo_gl_surface_composite (cairo_operator_t op,
return status;
status = _cairo_gl_composite_init (ctx, &setup,
- op, dst, src, mask,
+ op, dst,
mask && mask->has_component_alpha,
&rect);
if (unlikely (status))
@@ -1098,15 +1098,14 @@ _cairo_gl_surface_fill_rectangles (void *abstract_dst,
if (unlikely (status))
return status;
- _cairo_pattern_init_solid (&solid, color, CAIRO_CONTENT_COLOR_ALPHA);
-
status = _cairo_gl_composite_init (ctx, &setup,
- op, dst, &solid.base, NULL,
+ op, dst,
FALSE,
/* XXX */ NULL);
if (unlikely (status))
goto CLEANUP;
+ _cairo_pattern_init_solid (&solid, color, CAIRO_CONTENT_COLOR_ALPHA);
status = _cairo_gl_composite_set_source (ctx, &setup, &solid.base,
0, 0,
0, 0,
@@ -1302,7 +1301,7 @@ _cairo_gl_surface_create_span_renderer (cairo_operator_t op,
status = _cairo_gl_composite_init (renderer->ctx,
&renderer->setup,
- op, dst, src, NULL,
+ op, dst,
FALSE, extents);
if (unlikely (status))
goto FAIL;
commit 75f15babed8409fb1eaae514411de01d57072c80
Author: Benjamin Otte <otte at redhat.com>
Date: Mon May 17 14:17:47 2010 +0200
gl: Implement fill_rectangles with composite
Tiny performance improvement, but a lot less code.
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 9592534..b7bf14a 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1081,188 +1081,66 @@ _cairo_gl_surface_composite_trapezoids (cairo_operator_t op,
}
static cairo_int_status_t
-_cairo_gl_surface_fill_rectangles_fixed (void *abstract_surface,
- cairo_operator_t op,
- const cairo_color_t *color,
- cairo_rectangle_int_t *rects,
- int num_rects)
+_cairo_gl_surface_fill_rectangles (void *abstract_dst,
+ cairo_operator_t op,
+ const cairo_color_t *color,
+ cairo_rectangle_int_t *rects,
+ int num_rects)
{
-#define N_STACK_RECTS 4
- cairo_gl_surface_t *surface = abstract_surface;
- GLfloat vertices_stack[N_STACK_RECTS*4*2];
- GLfloat colors_stack[N_STACK_RECTS*4*4];
+ cairo_gl_surface_t *dst = abstract_dst;
+ cairo_solid_pattern_t solid;
cairo_gl_context_t *ctx;
- int i;
- GLfloat *vertices;
- GLfloat *colors;
cairo_status_t status;
+ cairo_gl_composite_t setup;
+ int i;
- if (! _cairo_gl_operator_is_supported (op))
- return UNSUPPORTED ("unsupported operator");
-
- status = _cairo_gl_context_acquire (surface->base.device, &ctx);
+ status = _cairo_gl_context_acquire (dst->base.device, &ctx);
if (unlikely (status))
return status;
- _cairo_gl_context_set_destination (ctx, surface);
- _cairo_gl_set_operator (surface, op, FALSE);
-
- if (num_rects > N_STACK_RECTS) {
- vertices = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 2);
- colors = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 4);
- if (!vertices || !colors) {
- _cairo_gl_context_release (ctx);
- free (vertices);
- free (colors);
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
- }
- } else {
- vertices = vertices_stack;
- colors = colors_stack;
- }
-
- /* This should be loaded in as either a blend constant and an operator
- * setup specific to this, or better, a fragment shader constant.
- */
- colors[0] = color->red * color->alpha;
- colors[1] = color->green * color->alpha;
- colors[2] = color->blue * color->alpha;
- colors[3] = color->alpha;
- for (i = 1; i < num_rects * 4; i++) {
- colors[i*4 + 0] = colors[0];
- colors[i*4 + 1] = colors[1];
- colors[i*4 + 2] = colors[2];
- colors[i*4 + 3] = colors[3];
- }
-
- for (i = 0; i < num_rects; i++) {
- vertices[i * 8 + 0] = rects[i].x;
- vertices[i * 8 + 1] = rects[i].y;
- vertices[i * 8 + 2] = rects[i].x + rects[i].width;
- vertices[i * 8 + 3] = rects[i].y;
- vertices[i * 8 + 4] = rects[i].x + rects[i].width;
- vertices[i * 8 + 5] = rects[i].y + rects[i].height;
- vertices[i * 8 + 6] = rects[i].x;
- vertices[i * 8 + 7] = rects[i].y + rects[i].height;
- }
-
- glVertexPointer (2, GL_FLOAT, sizeof (GLfloat)*2, vertices);
- glEnableClientState (GL_VERTEX_ARRAY);
- glColorPointer (4, GL_FLOAT, sizeof (GLfloat)*4, colors);
- glEnableClientState (GL_COLOR_ARRAY);
-
- glDrawArrays (GL_QUADS, 0, 4 * num_rects);
-
- glDisableClientState (GL_COLOR_ARRAY);
- glDisableClientState (GL_VERTEX_ARRAY);
- glDisable (GL_BLEND);
-
- _cairo_gl_context_release (ctx);
- if (vertices != vertices_stack)
- free (vertices);
- if (colors != colors_stack)
- free (colors);
-
- return CAIRO_STATUS_SUCCESS;
-#undef N_STACK_RECTS
-}
-
-static cairo_int_status_t
-_cairo_gl_surface_fill_rectangles_glsl (void *abstract_surface,
- cairo_operator_t op,
- const cairo_color_t *color,
- cairo_rectangle_int_t *rects,
- int num_rects)
-{
-#define N_STACK_RECTS 4
- cairo_gl_surface_t *surface = abstract_surface;
- GLfloat vertices_stack[N_STACK_RECTS*4*2];
- cairo_gl_context_t *ctx;
- int i;
- GLfloat *vertices;
- cairo_status_t status;
-
- if (! _cairo_gl_operator_is_supported (op))
- return UNSUPPORTED ("unsupported operator");
+ _cairo_pattern_init_solid (&solid, color, CAIRO_CONTENT_COLOR_ALPHA);
- status = _cairo_gl_context_acquire (surface->base.device, &ctx);
+ status = _cairo_gl_composite_init (ctx, &setup,
+ op, dst, &solid.base, NULL,
+ FALSE,
+ /* XXX */ NULL);
if (unlikely (status))
- return status;
+ goto CLEANUP;
- if (num_rects > N_STACK_RECTS) {
- vertices = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 2);
- if (!vertices) {
- _cairo_gl_context_release (ctx);
- free (vertices);
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
- }
- } else {
- vertices = vertices_stack;
- }
+ status = _cairo_gl_composite_set_source (ctx, &setup, &solid.base,
+ 0, 0,
+ 0, 0,
+ 0, 0);
+ if (unlikely (status))
+ goto CLEANUP;
- _cairo_gl_context_set_destination (ctx, surface);
- _cairo_gl_set_operator (surface, op, FALSE);
+ status = _cairo_gl_composite_set_mask (ctx, &setup, NULL,
+ 0, 0,
+ 0, 0,
+ 0, 0);
+ if (unlikely (status))
+ goto CLEANUP;
- _cairo_gl_set_shader (ctx, &ctx->fill_rectangles_shader);
- _cairo_gl_shader_bind_vec4 (ctx,
- &ctx->fill_rectangles_shader,
- "color",
- color->red * color->alpha,
- color->green * color->alpha,
- color->blue * color->alpha,
- color->alpha);
+ status = _cairo_gl_composite_begin (ctx, &setup);
+ if (unlikely (status))
+ goto CLEANUP;
for (i = 0; i < num_rects; i++) {
- vertices[i * 8 + 0] = rects[i].x;
- vertices[i * 8 + 1] = rects[i].y;
- vertices[i * 8 + 2] = rects[i].x + rects[i].width;
- vertices[i * 8 + 3] = rects[i].y;
- vertices[i * 8 + 4] = rects[i].x + rects[i].width;
- vertices[i * 8 + 5] = rects[i].y + rects[i].height;
- vertices[i * 8 + 6] = rects[i].x;
- vertices[i * 8 + 7] = rects[i].y + rects[i].height;
+ _cairo_gl_composite_emit_rect (ctx, &setup,
+ rects[i].x,
+ rects[i].y,
+ rects[i].x + rects[i].width,
+ rects[i].y + rects[i].height,
+ 0);
}
- glVertexPointer (2, GL_FLOAT, sizeof (GLfloat)*2, vertices);
- glEnableClientState (GL_VERTEX_ARRAY);
-
- glDrawArrays (GL_QUADS, 0, 4 * num_rects);
-
- glDisableClientState (GL_VERTEX_ARRAY);
- glDisable (GL_BLEND);
- glUseProgramObjectARB (0);
+ _cairo_gl_composite_end (ctx, &setup);
+ CLEANUP:
+ _cairo_gl_composite_fini (ctx, &setup);
_cairo_gl_context_release (ctx);
- if (vertices != vertices_stack)
- free (vertices);
-
- return CAIRO_STATUS_SUCCESS;
-#undef N_STACK_RECTS
-}
-
-
-static cairo_int_status_t
-_cairo_gl_surface_fill_rectangles (void *abstract_surface,
- cairo_operator_t op,
- const cairo_color_t *color,
- cairo_rectangle_int_t *rects,
- int num_rects)
-{
- cairo_gl_surface_t *surface = abstract_surface;
- if (_cairo_gl_device_has_glsl (surface->base.device)) {
- return _cairo_gl_surface_fill_rectangles_glsl(abstract_surface,
- op,
- color,
- rects,
- num_rects);
- } else {
- return _cairo_gl_surface_fill_rectangles_fixed(abstract_surface,
- op,
- color,
- rects,
- num_rects);
- }
+ return status;
}
typedef struct _cairo_gl_surface_span_renderer {
commit e7c5b4f79fa24b75026c93bc9244115d2ee23930
Author: Benjamin Otte <otte at redhat.com>
Date: Mon May 17 13:56:22 2010 +0200
gl: make _set_mask() accept NULL
That way, it can be used to unset the mask.
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 98e52f9..8491821 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -511,6 +511,9 @@ _cairo_gl_composite_set_mask (cairo_gl_context_t *ctx,
{
_cairo_gl_operand_destroy (&setup->mask);
setup->has_component_alpha = pattern && pattern->has_component_alpha;
+ if (pattern == NULL)
+ return CAIRO_STATUS_SUCCESS;
+
return _cairo_gl_operand_init (ctx, &setup->mask, pattern,
setup->dst,
src_x, src_y,
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index b5f33e3..9592534 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -984,14 +984,12 @@ _cairo_gl_surface_composite (cairo_operator_t op,
if (unlikely (status))
goto CLEANUP;
- if (mask != NULL) {
- status = _cairo_gl_composite_set_mask (ctx, &setup, mask,
- mask_x, mask_y,
- dst_x, dst_y,
- width, height);
- if (unlikely (status))
- goto CLEANUP;
- }
+ status = _cairo_gl_composite_set_mask (ctx, &setup, mask,
+ mask_x, mask_y,
+ dst_x, dst_y,
+ width, height);
+ if (unlikely (status))
+ goto CLEANUP;
status = _cairo_gl_composite_begin (ctx, &setup);
if (unlikely (status))
More information about the cairo-commit
mailing list