summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2014-08-04 15:23:06 -0700
committerBryce Harrington <b.harrington@samsung.com>2014-08-04 15:23:06 -0700
commiteb9e41b15b797e3e4f04c15e9170082c06c04490 (patch)
treedd0631cda5dfc95807af2c1198607ec9e79cdb89
parent5ad3c267a3fd57c7eca8417d49d945dc82120b15 (diff)
parent7cb71d5ed95246a80723550d04fbce102a0f440b (diff)
Merge pull request #131 from Samsung/Issue_130
Issue 130
-rw-r--r--src/cairo-tests/curves.cpp48
-rw-r--r--src/cairo-tests/linear-gradient.cpp54
-rw-r--r--src/cairo-tests/radial-gradient.cpp50
-rw-r--r--src/cairo-tests/transform.cpp38
-rw-r--r--src/skia-tests/curves.cpp30
-rw-r--r--src/skia-tests/linear-gradient.cpp32
-rw-r--r--src/skia-tests/radial-gradient.cpp40
7 files changed, 191 insertions, 101 deletions
diff --git a/src/cairo-tests/curves.cpp b/src/cairo-tests/curves.cpp
index 270e510..e40d3b2 100644
--- a/src/cairo-tests/curves.cpp
+++ b/src/cairo-tests/curves.cpp
@@ -6,17 +6,22 @@
*/
#include <config.h>
-#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
+#include <math.h>
#include "caskbench.h"
#include "caskbench_context.h"
#include "cairo-shapes.h"
+static double delta = 0;
+
int
ca_setup_curves(caskbench_context_t *ctx)
{
+ cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE);
+ cairo_set_line_width (ctx->cairo_cr, 1);
+
return 1;
}
@@ -28,6 +33,47 @@ ca_teardown_curves(void)
int
ca_test_curves(caskbench_context_t *ctx)
{
+ cairo_t *cr = ctx->cairo_cr;
+ int cp = ctx->canvas_width / 2; // center point
+ int rr = ctx->canvas_width / 2;
+ int nn = 32; // must be even
+ double step = (2 * M_PI) / nn;
+
+ for (int i=0; i<ctx->size; i++) {
+ double angle = delta; // in radians
+ double x = cp + rr * cos(angle);
+ double y = cp + rr * sin(angle);
+
+ // begin path
+ cairo_new_path(cr);
+ cairo_move_to (cr, x, y);
+
+ // segments
+ for (int j=0; j<nn; j++) {
+ double r = rr * drand48() / 8.0;
+
+ double angle1 = j * step + delta;
+ double x1 = cp + r * cos(angle1);
+ double y1 = cp + r * sin(angle1);
+
+ double x2 = cp + rr * cos(angle1);
+ double y2 = cp + rr * sin(angle1);
+
+ cairo_curve_to (ctx->cairo_cr,
+ x1, y1,
+ x2, y2, x2,y2);
+ }
+ cairo_close_path(cr);
+ cairoRandomizeColor(ctx);
+
+ // TODO: apply other fill types
+ if (ctx->shape_defaults.fill_type == CB_FILL_SOLID) {
+ cairo_fill (cr);
+ }
+ cairo_stroke (cr);
+
+ }
+ delta += 0.5;
return 1;
}
diff --git a/src/cairo-tests/linear-gradient.cpp b/src/cairo-tests/linear-gradient.cpp
index 9096cd5..6997c81 100644
--- a/src/cairo-tests/linear-gradient.cpp
+++ b/src/cairo-tests/linear-gradient.cpp
@@ -6,19 +6,17 @@
*/
#include <config.h>
-#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
#include "caskbench.h"
#include "caskbench_context.h"
#include "cairo-shapes.h"
+#include <math.h>
int
ca_setup_linear_gradient(caskbench_context_t *ctx)
{
- cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE);
- cairo_set_line_width (ctx->cairo_cr, 1);
return 1;
}
@@ -33,7 +31,19 @@ ca_test_linear_gradient(caskbench_context_t *ctx)
int w = ctx->canvas_width;
int h = ctx->canvas_height;
- // TODO: Implement linear gradient
+ int stops = 2;
+ double x1,y1 ,x2,y2;
+ x1 = y1 = 0;
+ x2 = y2 = 100;
+
+ cairo_t *cr = ctx->cairo_cr;
+ cairo_pattern_t *pattern = cairo_pattern_create_linear (0,0,100,100);
+
+ for (int i = 1; i <= stops; i++) {
+ double red, green, blue, alpha;
+ generate_random_color(red,green,blue,alpha);
+ cairo_pattern_add_color_stop_rgba (pattern, i/(stops), red, green, blue, alpha);
+ }
shapes_t shape;
shape_copy(&ctx->shape_defaults, &shape);
@@ -42,26 +52,30 @@ ca_test_linear_gradient(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;
+ double x = MIN(x1, x2);
+ double y = MIN(y1, y2);
+
+ double width_ratio = float(fabs(x2 - x1)) / float(100);
+ double height_ratio = float(fabs(y2 - y1)) / float(100);
- shape.x = MIN(x1, x2);
- shape.y = MIN(x1, x2);
- shape.width = abs(x2 - x1);
- shape.height = abs(y2 - y1);
+ cairo_save(cr);
+ cairo_translate(cr, x, y);
- cairoRandomizeColor(ctx);
+ cairo_scale(cr, width_ratio, height_ratio);
+ // transform(shape.width/100, 0, 0, shape.height/100, 0, 0)
+ shape.x = 0;
+ shape.y = 0;
+ shape.width = 100;
+ shape.height = 100;
+ shape.fill_type = CB_FILL_LINEAR_GRADIENT;
+
+ cairo_set_source (cr, pattern);
cairoDrawRectangle(ctx, &shape);
- switch (ctx->shape_defaults.fill_type) {
- case CB_FILL_NONE:
- cairo_stroke(ctx->cairo_cr);
- break;
- case CB_FILL_SOLID:
- cairo_fill(ctx->cairo_cr);
- break;
- default:
- break;
- }
- }
+ cairo_fill (cr);
+ cairo_restore(cr);
+ }
+ cairo_pattern_destroy(pattern);
return 1;
}
diff --git a/src/cairo-tests/radial-gradient.cpp b/src/cairo-tests/radial-gradient.cpp
index fbdc4c6..3fef5b6 100644
--- a/src/cairo-tests/radial-gradient.cpp
+++ b/src/cairo-tests/radial-gradient.cpp
@@ -6,19 +6,17 @@
*/
#include <config.h>
-#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
#include "caskbench.h"
#include "caskbench_context.h"
#include "cairo-shapes.h"
+#include <math.h>
int
ca_setup_radial_gradient(caskbench_context_t *ctx)
{
- cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE);
- cairo_set_line_width (ctx->cairo_cr, 1);
return 1;
}
@@ -33,7 +31,16 @@ ca_test_radial_gradient(caskbench_context_t *ctx)
int w = ctx->canvas_width;
int h = ctx->canvas_height;
- // TODO: Implement radial gradient
+ int stops = 2;
+ cairo_pattern_t *pattern = cairo_pattern_create_radial (20,20,20,50,50,70);
+
+ for (int i = 0; i < stops; i++) {
+ double red, green, blue, alpha;
+ generate_random_color(red,green,blue,alpha);
+ cairo_pattern_add_color_stop_rgba (pattern, i/(stops-1), red, green, blue, alpha);
+ }
+
+ cairo_t *cr = ctx->cairo_cr;
shapes_t shape;
shape_copy(&ctx->shape_defaults, &shape);
@@ -42,25 +49,30 @@ ca_test_radial_gradient(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;
+ double x = MIN(x1, x2);
+ double y = MIN(y1, y2);
+
+ double width_ratio = float(fabs(x2 - x1)) / float(100);
+ double height_ratio = float(fabs(y2 - y1)) / float(100);
- shape.x = MIN(x1, x2);
- shape.y = MIN(x1, x2);
- shape.width = abs(x2 - x1);
- shape.height = abs(y2 - y1);
+ cairo_save(cr);
+ cairo_translate(cr,x, y);
- cairoRandomizeColor(ctx);
+ cairo_scale(cr, width_ratio, height_ratio);
+
+ shape.x = 0;
+ shape.y = 0;
+ shape.width = 100;
+ shape.height = 100;
+ shape.fill_type = CB_FILL_LINEAR_GRADIENT;
+
+ cairo_set_source (cr, pattern);
cairoDrawRectangle(ctx, &shape);
- switch (ctx->shape_defaults.fill_type) {
- case CB_FILL_NONE:
- cairo_stroke(ctx->cairo_cr);
- break;
- case CB_FILL_SOLID:
- cairo_fill(ctx->cairo_cr);
- break;
- default:
- break;
- }
+
+ cairo_fill (cr);
+ cairo_restore(cr);
}
+ cairo_pattern_destroy(pattern);
return 1;
}
diff --git a/src/cairo-tests/transform.cpp b/src/cairo-tests/transform.cpp
index 25873cd..13461e2 100644
--- a/src/cairo-tests/transform.cpp
+++ b/src/cairo-tests/transform.cpp
@@ -32,24 +32,30 @@ ca_test_transform(caskbench_context_t *ctx)
{
int w = ctx->canvas_width;
int h = ctx->canvas_height;
+ double rotation_delta(0.02*180/M_PI);
+ cairo_t *cr = ctx->cairo_cr;
- shapes_t shape;
- shape_copy(&ctx->shape_defaults, &shape);
- for (int i=0; i<ctx->size; i++) {
- double x1 = (double)rand()/RAND_MAX * w;
- double x2 = (double)rand()/RAND_MAX * w;
- double y1 = (double)rand()/RAND_MAX * h;
- double y2 = (double)rand()/RAND_MAX * h;
-
- shape.x = x1;
- shape.y = y1;
- shape.width = x1 - x2;
- shape.height = y1 - y2;
-
- cairoRandomizeColor(ctx);
- cairoDrawLine(ctx, &shape);
- cairo_stroke(ctx->cairo_cr);
+ cairo_save (cr);
+ for (int nn=0; nn<ctx->size; nn++) {
+ for (int i=0; i<w; i+=50) {
+ cairo_new_path (cr);
+ cairo_move_to (cr, i, 0);
+ cairo_line_to (cr, i, h);
+ cairoRandomizeColor(ctx);
+ cairo_stroke (cr);
+ }
+ for (int j=0; j<h; j+=50) {
+ cairo_move_to(cr, 0, j);
+ cairo_line_to(cr, w, j);
+ cairoRandomizeColor(ctx);
+ cairo_stroke (cr);
+ }
+ cairo_translate(cr, w/2.0, h/2.0);
+ cairo_rotate(cr, (1/57.29)*rotation_delta);
+ cairo_scale(cr, 1.004, 0.996);
+ cairo_translate(cr, -w/2.0, -h/2.0);
}
+ cairo_restore (cr);
return 1;
}
diff --git a/src/skia-tests/curves.cpp b/src/skia-tests/curves.cpp
index 9f1b67f..f2b052e 100644
--- a/src/skia-tests/curves.cpp
+++ b/src/skia-tests/curves.cpp
@@ -39,31 +39,32 @@ sk_test_curves(caskbench_context_t *ctx)
int cp = ctx->canvas_width / 2; // center point
int rr = ctx->canvas_width / 2;
int nn = 32; // must be even
- double step = 2 * M_PI / nn;
+ double step = (2 * M_PI) / nn;
+
for (int i=0; i<ctx->size; i++) {
double angle = delta; // in radians
- double x1 = cp + rr * cos(angle);
- double y1 = cp + rr * sin(angle);
+ double x = cp + rr * cos(angle);
+ double y = cp + rr * sin(angle);
+
// begin path
- path.reset();
- path.moveTo(x1, y1);
+ SkPath path;
+ path.moveTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
// segments
- for (int j=0; j<nn; j+=2) {
- double r = (double)rand()/RAND_MAX * rr / 8.0;
+ for (int j=0; j<nn; j++) {
+ double r = rr * (double)rand()/RAND_MAX / 8.0;
- angle = j * step + delta;
- x1 = cp + r * cos(angle);
- y1 = cp + r * sin(angle);
+ double angle = j * step + delta;
- angle = (j+1) * step + delta;
+ double x1 = cp + r * cos(angle);
+ double y1 = cp + r * sin(angle);
double x2 = cp + rr * cos(angle);
double y2 = cp + rr * sin(angle);
- path.rQuadTo(x1, y1,
- x2, y2);
+ path.quadTo(SkDoubleToScalar(x1), SkDoubleToScalar(y1),
+ SkDoubleToScalar(x2), SkDoubleToScalar(y2));
}
skiaRandomizePaintColor(ctx);
@@ -73,9 +74,10 @@ sk_test_curves(caskbench_context_t *ctx)
ctx->skia_paint->setStyle(SkPaint::kStrokeAndFill_Style);
}
+ path.close();
ctx->skia_canvas->drawPath(path, *(ctx->skia_paint));
}
- delta += 0.05;
+ delta += 0.5;
return 1;
}
diff --git a/src/skia-tests/linear-gradient.cpp b/src/skia-tests/linear-gradient.cpp
index 6cfa58e..f2c776b 100644
--- a/src/skia-tests/linear-gradient.cpp
+++ b/src/skia-tests/linear-gradient.cpp
@@ -39,20 +39,22 @@ sk_test_linear_gradient(caskbench_context_t *ctx)
{
int w = ctx->canvas_width;
int h = ctx->canvas_height;
- SkShader *shader = NULL;
+ int stops = 2;
+
+ SkPoint pts[2];
+ pts[0].iset(0, 0);
+ pts[1].iset(100, 100);
SkColor colors[10];
- SkPoint points[2];
+ SkScalar pos[10];
- for (int i=0; i<NUM_ELEM(colors); i++)
+ for (int i = 0; i < stops; i++) {
+ pos[i] = i / SkIntToScalar(stops - 1);
colors[i] = skiaRandomColor();
- points[0].fX = SkIntToScalar(0);
- points[0].fY = SkIntToScalar(0);
- points[1].fX = SkIntToScalar(100);
- points[1].fY = SkIntToScalar(100);
+ }
- shader = SkGradientShader::CreateLinear(
- points, colors, NULL, NUM_ELEM(colors),
- SkShader::kClamp_TileMode);
+ SkShader *shader = SkGradientShader::CreateLinear(pts, colors, pos, stops,
+ SkShader::kClamp_TileMode);
+ ctx->skia_paint->setShader(shader);
shapes_t shape;
shape_copy(&ctx->shape_defaults, &shape);
@@ -67,6 +69,10 @@ sk_test_linear_gradient(caskbench_context_t *ctx)
double ww = abs(x2 - x1);
double hh = abs(y2 - y1);
+ ctx->skia_canvas->save();
+ ctx->skia_canvas->translate(SkDoubleToScalar(xx), SkDoubleToScalar(yy));
+ ctx->skia_canvas->scale(SkDoubleToScalar(ww/100), SkDoubleToScalar(hh/100));
+
// transform(shape.width/100, 0, 0, shape.height/100, 0, 0)
shape.x = 0;
shape.y = 0;
@@ -77,12 +83,12 @@ sk_test_linear_gradient(caskbench_context_t *ctx)
ctx->skia_paint->setStyle(SkPaint::kFill_Style);
ctx->skia_paint->setShader(shader);
- skiaRandomizePaintColor(ctx);
skiaDrawRectangle(ctx, &shape);
- if (shader)
- shader->unref();
+ ctx->skia_canvas->restore();
}
+ if (shader)
+ shader->unref();
return 1;
}
diff --git a/src/skia-tests/radial-gradient.cpp b/src/skia-tests/radial-gradient.cpp
index 62d7fe1..21025a8 100644
--- a/src/skia-tests/radial-gradient.cpp
+++ b/src/skia-tests/radial-gradient.cpp
@@ -33,25 +33,25 @@ sk_test_radial_gradient(caskbench_context_t *ctx)
{
int w = ctx->canvas_width;
int h = ctx->canvas_height;
- SkColor colors[10];
- SkPoint center;
+ int stops = 2;
- center.fX = SkIntToScalar(20);
- center.fY = SkIntToScalar(20);
+ SkPoint pts[2];
+ pts[0].iset(20, 20);
+ pts[1].iset(50, 50);
+ SkScalar radii[2];
+ radii[0] = 20.0f;
+ radii[1] = 70.0f;
+ SkColor colors[10];
+ SkScalar pos[10];
- for (int i=0; i<NUM_ELEM(colors); i++)
+ for (int i = 0; i < stops; i++) {
+ pos[i] = i / SkIntToScalar(stops - 1);
colors[i] = skiaRandomColor();
+ }
- SkShader* shader = NULL;
- shader = SkGradientShader::CreateRadial(
- center, 20,
- colors, NULL, NUM_ELEM(colors),
- SkShader::kClamp_TileMode);
-
- // TODO: the HTML5 createRadialGradiet() routine
- // actually creates a conical gradient: A gradient
- // is made between two circles C1 and C2.
- // x0=20, y0=20, r0=20, x1=50, y1=50, r1=70
+ SkShader *shader = SkGradientShader::CreateTwoPointRadial(pts[0], radii[0],
+ pts[1], radii[1], colors, pos, stops,
+ SkShader::kClamp_TileMode);
shapes_t shape;
shape_copy(&ctx->shape_defaults, &shape);
@@ -66,6 +66,10 @@ sk_test_radial_gradient(caskbench_context_t *ctx)
double ww = abs(x2 - x1);
double hh = abs(y2 - y1);
+ ctx->skia_canvas->save();
+ ctx->skia_canvas->translate(SkDoubleToScalar(xx), SkDoubleToScalar(yy));
+ ctx->skia_canvas->scale(SkDoubleToScalar(ww/100), SkDoubleToScalar(hh/100));
+
// transform(shape.width/100, 0, 0, shape.height/100, 0, 0)
shape.x = 0;
shape.y = 0;
@@ -73,16 +77,16 @@ sk_test_radial_gradient(caskbench_context_t *ctx)
shape.height = 100;
shape.fill_type = CB_FILL_RADIAL_GRADIENT;
- skiaRandomizePaintColor(ctx);
ctx->skia_paint->setStyle(SkPaint::kFill_Style);
ctx->skia_paint->setShader(shader);
skiaDrawRectangle(ctx, &shape);
+ ctx->skia_canvas->restore();
- if (shader)
- shader->unref();
}
+ if (shader)
+ shader->unref();
return 1;
}