[cairo-commit] 3 commits - src/cairo-image-surface-private.h src/cairo-script-surface.c test/xlib-expose-event.c
Chris Wilson
ickle at kemper.freedesktop.org
Sat Aug 13 12:54:55 PDT 2011
src/cairo-image-surface-private.h | 86 +++++++++++++++++++++++++++++++++++
src/cairo-script-surface.c | 93 +++++++++++++++++++++++++++++---------
test/xlib-expose-event.c | 27 ++++++-----
3 files changed, 173 insertions(+), 33 deletions(-)
New commits:
commit 0f4cc1f11804137fb6df8688451fe97428eab47a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Aug 13 17:39:25 2011 +0100
script: Emit sequences of boxes to as 'rectangle' for clarity
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index 1b715f5..e62f31f 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -1714,12 +1714,61 @@ _path_close (void *closure)
}
static cairo_status_t
+_emit_path_boxes (cairo_script_surface_t *surface,
+ const cairo_path_fixed_t *path)
+{
+ cairo_script_context_t *ctx = to_context (surface);
+ cairo_path_fixed_iter_t iter;
+ cairo_status_t status;
+ struct _cairo_boxes_chunk *chunk;
+ cairo_boxes_t boxes;
+ cairo_box_t box;
+ int i;
+
+ _cairo_boxes_init (&boxes);
+ _cairo_path_fixed_iter_init (&iter, path);
+ while (_cairo_path_fixed_iter_is_fill_box (&iter, &box)) {
+ if (box.p1.y == box.p2.y || box.p1.x == box.p2.x)
+ continue;
+
+ status = _cairo_boxes_add (&boxes, CAIRO_ANTIALIAS_DEFAULT, &box);
+ if (unlikely (status)) {
+ _cairo_boxes_fini (&boxes);
+ return status;
+ }
+ }
+
+ if (! _cairo_path_fixed_iter_at_end (&iter)) {
+ _cairo_boxes_fini (&boxes);
+ return FALSE;
+ }
+
+ for (chunk = &boxes.chunks; chunk; chunk = chunk->next) {
+ for (i = 0; i < chunk->count; i++) {
+ const cairo_box_t *b = &chunk->base[i];
+ double x1 = _cairo_fixed_to_double (b->p1.x);
+ double y1 = _cairo_fixed_to_double (b->p1.y);
+ double x2 = _cairo_fixed_to_double (b->p2.x);
+ double y2 = _cairo_fixed_to_double (b->p2.y);
+
+ _cairo_output_stream_printf (ctx->stream,
+ "\n %f %f %f %f rectangle",
+ x1, y1, x2 - x1, y2 - y1);
+ }
+ }
+
+ _cairo_boxes_fini (&boxes);
+ return status;
+}
+
+static cairo_status_t
_emit_path (cairo_script_surface_t *surface,
- const cairo_path_fixed_t *path)
+ const cairo_path_fixed_t *path,
+ cairo_bool_t is_fill)
{
cairo_script_context_t *ctx = to_context (surface);
cairo_box_t box;
- cairo_status_t status;
+ cairo_int_status_t status;
assert (target_is_active (surface));
assert (_cairo_matrix_is_identity (&surface->cr.current_ctm));
@@ -1733,39 +1782,41 @@ _emit_path (cairo_script_surface_t *surface,
if (path == NULL) {
_cairo_path_fixed_init (&surface->cr.current_path);
- } else if (_cairo_path_fixed_is_rectangle (path, &box)) {
+ _cairo_output_stream_puts (ctx->stream, "\n");
+ return CAIRO_STATUS_SUCCESS;
+ }
+
+ status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path);
+ if (unlikely (status))
+ return status;
+
+ status = CAIRO_INT_STATUS_UNSUPPORTED;
+ if (_cairo_path_fixed_is_rectangle (path, &box)) {
double x1 = _cairo_fixed_to_double (box.p1.x);
double y1 = _cairo_fixed_to_double (box.p1.y);
double x2 = _cairo_fixed_to_double (box.p2.x);
double y2 = _cairo_fixed_to_double (box.p2.y);
- status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path);
- if (unlikely (status))
- return status;
-
_cairo_output_stream_printf (ctx->stream,
" %f %f %f %f rectangle",
x1, y1, x2 - x1, y2 - y1);
- } else {
- cairo_status_t status;
-
- status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path);
- if (unlikely (status))
- return status;
+ status = CAIRO_INT_STATUS_SUCCESS;
+ } else if (is_fill && _cairo_path_fixed_fill_is_rectilinear (path)) {
+ status = _emit_path_boxes (surface, path);
+ }
+ if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
status = _cairo_path_fixed_interpret (path,
_path_move_to,
_path_line_to,
_path_curve_to,
_path_close,
ctx->stream);
- if (unlikely (status))
- return status;
}
_cairo_output_stream_puts (ctx->stream, "\n");
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
static cairo_bool_t
_scaling_matrix_equal (const cairo_matrix_t *a,
@@ -2124,8 +2175,8 @@ _cairo_script_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
_cairo_path_fixed_is_box (path, &box))
{
if (box.p1.x <= 0 && box.p1.y <= 0 &&
- box.p2.x - box.p1.x >= _cairo_fixed_from_double (surface->width) &&
- box.p2.y - box.p1.y >= _cairo_fixed_from_double (surface->height))
+ box.p2.x >= _cairo_fixed_from_double (surface->width) &&
+ box.p2.y >= _cairo_fixed_from_double (surface->height))
{
return CAIRO_STATUS_SUCCESS;
}
@@ -2151,7 +2202,7 @@ _cairo_script_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
return status;
}
- status = _emit_path (surface, path);
+ status = _emit_path (surface, path, TRUE);
if (unlikely (status))
return status;
@@ -2397,7 +2448,7 @@ _cairo_script_surface_stroke (void *abstract_surface,
if (unlikely (status))
goto BAIL;
- status = _emit_path (surface, path);
+ status = _emit_path (surface, path, FALSE);
if (unlikely (status))
goto BAIL;
@@ -2509,7 +2560,7 @@ _cairo_script_surface_fill (void *abstract_surface,
goto BAIL;
}
- status = _emit_path (surface, path);
+ status = _emit_path (surface, path, TRUE);
if (unlikely (status))
goto BAIL;
commit 6b7539d96b0968a00cf91d9d7a780727d37bdd34
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Aug 13 17:24:28 2011 +0100
test/xlib-expose-event: Be kinder to recording surfaces
And only create the source image once.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/test/xlib-expose-event.c b/test/xlib-expose-event.c
index 091fef5..4b1cb46 100644
--- a/test/xlib-expose-event.c
+++ b/test/xlib-expose-event.c
@@ -102,23 +102,19 @@ clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
}
static void
-draw_image (const cairo_test_context_t *ctx, cairo_t *cr)
+draw_image (const cairo_test_context_t *ctx,
+ cairo_t *cr,
+ cairo_surface_t *image)
{
- cairo_surface_t *surface, *similar;
-
- surface = cairo_test_create_surface_from_png (ctx, png_filename);
- similar = clone_similar_surface (cairo_get_group_target (cr), surface);
- cairo_surface_destroy (surface);
-
- cairo_set_source_surface (cr, similar, 0, 0);
+ cairo_set_source_surface (cr, image, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
- cairo_surface_destroy (similar);
}
static void
draw (const cairo_test_context_t *ctx,
cairo_t *cr,
+ cairo_surface_t *image,
cairo_rectangle_t *region,
int n_regions)
{
@@ -133,7 +129,7 @@ draw (const cairo_test_context_t *ctx,
cairo_clip (cr);
}
cairo_push_group (cr);
- draw_image (ctx, cr);
+ draw_image (ctx, cr, image);
draw_mask (cr);
cairo_pop_group_to_source (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
@@ -146,12 +142,17 @@ draw_func (cairo_t *cr, int width, int height)
{
cairo_rectangle_t region[4];
const cairo_test_context_t *ctx;
+ cairo_surface_t *source, *image;
int i, j;
ctx = cairo_test_get_context (cr);
+ source = cairo_test_create_surface_from_png (ctx, png_filename);
+ image = clone_similar_surface (cairo_get_group_target (cr), source);
+ cairo_surface_destroy (source);
+
cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR);
- draw (ctx, cr, NULL, 0);
+ draw (ctx, cr, image, NULL, 0);
for (i = 0; i < NLOOPS; i++) {
for (j = 0; j < NLOOPS; j++) {
region[0].x = i * SIZE / NLOOPS;
@@ -174,7 +175,7 @@ draw_func (cairo_t *cr, int width, int height)
region[3].width = SIZE / 4;
region[3].height = SIZE / 4;
- draw (ctx, cr, region, 4);
+ draw (ctx, cr, image, region, 4);
}
}
@@ -182,6 +183,8 @@ draw_func (cairo_t *cr, int width, int height)
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
+ cairo_surface_destroy (image);
+
return CAIRO_TEST_SUCCESS;
}
commit bc34c1c4efb2e252f4263e3fef0024ba92e8d326
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Aug 13 20:46:21 2011 +0100
Add missing 'cairo-image-surface-private.h'
It was supposed to be the centre point of e849e7c92, but I had a little
battle with git and lost...
Reported-by: James Cloos <cloos at jhcloos.com>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/cairo-image-surface-private.h b/src/cairo-image-surface-private.h
new file mode 100644
index 0000000..56a1dc4
--- /dev/null
+++ b/src/cairo-image-surface-private.h
@@ -0,0 +1,86 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 University of Southern
+ * California.
+ *
+ * Contributor(s):
+ * Carl D. Worth <cworth at cworth.org>
+ */
+
+#ifndef CAIRO_IMAGE_SURFACE_PRIVATE_H
+#define CAIRO_IMAGE_SURFACE_PRIVATE_H
+
+#include "cairo-surface-private.h"
+
+#include <pixman.h>
+
+CAIRO_BEGIN_DECLS
+
+struct _cairo_image_surface {
+ cairo_surface_t base;
+
+ pixman_format_code_t pixman_format;
+ cairo_format_t format;
+ unsigned char *data;
+
+ int width;
+ int height;
+ int stride;
+ int depth;
+
+ pixman_image_t *pixman_image;
+
+ unsigned owns_data : 1;
+ unsigned transparency : 2;
+ unsigned color : 2;
+};
+
+extern const cairo_private cairo_surface_backend_t _cairo_image_surface_backend;
+
+cairo_private void
+_cairo_image_surface_init (cairo_image_surface_t *surface,
+ pixman_image_t *pixman_image,
+ pixman_format_code_t pixman_format);
+
+cairo_private_no_warn cairo_bool_t
+_cairo_image_surface_get_extents (void *abstract_surface,
+ cairo_rectangle_int_t *rectangle);
+
+cairo_private void
+_cairo_image_surface_get_font_options (void *abstract_surface,
+ cairo_font_options_t *options);
+
+cairo_private cairo_status_t
+_cairo_image_surface_finish (void *abstract_surface);
+
+CAIRO_END_DECLS
+
+#endif /* CAIRO_IMAGE_SURFACE_PRIVATE_H */
More information about the cairo-commit
mailing list