[cairo-commit] 2 commits - perf/cairo-perf.h perf/cairo-perf-micro.c perf/Makefile.am perf/micro src/cairo-gl-gradient-private.h test/hatchings.c test/hatchings.ref.png test/hatchings.xlib.ref.png test/Makefile.refs test/Makefile.sources
Chris Wilson
ickle at kemper.freedesktop.org
Mon Jul 18 02:32:37 PDT 2011
perf/Makefile.am | 2
perf/cairo-perf-micro.c | 1
perf/cairo-perf.h | 1
perf/micro/Makefile.sources | 1
perf/micro/hatching.c | 199 ++++++++++++++++++++++++++++++++++++++++
src/cairo-gl-gradient-private.h | 1
test/Makefile.refs | 2
test/Makefile.sources | 1
test/hatchings.c | 153 ++++++++++++++++++++++++++++++
test/hatchings.ref.png |binary
test/hatchings.xlib.ref.png |binary
11 files changed, 361 insertions(+)
New commits:
commit 3a293657133145e1ecc4e7c047069cb465f6b4ef
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon Jul 18 09:16:21 2011 +0100
tests,perf: Add a hatchings clip-test
A benchmark to test how close we get to reducing paint+clip to an ordinary
fill, and to check correctness.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/perf/Makefile.am b/perf/Makefile.am
index d01ea06..17678a3 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -12,6 +12,8 @@ AM_CPPFLAGS = \
AM_LDFLAGS = $(CAIRO_LDFLAGS)
+noinst_PROGRAMS = cairo-perf-trace cairo-perf-micro
+
EXTRA_PROGRAMS += cairo-perf-micro \
cairo-perf-trace \
cairo-perf-diff-files \
diff --git a/perf/cairo-perf-micro.c b/perf/cairo-perf-micro.c
index 77c86d5..30b0102 100644
--- a/perf/cairo-perf-micro.c
+++ b/perf/cairo-perf-micro.c
@@ -535,6 +535,7 @@ const cairo_perf_case_t perf_cases[] = {
{ text, 64, 512},
{ glyphs, 64, 512},
{ mask, 64, 512},
+ { hatching, 64, 512},
{ tessellate, 100, 100},
{ subimage_copy, 16, 512},
{ pattern_create_radial, 16, 16},
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 3a3965e..cc9bbb6 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -188,6 +188,7 @@ CAIRO_PERF_DECL (paint_with_alpha);
CAIRO_PERF_DECL (mask);
CAIRO_PERF_DECL (stroke);
CAIRO_PERF_DECL (subimage_copy);
+CAIRO_PERF_DECL (hatching);
CAIRO_PERF_DECL (tessellate);
CAIRO_PERF_DECL (text);
CAIRO_PERF_DECL (glyphs);
diff --git a/perf/micro/Makefile.sources b/perf/micro/Makefile.sources
index 794ed62..84e02f6 100644
--- a/perf/micro/Makefile.sources
+++ b/perf/micro/Makefile.sources
@@ -3,6 +3,7 @@ libcairo_perf_micro_sources = \
box-outline.c \
composite-checker.c \
fill.c \
+ hatching.c \
long-lines.c \
mosaic.c \
paint.c \
diff --git a/perf/micro/hatching.c b/perf/micro/hatching.c
new file mode 100644
index 0000000..2098ab3
--- /dev/null
+++ b/perf/micro/hatching.c
@@ -0,0 +1,199 @@
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright (c) 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <assert.h>
+#include "cairo-perf.h"
+
+
+#define STEP 5
+#define WIDTH 100
+#define HEIGHT 100
+
+static void path (cairo_t *cr, int width, int height)
+{
+ int i;
+
+ for (i = 0; i < width+1; i += STEP) {
+ cairo_rectangle (cr, i-1, -1, 2, height+2);
+ cairo_rectangle (cr, -1, i-1, width+2, 2);
+ }
+}
+
+static void aa (cairo_t *cr)
+{
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
+}
+
+static void mono (cairo_t *cr)
+{
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+}
+
+static void aligned (cairo_t *cr, int width, int height)
+{
+}
+
+static void misaligned (cairo_t *cr, int width, int height)
+{
+ cairo_translate (cr, 0.25, 0.25);
+}
+
+static void rotated (cairo_t *cr, int width, int height)
+{
+ cairo_translate (cr, width/2, height/2);
+ cairo_rotate (cr, M_PI/4);
+ cairo_translate (cr, -width/2, -height/2);
+}
+
+static void clip (cairo_t *cr)
+{
+ cairo_clip (cr);
+ cairo_paint (cr);
+}
+
+static void clip_alpha (cairo_t *cr)
+{
+ cairo_clip (cr);
+ cairo_paint_with_alpha (cr, .5);
+}
+
+static cairo_perf_ticks_t
+draw (cairo_t *cr,
+ void (*prepare) (cairo_t *cr),
+ void (*transform) (cairo_t *cr, int width, int height),
+ void (*op) (cairo_t *cr),
+ int width, int height, int loops)
+{
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_paint (cr);
+ cairo_set_source_rgb (cr, 1, 0, 0);
+
+ prepare (cr);
+
+ cairo_perf_timer_start ();
+ while (loops--) {
+ cairo_save (cr);
+ transform (cr, width, height);
+ path (cr, width, height);
+ op (cr);
+ cairo_restore (cr);
+ }
+ cairo_perf_timer_stop ();
+
+ cairo_restore (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+draw_aligned_aa (cairo_t *cr, int width, int height, int loops)
+{
+ return draw(cr, aa, aligned, cairo_fill,
+ width, height, loops);
+}
+
+static cairo_perf_ticks_t
+draw_misaligned_aa (cairo_t *cr, int width, int height, int loops)
+{
+ return draw(cr, aa, misaligned, cairo_fill,
+ width, height, loops);
+}
+
+static cairo_perf_ticks_t
+draw_rotated_aa (cairo_t *cr, int width, int height, int loops)
+{
+ return draw(cr, aa, rotated, cairo_fill,
+ width, height, loops);
+}
+
+static cairo_perf_ticks_t
+draw_aligned_mono (cairo_t *cr, int width, int height, int loops)
+{
+ return draw(cr, mono, aligned, cairo_fill,
+ width, height, loops);
+}
+
+static cairo_perf_ticks_t
+draw_misaligned_mono (cairo_t *cr, int width, int height, int loops)
+{
+ return draw(cr, mono, misaligned, cairo_fill,
+ width, height, loops);
+}
+
+static cairo_perf_ticks_t
+draw_rotated_mono (cairo_t *cr, int width, int height, int loops)
+{
+ return draw(cr, mono, rotated, cairo_fill,
+ width, height, loops);
+}
+
+#define F(name, op,transform,aa) \
+static cairo_perf_ticks_t \
+draw_##name (cairo_t *cr, int width, int height, int loops) \
+{ return draw(cr, (aa), (transform), (op), width, height, loops); }
+
+F(clip_aligned, clip, aligned, aa)
+F(clip_misaligned, clip, misaligned, aa)
+F(clip_rotated, clip, rotated, aa)
+F(clip_aligned_mono, clip, aligned, mono)
+F(clip_misaligned_mono, clip, misaligned, mono)
+F(clip_rotated_mono, clip, rotated, mono)
+
+F(clip_alpha_aligned, clip_alpha, aligned, aa)
+F(clip_alpha_misaligned, clip_alpha, misaligned, aa)
+F(clip_alpha_rotated, clip_alpha, rotated, aa)
+F(clip_alpha_aligned_mono, clip_alpha, aligned, mono)
+F(clip_alpha_misaligned_mono, clip_alpha, misaligned, mono)
+F(clip_alpha_rotated_mono, clip_alpha, rotated, mono)
+
+void
+hatching (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+ if (! cairo_perf_can_run (perf, "hatching", NULL))
+ return;
+
+ cairo_perf_run (perf, "hatching-aligned-aa", draw_aligned_aa, NULL);
+ cairo_perf_run (perf, "hatching-misaligned-aa", draw_misaligned_aa, NULL);
+ cairo_perf_run (perf, "hatching-rotated-aa", draw_rotated_aa, NULL);
+ cairo_perf_run (perf, "hatching-aligned-mono", draw_aligned_mono, NULL);
+ cairo_perf_run (perf, "hatching-misaligned-mono", draw_misaligned_mono, NULL);
+ cairo_perf_run (perf, "hatching-rotated-mono", draw_rotated_mono, NULL);
+
+ cairo_perf_run (perf, "hatching-clip-aligned-aa", draw_clip_aligned, NULL);
+ cairo_perf_run (perf, "hatching-clip-misaligned-aa", draw_clip_misaligned, NULL);
+ cairo_perf_run (perf, "hatching-clip-rotated-aa", draw_clip_rotated, NULL);
+ cairo_perf_run (perf, "hatching-clip-aligned-mono", draw_clip_aligned_mono, NULL);
+ cairo_perf_run (perf, "hatching-clip-misaligned-mono", draw_clip_misaligned_mono, NULL);
+ cairo_perf_run (perf, "hatching-clip-rotated-mono", draw_clip_rotated_mono, NULL);
+
+ cairo_perf_run (perf, "hatching-clip-alpha-aligned-aa", draw_clip_alpha_aligned, NULL);
+ cairo_perf_run (perf, "hatching-clip-alpha-misaligned-aa", draw_clip_alpha_misaligned, NULL);
+ cairo_perf_run (perf, "hatching-clip-alpha-rotated-aa", draw_clip_alpha_rotated, NULL);
+ cairo_perf_run (perf, "hatching-clip-alpha-aligned-mono", draw_clip_alpha_aligned_mono, NULL);
+ cairo_perf_run (perf, "hatching-clip-alpha-misaligned-mono", draw_clip_alpha_misaligned_mono, NULL);
+ cairo_perf_run (perf, "hatching-clip-alpha-rotated-mono", draw_clip_alpha_rotated_mono, NULL);
+}
diff --git a/test/Makefile.refs b/test/Makefile.refs
index 5a82b38..1c0945b 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -612,6 +612,8 @@ REFERENCE_IMAGES = \
halo.quartz.ref.png \
halo.ref.png \
halo.xlib.ref.png \
+ hatchings.ref.png \
+ hatchings.xlib.ref.png \
huge-linear.image16.ref.png \
huge-linear.pdf.ref.png \
huge-linear.ps3.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 46ce337..bb907bf 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -129,6 +129,7 @@ test_sources = \
group-unaligned.c \
half-coverage.c \
halo.c \
+ hatchings.c \
huge-linear.c \
huge-radial.c \
image-surface-source.c \
diff --git a/test/hatchings.c b/test/hatchings.c
new file mode 100644
index 0000000..ca3f2c6
--- /dev/null
+++ b/test/hatchings.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#define STEP 5
+#define WIDTH 100
+#define HEIGHT 100
+
+static void hatching (cairo_t *cr)
+{
+ int i;
+
+ cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
+ cairo_clip (cr);
+
+ for (i = 0; i < WIDTH; i += STEP) {
+ cairo_rectangle (cr, i-1, -2, 2, HEIGHT+4);
+ cairo_rectangle (cr, -2, i-1, WIDTH+4, 2);
+ }
+}
+
+static void background (cairo_t *cr)
+{
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgb (cr, 1,1,1);
+ cairo_paint (cr);
+}
+
+static void clip_to_quadrant (cairo_t *cr)
+{
+ cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
+ cairo_clip (cr);
+}
+
+static void draw_hatching (cairo_t *cr, void (*func) (cairo_t *))
+{
+ cairo_save (cr); {
+ clip_to_quadrant (cr);
+ hatching (cr);
+ func (cr);
+ } cairo_restore (cr);
+
+ cairo_translate (cr, WIDTH, 0);
+
+ cairo_save (cr); {
+ clip_to_quadrant (cr);
+ cairo_translate (cr, 0.25, 0.25);
+ hatching (cr);
+ func (cr);
+ } cairo_restore (cr);
+
+ cairo_translate (cr, WIDTH, 0);
+
+ cairo_save (cr); {
+ clip_to_quadrant (cr);
+ cairo_translate (cr, WIDTH/2, HEIGHT/2);
+ cairo_rotate (cr, M_PI/4);
+ cairo_translate (cr, -WIDTH/2, -HEIGHT/2);
+ hatching (cr);
+ func (cr);
+ } cairo_restore (cr);
+
+ cairo_translate (cr, WIDTH, 0);
+}
+
+static void do_clip (cairo_t *cr)
+{
+ cairo_clip (cr);
+ cairo_paint (cr);
+}
+
+static void do_clip_alpha (cairo_t *cr)
+{
+ cairo_clip (cr);
+ cairo_paint_with_alpha (cr, .5);
+}
+
+static void hatchings (cairo_t *cr, void (*func) (cairo_t *))
+{
+ cairo_save (cr); {
+ cairo_set_source_rgb(cr, 1, 0, 0);
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
+ draw_hatching (cr, func);
+ cairo_set_source_rgb(cr, 0, 0, 1);
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+ draw_hatching (cr, func);
+ } cairo_restore (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ background (cr);
+
+
+ /* aligned, misaligned, diagonal; mono repeat
+ * x fill
+ * x clip; paint
+ * x clip; paint-alpha
+ * repeated, for over/source
+ */
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ hatchings (cr, cairo_fill);
+ cairo_translate (cr, 0, HEIGHT);
+ hatchings (cr, do_clip);
+ cairo_translate (cr, 0, HEIGHT);
+ hatchings (cr, do_clip_alpha);
+ cairo_translate (cr, 0, HEIGHT);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+ hatchings (cr, cairo_fill);
+ cairo_translate (cr, 0, HEIGHT);
+ hatchings (cr, do_clip);
+ cairo_translate (cr, 0, HEIGHT);
+ hatchings (cr, do_clip_alpha);
+ cairo_translate (cr, 0, HEIGHT);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (hatchings,
+ "Test drawing through various aligned/unaliged clips",
+ "clip, alpha", /* keywords */
+ "target=raster", /* requirements */
+ 6*WIDTH, 6*HEIGHT,
+ NULL, draw)
diff --git a/test/hatchings.ref.png b/test/hatchings.ref.png
new file mode 100644
index 0000000..4b6c9a8
Binary files /dev/null and b/test/hatchings.ref.png differ
diff --git a/test/hatchings.xlib.ref.png b/test/hatchings.xlib.ref.png
new file mode 100644
index 0000000..2b319ad
Binary files /dev/null and b/test/hatchings.xlib.ref.png differ
commit 2786864306eeb353ca873b63e471224d5ab8d0c8
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon Jul 18 10:08:16 2011 +0100
gl: Compile fix, missing include cairo-pattern-private.h
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/cairo-gl-gradient-private.h b/src/cairo-gl-gradient-private.h
index 3d7b047..77f9bbd 100644
--- a/src/cairo-gl-gradient-private.h
+++ b/src/cairo-gl-gradient-private.h
@@ -46,6 +46,7 @@
#include "cairo-cache-private.h"
#include "cairo-device-private.h"
#include "cairo-reference-count-private.h"
+#include "cairo-pattern-private.h"
#include "cairo-types-private.h"
#include "cairo-gl.h"
More information about the cairo-commit
mailing list