[cairo-commit] 3 commits - perf/cairo-perf.c perf/cairo-perf.h perf/dragon.c perf/Makefile.am perf/pythagoras-tree.c src/cairo-surface.c
Chris Wilson
ickle at kemper.freedesktop.org
Wed Nov 19 06:07:18 PST 2008
perf/Makefile.am | 4 -
perf/cairo-perf.c | 2
perf/cairo-perf.h | 2
perf/dragon.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++
perf/pythagoras-tree.c | 86 +++++++++++++++++++++++++
src/cairo-surface.c | 30 ++++++++
6 files changed, 287 insertions(+), 3 deletions(-)
New commits:
commit 63a86a470fb88ee876414164e7e26789c1065b82
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Nov 19 14:04:01 2008 +0000
[surface] Replay meta surfaces to a similar surface.
When cloning a meta-surface, first attempt to replay it to a similar
surface rather than a full-sized image buffer.
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index c419bd5..77e8352 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -40,6 +40,7 @@
#include "cairo-surface-fallback-private.h"
#include "cairo-clip-private.h"
+#include "cairo-meta-surface-private.h"
#define DEFINE_NIL_SURFACE(status, name) \
const cairo_surface_t name = { \
@@ -1297,10 +1298,10 @@ _cairo_surface_clone_similar (cairo_surface_t *surface,
cairo_image_surface_t *image;
void *image_extra;
- if (surface->status)
+ if (unlikely (surface->status))
return surface->status;
- if (surface->finished)
+ if (unlikely (surface->finished))
return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED);
if (surface->backend->clone_similar) {
@@ -1312,6 +1313,31 @@ _cairo_surface_clone_similar (cairo_surface_t *surface,
clone_out);
if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
+ /* First check to see if we can replay to a similar surface */
+ if (_cairo_surface_is_meta (src)) {
+ cairo_surface_t *similar;
+
+ similar = cairo_surface_create_similar (surface,
+ src->content,
+ width, height);
+ status = similar->status;
+ if (unlikely (status))
+ return status;
+
+ cairo_surface_set_device_offset (similar, -src_x, -src_y);
+
+ status = _cairo_meta_surface_replay (src, similar);
+ if (unlikely (status)) {
+ cairo_surface_destroy (similar);
+ return status;
+ }
+
+ *clone_out = similar;
+ *clone_offset_x = src_x;
+ *clone_offset_y = src_y;
+ return CAIRO_STATUS_SUCCESS;
+ }
+
/* If we failed, try again with an image surface */
status = _cairo_surface_acquire_source_image (src, &image, &image_extra);
if (status == CAIRO_STATUS_SUCCESS) {
commit 7657bda0172f823fba61db4f66e0166c7619fbd2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Dec 18 11:23:33 2007 +0000
[perf/pythagoras_tree] Another fractal.
Test lots of rectangles and recursion path construction.
diff --git a/perf/Makefile.am b/perf/Makefile.am
index 3c4dea6..737e96a 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -42,7 +42,8 @@ cairo_perf_SOURCES = \
zrusin.c \
zrusin-another.h \
long-dashed-lines.c \
- dragon.c
+ dragon.c \
+ pythagoras-tree.c
if CAIRO_HAS_WIN32_SURFACE
cairo_perf_SOURCES += cairo-perf-win32.c
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 984ef54..d5f6920 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -460,5 +460,6 @@ const cairo_perf_case_t perf_cases[] = {
{ composite_checker, 16, 512},
{ twin, 800, 800},
{ dragon, 1024, 1024 },
+ { pythagoras_tree, 768, 768 },
{ NULL }
};
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 8d8b960..d18be03 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -174,5 +174,6 @@ CAIRO_PERF_DECL (long_dashed_lines);
CAIRO_PERF_DECL (composite_checker);
CAIRO_PERF_DECL (twin);
CAIRO_PERF_DECL (dragon);
+CAIRO_PERF_DECL (pythagoras_tree);
#endif
diff --git a/perf/pythagoras-tree.c b/perf/pythagoras-tree.c
new file mode 100644
index 0000000..5a78d8a
--- /dev/null
+++ b/perf/pythagoras-tree.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright © 2007 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-perf.h"
+#include <math.h>
+
+static void
+add_rectangle (cairo_t *cr, double size)
+{
+ double x, y;
+
+ if (size < 1)
+ return;
+
+ cairo_get_current_point (cr, &x, &y);
+
+ cairo_rel_move_to (cr, -size/2., -size/2.);
+ cairo_rel_line_to (cr, size, 0);
+ cairo_rel_line_to (cr, 0, size);
+ cairo_rel_line_to (cr, -size, 0);
+ cairo_close_path (cr);
+
+ cairo_save (cr);
+ cairo_translate (cr, -size/2., size);
+ cairo_move_to (cr, x, y);
+ cairo_rotate (cr, M_PI/4);
+ add_rectangle (cr, size / M_SQRT2);
+ cairo_restore (cr);
+
+ cairo_save (cr);
+ cairo_translate (cr, size/2., size);
+ cairo_move_to (cr, x, y);
+ cairo_rotate (cr, -M_PI/4);
+ add_rectangle (cr, size / M_SQRT2);
+ cairo_restore (cr);
+}
+
+static cairo_perf_ticks_t
+do_pythagoras_tree (cairo_t *cr, int width, int height)
+{
+ double size = 128;
+
+ cairo_perf_timer_start ();
+
+ cairo_save (cr);
+ cairo_translate (cr, 0, height);
+ cairo_scale (cr, 1, -1);
+
+ cairo_move_to (cr, width/2, size/2);
+ add_rectangle (cr, size);
+ cairo_set_source_rgb (cr, 0., 0., 0.);
+ cairo_fill (cr);
+ cairo_restore (cr);
+
+ cairo_perf_timer_stop ();
+
+ return cairo_perf_timer_elapsed ();
+}
+
+void
+pythagoras_tree (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+ cairo_perf_run (perf, "pythagoras_tree", do_pythagoras_tree);
+}
commit abd0a2627d198eddb628bbc1f2974435a74655a2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Dec 18 10:49:23 2007 +0000
[perf/dragon] Add a dragon curve perf case.
Inspired by http://labs.trolltech.com/blogs/2007/08/31/rasterizing-dragons/
and http://en.wikipedia.org/wiki/Dragon_curve, add a performance test case
to measure drawing this space-filling fractal curve.
diff --git a/perf/Makefile.am b/perf/Makefile.am
index edd4c68..3c4dea6 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -41,7 +41,8 @@ cairo_perf_SOURCES = \
world-map.h \
zrusin.c \
zrusin-another.h \
- long-dashed-lines.c
+ long-dashed-lines.c \
+ dragon.c
if CAIRO_HAS_WIN32_SURFACE
cairo_perf_SOURCES += cairo-perf-win32.c
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index a6d59a5..984ef54 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -459,5 +459,6 @@ const cairo_perf_case_t perf_cases[] = {
{ long_dashed_lines, 512, 512},
{ composite_checker, 16, 512},
{ twin, 800, 800},
+ { dragon, 1024, 1024 },
{ NULL }
};
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 0cedb69..8d8b960 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -173,5 +173,6 @@ CAIRO_PERF_DECL (rounded_rectangles);
CAIRO_PERF_DECL (long_dashed_lines);
CAIRO_PERF_DECL (composite_checker);
CAIRO_PERF_DECL (twin);
+CAIRO_PERF_DECL (dragon);
#endif
diff --git a/perf/dragon.c b/perf/dragon.c
new file mode 100644
index 0000000..6d0328e
--- /dev/null
+++ b/perf/dragon.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright © 2007 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ *
+ * Inspiration (and path!) taken from
+ * http://labs.trolltech.com/blogs/2007/08/31/rasterizing-dragons/
+ */
+
+#include "cairo-perf.h"
+
+#ifndef MIN
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
+static inline int
+next_pot (int v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ v++;
+ return v;
+}
+
+static cairo_bool_t
+direction (int i)
+{
+ int pivot, np2;
+
+ if (i < 2)
+ return TRUE;
+
+ np2 = next_pot (i + 1);
+ if (np2 == i + 1)
+ return TRUE;
+
+ pivot = np2 / 2 - 1;
+ return ! direction (2 * pivot - i);
+}
+
+
+static void
+path (cairo_t *cr, int step, int dir, int iterations)
+{
+ double dx, dy;
+ int i;
+
+ switch (dir) {
+ case 0: dx = step; dy = 0; break;
+ case 1: dx = -step; dy = 0; break;
+ case 2: dx = 0; dy = step; break;
+ case 3: dx = 0; dy = -step; break;
+ }
+
+ for (i = 0; i < iterations; i++) {
+ cairo_rel_line_to (cr, dx, dy);
+
+ if (direction (i)) {
+ double t = dx;
+ dx = dy;
+ dy = -t;
+ } else {
+ double t = dx;
+ dx = -dy;
+ dy = t;
+ }
+ }
+}
+
+static cairo_perf_ticks_t
+do_dragon (cairo_t *cr, int width, int height)
+{
+ cairo_pattern_t *pattern;
+ double cx, cy, r;
+
+ cx = cy = .5 * MAX (width, height);
+ r = .5 * MIN (width, height);
+
+ cairo_perf_timer_start ();
+
+ pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r);
+ cairo_pattern_add_color_stop_rgb (pattern, 0., .0, .0, .0);
+ cairo_pattern_add_color_stop_rgb (pattern, 0.25, .5, .4, .4);
+ cairo_pattern_add_color_stop_rgb (pattern, .5, .8, .8, .9);
+ cairo_pattern_add_color_stop_rgb (pattern, 1., .9, .9, 1.);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_paint (cr);
+
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+ cairo_set_line_width (cr, 4.);
+
+ cairo_move_to (cr, cx, cy);
+ path (cr, 12, 0, 2048);
+ pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r);
+ cairo_pattern_add_color_stop_rgb (pattern, 0., 1., 1., 1.);
+ cairo_pattern_add_color_stop_rgb (pattern, 1., 0., 0., 0.);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_stroke(cr);
+
+ cairo_move_to (cr, cx, cy);
+ path (cr, 12, 1, 2048);
+ pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r);
+ cairo_pattern_add_color_stop_rgb (pattern, 1., 1., 1., 0.);
+ cairo_pattern_add_color_stop_rgb (pattern, 0., 1., 0., 0.);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_stroke(cr);
+
+ cairo_move_to (cr, cx, cy);
+ path (cr, 12, 2, 2048);
+ pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r);
+ cairo_pattern_add_color_stop_rgb (pattern, 1., 0., 1., 1.);
+ cairo_pattern_add_color_stop_rgb (pattern, 0., 0., 1., 0.);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_stroke(cr);
+
+ cairo_move_to (cr, cx, cy);
+ path (cr, 12, 3, 2048);
+ pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r);
+ cairo_pattern_add_color_stop_rgb (pattern, 1., 1., 0., 1.);
+ cairo_pattern_add_color_stop_rgb (pattern, 0., 0., 0., 1.);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_stroke(cr);
+
+ cairo_perf_timer_stop ();
+
+ return cairo_perf_timer_elapsed ();
+}
+
+void
+dragon (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+ cairo_perf_run (perf, "dragon", do_dragon);
+}
More information about the cairo-commit
mailing list