summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-12-05 15:03:43 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2011-12-05 17:17:26 +0000
commit16038150b3691d4d4a320a727afc107cd0937ac6 (patch)
treebe32ab8370181e7764bb0f0fbd48f86026bee911
parent65cd7d3bebe12e0db61b2739a7950d1ed49c20f3 (diff)
gl: Use the embedded operand to allow passing sources around
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--src/Makefile.sources1
-rw-r--r--src/cairo-gl-glyphs.c7
-rw-r--r--src/cairo-gl-operand.c79
-rw-r--r--src/cairo-gl-private.h16
-rw-r--r--src/cairo-gl-source.c106
-rw-r--r--src/cairo-gl-spans-compositor.c75
-rw-r--r--src/cairo-gl-surface.c2
-rw-r--r--src/cairo-gl-traps-compositor.c59
8 files changed, 136 insertions, 209 deletions
diff --git a/src/Makefile.sources b/src/Makefile.sources
index 11826317..67e3537d 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -369,6 +369,7 @@ cairo_gl_sources = cairo-gl-composite.c \
cairo-gl-msaa-compositor.c \
cairo-gl-spans-compositor.c \
cairo-gl-traps-compositor.c \
+ cairo-gl-source.c \
cairo-gl-surface.c
cairo_glesv2_headers = $(cairo_gl_headers)
diff --git a/src/cairo-gl-glyphs.c b/src/cairo-gl-glyphs.c
index 395222c6..ae2d1812 100644
--- a/src/cairo-gl-glyphs.c
+++ b/src/cairo-gl-glyphs.c
@@ -217,13 +217,6 @@ _cairo_gl_font_fini (cairo_scaled_font_private_t *_priv,
free (priv);
}
-static inline cairo_gl_operand_t *
-source_to_operand (cairo_surface_t *surface)
-{
- cairo_gl_source_t *source = (cairo_gl_source_t *) surface;
- return &source->operand;
-}
-
static cairo_status_t
render_glyphs (cairo_gl_surface_t *dst,
int dst_x, int dst_y,
diff --git a/src/cairo-gl-operand.c b/src/cairo-gl-operand.c
index d494eb98..9b53b2ff 100644
--- a/src/cairo-gl-operand.c
+++ b/src/cairo-gl-operand.c
@@ -154,7 +154,6 @@ _cairo_gl_subsurface_operand_init (cairo_gl_operand_t *operand,
cairo_surface_subsurface_t *sub;
cairo_gl_surface_t *surface;
cairo_surface_attributes_t *attributes;
- cairo_matrix_t m;
sub = (cairo_surface_subsurface_t *) src->surface;
@@ -168,37 +167,19 @@ _cairo_gl_subsurface_operand_init (cairo_gl_operand_t *operand,
surface = (cairo_gl_surface_t *) sub->target;
- attributes = &operand->texture.attributes;
-
- operand->type = CAIRO_GL_OPERAND_TEXTURE;
- operand->texture.surface =
- (cairo_gl_surface_t *) cairo_surface_reference (&surface->base);
- operand->texture.tex = surface->tex;
-
/* Translate the matrix from
* (unnormalized src -> unnormalized src) to
* (unnormalized dst -> unnormalized src)
*/
+ *operand = surface->operand;
+
+ attributes = &operand->texture.attributes;
attributes->matrix = src->base.matrix;
attributes->matrix.x0 += sub->extents.x;
attributes->matrix.y0 += sub->extents.y;
-
- /* Translate the matrix from
- * (unnormalized dst -> unnormalized src) to
- * (unnormalized dst -> normalized src)
- */
- if (_cairo_gl_device_requires_power_of_two_textures (dst->base.device)) {
- cairo_matrix_init_scale (&m,
- 1.0,
- 1.0);
- } else {
- cairo_matrix_init_scale (&m,
- 1.0 / surface->width,
- 1.0 / surface->height);
- }
cairo_matrix_multiply (&attributes->matrix,
&attributes->matrix,
- &m);
+ &surface->operand.texture.attributes.matrix);
attributes->extend = src->base.extend;
attributes->filter = src->base.filter;
@@ -216,7 +197,6 @@ _cairo_gl_surface_operand_init (cairo_gl_operand_t *operand,
const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src;
cairo_gl_surface_t *surface;
cairo_surface_attributes_t *attributes;
- cairo_matrix_t m;
surface = (cairo_gl_surface_t *) src->surface;
if (surface->base.type != CAIRO_SURFACE_TYPE_GL)
@@ -230,35 +210,12 @@ _cairo_gl_surface_operand_init (cairo_gl_operand_t *operand,
return CAIRO_INT_STATUS_UNSUPPORTED;
}
- attributes = &operand->texture.attributes;
-
- operand->type = CAIRO_GL_OPERAND_TEXTURE;
- operand->texture.surface =
- (cairo_gl_surface_t *) cairo_surface_reference (&surface->base);
- operand->texture.tex = surface->tex;
-
- /* Translate the matrix from
- * (unnormalized src -> unnormalized src) to
- * (unnormalized dst -> unnormalized src)
- */
- attributes->matrix = src->base.matrix;
+ *operand = surface->operand;
- /* Translate the matrix from
- * (unnormalized dst -> unnormalized src) to
- * (unnormalized dst -> normalized src)
- */
- if (_cairo_gl_device_requires_power_of_two_textures (dst->base.device)) {
- cairo_matrix_init_scale (&m,
- 1.0,
- 1.0);
- } else {
- cairo_matrix_init_scale (&m,
- 1.0 / surface->width,
- 1.0 / surface->height);
- }
+ attributes = &operand->texture.attributes;
cairo_matrix_multiply (&attributes->matrix,
- &attributes->matrix,
- &m);
+ &src->base.matrix,
+ &attributes->matrix);
attributes->extend = src->base.extend;
attributes->filter = src->base.filter;
@@ -275,11 +232,8 @@ _cairo_gl_pattern_texture_setup (cairo_gl_operand_t *operand,
cairo_status_t status;
cairo_gl_surface_t *surface;
cairo_gl_context_t *ctx;
- cairo_surface_attributes_t *attributes;
cairo_surface_t *image;
- attributes = &operand->texture.attributes;
-
status = _cairo_gl_context_acquire (dst->base.device, &ctx);
if (unlikely (status))
return status;
@@ -299,21 +253,10 @@ _cairo_gl_pattern_texture_setup (cairo_gl_operand_t *operand,
return status;
}
- attributes->extend = CAIRO_EXTEND_NONE;
- attributes->filter = CAIRO_FILTER_NEAREST;
- attributes->has_component_alpha = FALSE;
-
- operand->type = CAIRO_GL_OPERAND_TEXTURE;
+ *operand = surface->operand;
operand->texture.surface = surface;
- operand->texture.tex = surface->tex;
-
- if (_cairo_gl_device_requires_power_of_two_textures (dst->base.device)) {
- cairo_matrix_init_identity (&attributes->matrix);
- } else {
- cairo_matrix_init_scale (&attributes->matrix,
- 1.0 / surface->width,
- 1.0 / surface->height);
- }
+ operand->texture.attributes.matrix.x0 -= extents->x * operand->texture.attributes.matrix.xx;
+ operand->texture.attributes.matrix.y0 -= extents->y * operand->texture.attributes.matrix.yy;
return CAIRO_STATUS_SUCCESS;
}
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index e508714c..d8446768 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -150,7 +150,6 @@ typedef struct cairo_gl_operand {
typedef struct cairo_gl_source {
cairo_surface_t base;
-
cairo_gl_operand_t operand;
} cairo_gl_source_t;
@@ -699,8 +698,23 @@ _cairo_gl_surface_create_scratch (cairo_gl_context_t *ctx,
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,
+ const cairo_rectangle_int_t *extents,
+ const cairo_rectangle_int_t *sample,
+ int *src_x, int *src_y);
+
+cairo_private cairo_surface_t *
_cairo_gl_white_source (void);
+static inline cairo_gl_operand_t *
+source_to_operand (cairo_surface_t *surface)
+{
+ cairo_gl_source_t *source = (cairo_gl_source_t *)surface;
+ return source ? &source->operand : NULL;
+}
+
slim_hidden_proto (cairo_gl_surface_create);
slim_hidden_proto (cairo_gl_surface_create_for_texture);
diff --git a/src/cairo-gl-source.c b/src/cairo-gl-source.c
new file mode 100644
index 00000000..01064680
--- /dev/null
+++ b/src/cairo-gl-source.c
@@ -0,0 +1,106 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is Red Hat, Inc.
+ *
+ * Contributor(s):
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#include "cairoint.h"
+
+#include "cairo-gl-private.h"
+
+#include "cairo-surface-backend-private.h"
+
+static cairo_status_t
+_cairo_gl_source_finish (void *abstract_surface)
+{
+ cairo_gl_source_t *source = abstract_surface;
+
+ _cairo_gl_operand_destroy (&source->operand);
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static const cairo_surface_backend_t cairo_gl_source_backend = {
+ CAIRO_SURFACE_TYPE_GL,
+ _cairo_gl_source_finish,
+ NULL, /* read-only wrapper */
+};
+
+cairo_surface_t *
+_cairo_gl_pattern_to_source (cairo_surface_t *dst,
+ const cairo_pattern_t *pattern,
+ cairo_bool_t is_mask,
+ const cairo_rectangle_int_t *extents,
+ const cairo_rectangle_int_t *sample,
+ int *src_x, int *src_y)
+{
+ cairo_gl_source_t *source;
+ cairo_int_status_t status;
+
+ source = malloc (sizeof (*source));
+ if (unlikely (source == NULL))
+ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+
+ _cairo_surface_init (&source->base,
+ &cairo_gl_source_backend,
+ NULL, /* device */
+ CAIRO_CONTENT_COLOR_ALPHA);
+
+ *src_x = *src_y = 0;
+ status = _cairo_gl_operand_init (&source->operand, pattern,
+ (cairo_gl_surface_t *)dst,
+ sample, extents);
+ if (unlikely (status)) {
+ cairo_surface_destroy (&source->base);
+ return _cairo_surface_create_in_error (status);
+ }
+
+ return &source->base;
+}
+
+cairo_surface_t *
+_cairo_gl_white_source (void)
+{
+ cairo_gl_source_t *source;
+
+ source = malloc (sizeof (*source));
+ if (unlikely (source == NULL))
+ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+
+ _cairo_surface_init (&source->base,
+ &cairo_gl_source_backend,
+ NULL, /* device */
+ CAIRO_CONTENT_COLOR_ALPHA);
+
+ _cairo_gl_solid_operand_init (&source->operand, CAIRO_COLOR_WHITE);
+
+ return &source->base;
+}
diff --git a/src/cairo-gl-spans-compositor.c b/src/cairo-gl-spans-compositor.c
index 710cbe24..c86b638d 100644
--- a/src/cairo-gl-spans-compositor.c
+++ b/src/cairo-gl-spans-compositor.c
@@ -279,79 +279,6 @@ FAIL:
return status;
}
-static cairo_status_t
-_cairo_gl_source_finish (void *abstract_surface)
-{
- cairo_gl_source_t *source = abstract_surface;
-
- _cairo_gl_operand_destroy (&source->operand);
- return CAIRO_STATUS_SUCCESS;
-}
-
-static const cairo_surface_backend_t cairo_gl_source_backend = {
- CAIRO_SURFACE_TYPE_GL,
- _cairo_gl_source_finish,
- NULL, /* read-only wrapper */
-};
-
-static cairo_surface_t *
-pattern_to_surface (cairo_surface_t *dst,
- const cairo_pattern_t *pattern,
- cairo_bool_t is_mask,
- const cairo_rectangle_int_t *extents,
- const cairo_rectangle_int_t *sample,
- int *src_x, int *src_y)
-{
- cairo_gl_source_t *source;
- cairo_int_status_t status;
-
- source = malloc (sizeof (*source));
- if (unlikely (source == NULL))
- return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
- _cairo_surface_init (&source->base,
- &cairo_gl_source_backend,
- NULL, /* device */
- CAIRO_CONTENT_COLOR_ALPHA);
-
- *src_x = *src_y = 0;
- status = _cairo_gl_operand_init (&source->operand, pattern,
- (cairo_gl_surface_t *)dst,
- sample, extents);
- if (unlikely (status)) {
- cairo_surface_destroy (&source->base);
- return _cairo_surface_create_in_error (status);
- }
-
- return &source->base;
-}
-
-cairo_surface_t *
-_cairo_gl_white_source (void)
-{
- cairo_gl_source_t *source;
-
- source = malloc (sizeof (*source));
- if (unlikely (source == NULL))
- return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
- _cairo_surface_init (&source->base,
- &cairo_gl_source_backend,
- NULL, /* device */
- CAIRO_CONTENT_COLOR_ALPHA);
-
- _cairo_gl_solid_operand_init (&source->operand, CAIRO_COLOR_WHITE);
-
- return &source->base;
-}
-
-static inline cairo_gl_operand_t *
-source_to_operand (cairo_surface_t *surface)
-{
- cairo_gl_source_t *source = (cairo_gl_source_t *)surface;
- return source ? &source->operand : NULL;
-}
-
static cairo_int_status_t
composite_boxes (void *_dst,
cairo_operator_t op,
@@ -498,7 +425,7 @@ _cairo_gl_span_compositor_get (void)
compositor.fill_boxes = fill_boxes;
//compositor.check_composite_boxes = check_composite_boxes;
- compositor.pattern_to_surface = pattern_to_surface;
+ compositor.pattern_to_surface = _cairo_gl_pattern_to_source;
compositor.composite_boxes = composite_boxes;
//compositor.check_span_renderer = check_span_renderer;
compositor.renderer_init = _cairo_gl_span_renderer_init;
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index ba6857e7..b6dbedc7 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -360,7 +360,7 @@ _cairo_gl_surface_embedded_operand_init (cairo_gl_surface_t *surface)
memset (operand, 0, sizeof (cairo_gl_operand_t));
operand->type = CAIRO_GL_OPERAND_TEXTURE;
- operand->texture.surface = surface;
+ operand->texture.surface = NULL;
operand->texture.tex = surface->tex;
if (_cairo_gl_device_requires_power_of_two_textures (surface->base.device)) {
diff --git a/src/cairo-gl-traps-compositor.c b/src/cairo-gl-traps-compositor.c
index eb8f7ff9..6c55ab64 100644
--- a/src/cairo-gl-traps-compositor.c
+++ b/src/cairo-gl-traps-compositor.c
@@ -150,63 +150,6 @@ FAIL:
return status;
}
-static cairo_status_t
-_cairo_gl_source_finish (void *abstract_surface)
-{
- cairo_gl_source_t *source = abstract_surface;
-
- _cairo_gl_operand_destroy (&source->operand);
- return CAIRO_STATUS_SUCCESS;
-}
-
-static const cairo_surface_backend_t cairo_gl_source_backend = {
- CAIRO_SURFACE_TYPE_GL,
- _cairo_gl_source_finish,
- NULL, /* read-only wrapper */
-};
-
-static cairo_surface_t *
-pattern_to_surface (cairo_surface_t *dst,
- const cairo_pattern_t *pattern,
- cairo_bool_t is_mask,
- const cairo_rectangle_int_t *extents,
- const cairo_rectangle_int_t *sample,
- int *src_x, int *src_y)
-{
- cairo_gl_source_t *source;
- cairo_int_status_t status;
-
- if (pattern == NULL)
- return _cairo_gl_white_source ();
-
- source = malloc (sizeof (*source));
- if (unlikely (source == NULL))
- return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
- _cairo_surface_init (&source->base,
- &cairo_gl_source_backend,
- NULL, /* device */
- CAIRO_CONTENT_COLOR_ALPHA);
-
- *src_x = *src_y = 0;
- status = _cairo_gl_operand_init (&source->operand, pattern,
- (cairo_gl_surface_t *)dst,
- sample, extents);
- if (unlikely (status)) {
- cairo_surface_destroy (&source->base);
- return _cairo_surface_create_in_error (status);
- }
-
- return &source->base;
-}
-
-static inline cairo_gl_operand_t *
-source_to_operand (cairo_surface_t *surface)
-{
- cairo_gl_source_t *source = (cairo_gl_source_t *)surface;
- return surface ? &source->operand : NULL;
-}
-
static cairo_int_status_t
composite_boxes (void *_dst,
cairo_operator_t op,
@@ -544,7 +487,7 @@ _cairo_gl_traps_compositor_get (void)
compositor.acquire = acquire;
compositor.release = release;
compositor.set_clip_region = set_clip_region;
- compositor.pattern_to_surface = pattern_to_surface;
+ compositor.pattern_to_surface = _cairo_gl_pattern_to_source;
compositor.draw_image_boxes = draw_image_boxes;
//compositor.copy_boxes = copy_boxes;
compositor.fill_boxes = fill_boxes;