diff options
| author | Bryce Harrington <b.harrington@samsung.com> | 2014-07-24 16:51:14 -0700 |
|---|---|---|
| committer | Bryce Harrington <b.harrington@samsung.com> | 2014-07-25 18:11:34 -0700 |
| commit | 69f2b4bcb842b8f2ab6a82bf9295a6608d227fe9 (patch) | |
| tree | 2a719367581b05ea5e819f6387534abb8208a0f5 | |
| parent | 7acc2130fcb4dd4e0375560ce7978002f2d2d2bb (diff) | |
tests: Implement Skia curves test
Cairo curves test is stubbed out.
| -rw-r--r-- | src/cairo-tests/curves.cpp | 43 | ||||
| -rw-r--r-- | src/skia-tests/curves.cpp | 92 | ||||
| -rwxr-xr-x | utils/canvas_perf | 4 |
3 files changed, 137 insertions, 2 deletions
diff --git a/src/cairo-tests/curves.cpp b/src/cairo-tests/curves.cpp new file mode 100644 index 0000000..270e510 --- /dev/null +++ b/src/cairo-tests/curves.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2014 © Samsung Research America, Silicon Valley + * + * Use of this source code is governed by the 3-Clause BSD license + * specified in the COPYING file included with this source code. + */ +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <cairo.h> + +#include "caskbench.h" +#include "caskbench_context.h" +#include "cairo-shapes.h" + +int +ca_setup_curves(caskbench_context_t *ctx) +{ + return 1; +} + +void +ca_teardown_curves(void) +{ +} + +int +ca_test_curves(caskbench_context_t *ctx) +{ + return 1; +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/skia-tests/curves.cpp b/src/skia-tests/curves.cpp new file mode 100644 index 0000000..9f1b67f --- /dev/null +++ b/src/skia-tests/curves.cpp @@ -0,0 +1,92 @@ +/* + * Copyright 2014 © Samsung Research America, Silicon Valley + * + * Use of this source code is governed by the 3-Clause BSD license + * specified in the COPYING file included with this source code. + */ +#include <config.h> + +#include <math.h> + +#include <SkCanvas.h> +#include <SkPaint.h> +#include <SkRect.h> + +#include "caskbench.h" +#include "caskbench_context.h" +#include "skia-shapes.h" + +static double delta = 0; + +int +sk_setup_curves(caskbench_context_t *ctx) +{ + ctx->skia_paint->setAntiAlias(false); + ctx->skia_paint->setStrokeWidth(1); + ctx->skia_paint->setStyle(SkPaint::kStroke_Style); + return 1; +} + +void +sk_teardown_curves(void) +{ +} + +int +sk_test_curves(caskbench_context_t *ctx) +{ + SkPath path; + 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 x1 = cp + rr * cos(angle); + double y1 = cp + rr * sin(angle); + + // begin path + path.reset(); + path.moveTo(x1, y1); + + // segments + for (int j=0; j<nn; j+=2) { + double r = (double)rand()/RAND_MAX * rr / 8.0; + + angle = j * step + delta; + x1 = cp + r * cos(angle); + y1 = cp + r * sin(angle); + + angle = (j+1) * step + delta; + double x2 = cp + rr * cos(angle); + double y2 = cp + rr * sin(angle); + + path.rQuadTo(x1, y1, + x2, y2); + } + + skiaRandomizePaintColor(ctx); + + // TODO: apply other fill types + if (ctx->shape_defaults.fill_type == CB_FILL_SOLID) { + ctx->skia_paint->setStyle(SkPaint::kStrokeAndFill_Style); + } + + ctx->skia_canvas->drawPath(path, *(ctx->skia_paint)); + } + delta += 0.05; + + return 1; +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/utils/canvas_perf b/utils/canvas_perf index 5e42f18..8db6e8b 100755 --- a/utils/canvas_perf +++ b/utils/canvas_perf @@ -26,8 +26,8 @@ perfdefs = [ [ "bezier", 1000, 3, ["cubic"] ], [ "fill_bezier", 1000, 4, ["cubic", "-f", "solid"] ], [ "quad", 1000, 4, ["quadratic"] ], -# [ "curves", 50, 5, ["curves", "-f", "none"] ], -# [ "fill_curves", 50, 8, ["curves", "-f", "solid"] ], + [ "curves", 50, 5, ["curves", "-f", "none"] ], + [ "fill_curves", 50, 8, ["curves", "-f", "solid"] ], [ "stroke_star", 1000, 7, ["star", "-f", "none"] ], [ "fill_star", 1000, 12, ["star", "-f", "solid"] ], # [ "transform", 10, 0.2, ["transform"] ], |