summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2006-10-04 15:39:05 -0700
committerCarl Worth <cworth@cworth.org>2006-10-04 17:14:12 -0700
commitd52256df7c0147c29246dfc930644b6bdbff3c3f (patch)
tree1d7736ab88cd0eefd8c6224bef7b9516e8c4bb58
parentad02773e9babe935250b810f8f9f490eb3d02a64 (diff)
perf: Move iteration over sources and operators from paint to new cairo-perf-cover
This will finally allow us to very easily add lots of other tests that will similarly involve iterating over the various sources and operators of interest.
-rw-r--r--perf/Makefile.am1
-rw-r--r--perf/cairo-perf-cover.c166
-rw-r--r--perf/cairo-perf.c9
-rw-r--r--perf/cairo-perf.h13
-rw-r--r--perf/paint.c133
5 files changed, 180 insertions, 142 deletions
diff --git a/perf/Makefile.am b/perf/Makefile.am
index d10c3d06..ccc95ddd 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -17,6 +17,7 @@ noinst_PROGRAMS = cairo-perf
cairo_perf_SOURCES = \
cairo-perf.c \
cairo-perf.h \
+ cairo-perf-cover.c \
paint.c \
tessellate.c
diff --git a/perf/cairo-perf-cover.c b/perf/cairo-perf-cover.c
new file mode 100644
index 00000000..4ba53f20
--- /dev/null
+++ b/perf/cairo-perf-cover.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright © 2006 Red Hat, Inc.
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Carl D. Worth <cworth@cworth.org>
+ */
+
+#include "cairo-perf.h"
+
+static void
+init_and_set_source_surface (cairo_t *cr,
+ cairo_surface_t *source,
+ int width,
+ int height)
+{
+ cairo_t *cr2;
+
+ /* Fill it with something known */
+ cr2 = cairo_create (source);
+ cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
+ cairo_paint (cr2);
+
+ cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
+ cairo_paint (cr2);
+
+ cairo_set_source_rgba (cr2, 1, 0, 0, 0.5); /* 50% red */
+ cairo_new_path (cr2);
+ cairo_rectangle (cr2, 0, 0, width/2.0, height/2.0);
+ cairo_rectangle (cr2, width/2.0, height/2.0, width/2.0, height/2.0);
+ cairo_fill (cr2);
+ cairo_destroy (cr2);
+
+ cairo_set_source_surface (cr, source, 0, 0);
+}
+
+static void
+set_source_solid_rgb (cairo_t *cr,
+ int width,
+ int height)
+{
+ cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
+}
+
+static void
+set_source_solid_rgba (cairo_t *cr,
+ int width,
+ int height)
+{
+ cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
+}
+
+static void
+set_source_image_surface_rgb (cairo_t *cr,
+ int width,
+ int height)
+{
+ cairo_surface_t *source;
+
+ source = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+ width, height);
+ init_and_set_source_surface (cr, source, width, height);
+
+ cairo_surface_destroy (source);
+}
+
+static void
+set_source_image_surface_rgba (cairo_t *cr,
+ int width,
+ int height)
+{
+ cairo_surface_t *source;
+
+ source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ width, height);
+ init_and_set_source_surface (cr, source, width, height);
+
+ cairo_surface_destroy (source);
+}
+
+static void
+set_source_similar_surface_rgb (cairo_t *cr,
+ int width,
+ int height)
+{
+ cairo_surface_t *source;
+
+ source = cairo_surface_create_similar (cairo_get_target (cr),
+ CAIRO_CONTENT_COLOR,
+ width, height);
+ init_and_set_source_surface (cr, source, width, height);
+
+ cairo_surface_destroy (source);
+}
+
+static void
+set_source_similar_surface_rgba (cairo_t *cr,
+ int width,
+ int height)
+{
+ cairo_surface_t *source;
+
+ source = cairo_surface_create_similar (cairo_get_target (cr),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ width, height);
+ init_and_set_source_surface (cr, source, width, height);
+
+ cairo_surface_destroy (source);
+}
+
+typedef void (*set_source_func_t) (cairo_t *cr, int width, int height);
+#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
+
+void
+cairo_perf_cover_sources_and_operators (cairo_perf_t *perf,
+ const char *name,
+ cairo_perf_func_t perf_func)
+{
+ unsigned int i, j;
+ char *expanded_name;
+
+ struct { set_source_func_t set_source; const char *name; } sources[] = {
+ { set_source_solid_rgb, "solid_source_rgb" },
+ { set_source_solid_rgba, "solid_source_rgba" },
+ { set_source_image_surface_rgb, "image_surface_rgb" },
+ { set_source_image_surface_rgba, "image_surface_rgba" },
+ { set_source_similar_surface_rgb, "similar_surface_rgb" },
+ { set_source_similar_surface_rgba, "similar_surface_rgba" }
+ };
+
+ struct { cairo_operator_t op; const char *name; } operators[] = {
+ { CAIRO_OPERATOR_OVER, "over" },
+ { CAIRO_OPERATOR_SOURCE, "source" }
+ };
+
+ for (i = 0; i < ARRAY_SIZE (sources); i++) {
+ (sources[i].set_source) (perf->cr, perf->size, perf->size);
+
+ for (j = 0; j < ARRAY_SIZE (operators); j++) {
+ cairo_set_operator (perf->cr, operators[j].op);
+
+ xasprintf (&expanded_name, "%s_%s_%s",
+ name, sources[i].name, operators[j].name);
+ cairo_perf_run (perf, expanded_name, perf_func);
+ free (expanded_name);
+ }
+ }
+}
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 0c481760..ff72bfd9 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -28,15 +28,6 @@
#include "cairo-perf.h"
-
-struct _cairo_perf {
- unsigned int iterations;
- cairo_boilerplate_target_t *target;
- unsigned int test_number;
- unsigned int size;
- cairo_t *cr;
-};
-
typedef struct _cairo_perf_case {
CAIRO_PERF_DECL (*run);
unsigned int min_size;
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 5c5ec21b..10007200 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -59,7 +59,13 @@ void
cairo_perf_yield (void);
/* running a test case */
-typedef struct _cairo_perf cairo_perf_t;
+typedef struct _cairo_perf {
+ unsigned int iterations;
+ cairo_boilerplate_target_t *target;
+ unsigned int test_number;
+ unsigned int size;
+ cairo_t *cr;
+} cairo_perf_t;
typedef cairo_perf_ticks_t
(*cairo_perf_func_t) (cairo_t *cr, int width, int height);
@@ -69,6 +75,11 @@ cairo_perf_run (cairo_perf_t *perf,
const char *name,
cairo_perf_func_t perf_func);
+void
+cairo_perf_cover_sources_and_operators (cairo_perf_t *perf,
+ const char *name,
+ cairo_perf_func_t perf_func);
+
#define CAIRO_PERF_DECL(func) void (func) (cairo_perf_t *perf, cairo_t *cr, int width, int height);
/* paint.c */
diff --git a/perf/paint.c b/perf/paint.c
index 30948d21..6f75016c 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -37,139 +37,8 @@ do_paint (cairo_t *cr, int width, int height)
return cairo_perf_timer_elapsed ();
}
-static void
-init_and_set_source_surface (cairo_t *cr,
- cairo_surface_t *source,
- int width,
- int height)
-{
- cairo_t *cr2;
-
- /* Fill it with something known */
- cr2 = cairo_create (source);
- cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
- cairo_paint (cr2);
-
- cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
- cairo_paint (cr2);
-
- cairo_set_source_rgba (cr2, 1, 0, 0, 0.5); /* 50% red */
- cairo_new_path (cr2);
- cairo_rectangle (cr2, 0, 0, width/2.0, height/2.0);
- cairo_rectangle (cr2, width/2.0, height/2.0, width/2.0, height/2.0);
- cairo_fill (cr2);
- cairo_destroy (cr2);
-
- cairo_set_source_surface (cr, source, 0, 0);
-}
-
-static void
-set_source_solid_rgb (cairo_t *cr,
- int width,
- int height)
-{
- cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
-}
-
-static void
-set_source_solid_rgba (cairo_t *cr,
- int width,
- int height)
-{
- cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
-}
-
-static void
-set_source_image_surface_rgb (cairo_t *cr,
- int width,
- int height)
-{
- cairo_surface_t *source;
-
- source = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
- width, height);
- init_and_set_source_surface (cr, source, width, height);
-
- cairo_surface_destroy (source);
-}
-
-static void
-set_source_image_surface_rgba (cairo_t *cr,
- int width,
- int height)
-{
- cairo_surface_t *source;
-
- source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- width, height);
- init_and_set_source_surface (cr, source, width, height);
-
- cairo_surface_destroy (source);
-}
-
-static void
-set_source_similar_surface_rgb (cairo_t *cr,
- int width,
- int height)
-{
- cairo_surface_t *source;
-
- source = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR,
- width, height);
- init_and_set_source_surface (cr, source, width, height);
-
- cairo_surface_destroy (source);
-}
-
-static void
-set_source_similar_surface_rgba (cairo_t *cr,
- int width,
- int height)
-{
- cairo_surface_t *source;
-
- source = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA,
- width, height);
- init_and_set_source_surface (cr, source, width, height);
-
- cairo_surface_destroy (source);
-}
-
-typedef void (*set_source_func_t) (cairo_t *cr, int width, int height);
-#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
-
void
paint (cairo_perf_t *perf, cairo_t *cr, int width, int height)
{
- unsigned int i, j;
- char *name;
-
- struct { set_source_func_t set_source; const char *name; } sources[] = {
- { set_source_solid_rgb, "solid_source_rgb" },
- { set_source_solid_rgba, "solid_source_rgba" },
- { set_source_image_surface_rgb, "image_surface_rgb" },
- { set_source_image_surface_rgba, "image_surface_rgba" },
- { set_source_similar_surface_rgb, "similar_surface_rgb" },
- { set_source_similar_surface_rgba, "similar_surface_rgba" }
- };
-
- struct { cairo_operator_t op; const char *name; } operators[] = {
- { CAIRO_OPERATOR_OVER, "over" },
- { CAIRO_OPERATOR_SOURCE, "source" }
- };
-
- for (i = 0; i < ARRAY_SIZE (sources); i++) {
- (sources[i].set_source) (cr, width, height);
-
- for (j = 0; j < ARRAY_SIZE (operators); j++) {
- cairo_set_operator (cr, operators[j].op);
-
- xasprintf (&name, "paint_%s_%s", sources[i].name, operators[j].name);
- cairo_perf_run (perf, name, do_paint);
- free (name);
- }
- }
+ cairo_perf_cover_sources_and_operators (perf, "paint", do_paint);
}