summaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2014-07-03 12:05:32 -0700
committerBryce Harrington <b.harrington@samsung.com>2014-07-03 12:05:32 -0700
commitb056641ef302205719974aac5f8f4e2e56fe9f3e (patch)
treee0c235c89d4aeeaf42701d483fac97a7af57b3d6 /src
parent47de2e7053b90da347e739a220c698bde8313ce9 (diff)
parent80e178b1ff37e67d7067e91e5ed35a3c163e6c1d (diff)
Merge pull request #122 from Samsung/Issue_104
Issue 104. Image surface caching.
Diffstat (limited to 'src')
-rw-r--r--src/cairo-shapes.cpp15
-rw-r--r--src/cairo-shapes.h2
-rw-r--r--src/cairo-tests/clip.cpp6
-rw-r--r--src/cairo-tests/image-rotate.cpp5
-rw-r--r--src/cairo-tests/image-scale.cpp5
-rw-r--r--src/cairo-tests/image.cpp5
6 files changed, 33 insertions, 5 deletions
diff --git a/src/cairo-shapes.cpp b/src/cairo-shapes.cpp
index 50ce77b..28320ae 100644
--- a/src/cairo-shapes.cpp
+++ b/src/cairo-shapes.cpp
@@ -230,7 +230,20 @@ cairoDrawRoundedRectangle (caskbench_context_t *ctx, shapes_t *args)
#endif
}
-cairo_surface_t *cairoCreateSampleImage (caskbench_context_t *ctx)
+cairo_surface_t *
+cairoCacheImageSurface(caskbench_context_t *ctx, cairo_surface_t *image)
+{
+ cairo_surface_t *cached_image;
+ cached_image = cairo_surface_create_similar (cairo_get_target(ctx->cairo_cr), CAIRO_CONTENT_COLOR_ALPHA, 160, 40);
+ cairo_t *cached_cr = cairo_create (cached_image);
+ cairo_set_source_surface (cached_cr, image, 0, 0);
+ cairo_paint (cached_cr);
+ cairo_destroy (cached_cr);
+ return cached_image;
+}
+
+cairo_surface_t *
+cairoCreateSampleImage (caskbench_context_t *ctx)
{
cairo_surface_t *image;
cairo_t *cr_image;
diff --git a/src/cairo-shapes.h b/src/cairo-shapes.h
index e7247c5..194ee13 100644
--- a/src/cairo-shapes.h
+++ b/src/cairo-shapes.h
@@ -33,6 +33,8 @@ void cairoDrawQuadraticCurve(caskbench_context_t *ctx, shapes_t *args);
cairo_surface_t *cairoCreateSampleImage (caskbench_context_t *ctx);
+cairo_surface_t *cairoCacheImageSurface(caskbench_context_t *ctx, cairo_surface_t *image);
+
extern void (*cairoShapes[CB_SHAPE_END-1])(caskbench_context_t *ctx , shapes_t *args);
void cairoDrawRandomizedShape(caskbench_context_t *ctx, shapes_t *shape);
diff --git a/src/cairo-tests/clip.cpp b/src/cairo-tests/clip.cpp
index 1a88941..680d29d 100644
--- a/src/cairo-tests/clip.cpp
+++ b/src/cairo-tests/clip.cpp
@@ -14,16 +14,20 @@
#include "cairo-shapes.h"
static cairo_surface_t *image;
+static cairo_surface_t *cached_image;
int
ca_setup_clip(caskbench_context_t *ctx)
{
image = cairoCreateSampleImage (ctx);
+ cached_image = cairoCacheImageSurface (ctx, image);
return 1;
}
void
ca_teardown_clip(void)
{
+ cairo_surface_destroy (image);
+ cairo_surface_destroy (cached_image);
}
#if 1
@@ -69,7 +73,7 @@ ca_test_clip(caskbench_context_t *ctx)
double x2 = (double)rand()/RAND_MAX * w;
double y1 = (double)rand()/RAND_MAX * h;
double y2 = (double)rand()/RAND_MAX * h;
- cairo_set_source_surface (cr, image, x1, y1);
+ cairo_set_source_surface (cr, cached_image, x1, y1);
// To scale without blur
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_FAST);
cairo_paint (cr);
diff --git a/src/cairo-tests/image-rotate.cpp b/src/cairo-tests/image-rotate.cpp
index 9a6725d..2563d9c 100644
--- a/src/cairo-tests/image-rotate.cpp
+++ b/src/cairo-tests/image-rotate.cpp
@@ -15,11 +15,13 @@
#include "cairo-shapes.h"
static cairo_surface_t *image;
+static cairo_surface_t *cached_image;
int
ca_setup_image_rotate(caskbench_context_t *ctx)
{
image = cairoCreateSampleImage (ctx);
+ cached_image = cairoCacheImageSurface (ctx, image);
return 1;
}
@@ -27,6 +29,7 @@ void
ca_teardown_image_rotate(void)
{
cairo_surface_destroy (image);
+ cairo_surface_destroy (cached_image);
}
int
@@ -51,7 +54,7 @@ ca_test_image_rotate(caskbench_context_t* ctx)
cairo_translate(cr, w/2, h/2);
cairo_rotate(cr, i / 50.0); // TODO: Original rotates by counter/50
cairo_translate(cr, -iw/2, -ih/2);
- cairo_set_source_surface (cr, image, 0, 0);
+ cairo_set_source_surface (cr, cached_image, 0, 0);
#if 1
cairo_paint (cr);
#else
diff --git a/src/cairo-tests/image-scale.cpp b/src/cairo-tests/image-scale.cpp
index 85f50d7..47e1e65 100644
--- a/src/cairo-tests/image-scale.cpp
+++ b/src/cairo-tests/image-scale.cpp
@@ -16,11 +16,13 @@
#include <math.h>
static cairo_surface_t *image;
+static cairo_surface_t *cached_image;
int
ca_setup_image_scale(caskbench_context_t *ctx)
{
image = cairoCreateSampleImage (ctx);
+ cached_image = cairoCacheImageSurface (ctx, image);
return 1;
}
@@ -28,6 +30,7 @@ void
ca_teardown_image_scale(void)
{
cairo_surface_destroy (image);
+ cairo_surface_destroy (cached_image);
}
int
@@ -53,7 +56,7 @@ ca_test_image_scale(caskbench_context_t *ctx)
cairo_translate(cr,x,y);
cairo_scale(cr, width_ratio, height_ratio);
- cairo_set_source_surface (cr, image, 0, 0);
+ cairo_set_source_surface (cr, cached_image, 0, 0);
// Scale without blur
cairo_pattern_set_filter (cairo_get_source(cr), CAIRO_FILTER_FAST);
#if 1
diff --git a/src/cairo-tests/image.cpp b/src/cairo-tests/image.cpp
index 767b80f..3989899 100644
--- a/src/cairo-tests/image.cpp
+++ b/src/cairo-tests/image.cpp
@@ -15,11 +15,13 @@
#include <cairo-shapes.h>
static cairo_surface_t *image;
+static cairo_surface_t *cached_image;
int
ca_setup_image(caskbench_context_t *ctx)
{
image = cairoCreateSampleImage (ctx);
+ cached_image = cairoCacheImageSurface (ctx, image);
return 1;
}
@@ -27,6 +29,7 @@ void
ca_teardown_image(void)
{
cairo_surface_destroy (image);
+ cairo_surface_destroy (cached_image);
}
int
@@ -44,7 +47,7 @@ ca_test_image(caskbench_context_t* ctx)
for (int i=0; i<ctx->size; i++) {
double x = (double)rand()/RAND_MAX * pw;
double y = (double)rand()/RAND_MAX * ph;
- cairo_set_source_surface (cr, image, x, y);
+ cairo_set_source_surface (cr, cached_image, x, y);
#if 1
cairo_paint (cr);
#else