summaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2014-06-18 21:47:36 +0900
committerBryce Harrington <b.harrington@samsung.com>2014-06-18 21:47:36 +0900
commitab1408df117d2a2a58bce9e43b10e2a87a663e5f (patch)
tree61f4a6aba53fb6bf922e27559f789fb28f852573 /src
parentcb2cd9b7c3893e4b6ef55599b2ddcaef6456ad4c (diff)
parentf74cf6e5db73f21330b88f9f090d8f76d9c120f8 (diff)
Merge pull request #100 from Samsung/Issue_26
Issue #26 Add test for shadow caching.
Diffstat (limited to 'src')
-rw-r--r--src/cairo-tests/shadow.cpp159
-rw-r--r--src/skia-tests/shadow.cpp149
2 files changed, 308 insertions, 0 deletions
diff --git a/src/cairo-tests/shadow.cpp b/src/cairo-tests/shadow.cpp
new file mode 100644
index 0000000..b742b88
--- /dev/null
+++ b/src/cairo-tests/shadow.cpp
@@ -0,0 +1,159 @@
+/*
+ * 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 <math.h>
+
+#include "caskbench.h"
+#include "caskbench_context.h"
+#include "cairo-shapes.h"
+#include "kinetics.h"
+
+static double line_width;
+
+static double shadow_x_blur;
+static double shadow_y_blur;
+
+static double spread_line_width;
+static double spread_x_blur;
+static double spread_y_blur;
+
+static double drop_x_blur;
+static double drop_y_blur;
+static double drop_x_offset;
+static double drop_y_offset;
+static double drop_line_width;
+
+static double x_offset;
+static double y_offset;
+
+static kinetics_t *particles;
+
+static void particle_init ()
+{
+ line_width = 20.0;
+
+ /* Inset shadow */
+ shadow_x_blur = 5;
+ shadow_y_blur = 2;
+
+ x_offset = 6;
+ y_offset = 1;
+
+ /* Spread */
+ spread_x_blur = 5;
+ spread_y_blur = 2;
+ spread_line_width = 3;
+
+ /* Drop shadow */
+ drop_x_blur = 10;
+ drop_y_blur = 8;
+ drop_x_offset = -30;
+ drop_y_offset = -5;
+ drop_line_width = line_width;
+}
+
+static void fill_particle (caskbench_context_t *ctx, shapes_t *shape)
+{
+ cairo_t *cr = ctx->cairo_cr;
+ /* Drop shadow */
+ cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
+ cairo_set_draw_shadow_only (cr, 1);
+ cairo_set_shadow_rgba (cr, 0, 0, 0, 0.5);
+ cairo_set_shadow_offset (cr, drop_x_offset,
+ drop_y_offset);
+ cairo_set_shadow_blur (cr, drop_x_blur,
+ drop_y_blur);
+ cairoDrawCircle (ctx, shape);
+ cairo_set_line_width (cr, drop_line_width);
+ cairo_stroke (cr);
+ /* Ring */
+ cairoRandomizeColor (ctx);
+ cairo_set_shadow (cr, CAIRO_SHADOW_INSET);
+ cairo_set_draw_shadow_only (cr, 0);
+
+ // cairo_set_shadow_rgba (cr, 0, 0, 0, 1); /* Disable shadow masking to make output similar to skia */
+ cairo_set_shadow_offset (cr, x_offset,
+ y_offset);
+ cairo_set_shadow_blur (cr, shadow_x_blur,
+ shadow_y_blur);
+ cairoDrawCircle (ctx,shape);
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+ /* Spread */
+ cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
+ cairo_set_draw_shadow_only (cr, 1);
+ cairo_set_shadow_rgba (cr, 1, 1, 1, 1);
+ cairo_set_shadow_offset (cr, x_offset,
+ y_offset);
+ cairo_set_shadow_blur (cr, spread_x_blur,
+ spread_y_blur);
+ cairoDrawCircle (ctx,shape);
+ cairo_set_line_width (cr, spread_line_width);
+ cairo_stroke (cr);
+}
+
+int
+ca_setup_shadow(caskbench_context_t *ctx)
+{
+ if (ctx->size < 0)
+ return 0;
+ // Animation & Shadow setup
+ particles = (kinetics_t *) malloc (sizeof (kinetics_t) * ctx->size);
+ for (int i = 0; i < ctx->size; i++)
+ kinetics_init(&particles[i], ctx);
+
+ particle_init ();
+ return 1;
+}
+
+void
+ca_teardown_shadow(void)
+{
+ free(particles);
+}
+
+int
+ca_test_shadow(caskbench_context_t *ctx)
+{
+ cairo_set_source_rgb (ctx->cairo_cr, 1, 1, 1);
+ cairo_rectangle (ctx->cairo_cr, 0, 0, ctx->canvas_width ,ctx->canvas_height);
+ cairo_fill (ctx->cairo_cr);
+
+ for (int i = 0; i < ctx->size; i++) {
+ shapes_t shape;
+ kinetics_t *particle = &particles[i];
+ kinetics_update(particle, 0.1);
+
+ shape_copy(&ctx->shape_defaults, &shape);
+ shape.width = particle->width;
+ shape.height = particle->height;
+ shape.x = particle->x;
+ shape.y = particle->y;
+ if (!shape.radius)
+ shape.radius = 40;
+
+ cairo_shadow_enable_cache (ctx->cairo_cr, 1);
+ fill_particle (ctx, &shape);
+ }
+ 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/shadow.cpp b/src/skia-tests/shadow.cpp
new file mode 100644
index 0000000..4e0de46
--- /dev/null
+++ b/src/skia-tests/shadow.cpp
@@ -0,0 +1,149 @@
+/*
+ * 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 <SkCanvas.h>
+#include <effects/SkGradientShader.h>
+
+#include "forward.h"
+#include "caskbench.h"
+#include "caskbench_context.h"
+#include "skia-shapes.h"
+#include "kinetics.h"
+#include "SkBlurMaskFilter.h"
+
+static double line_width;
+
+static double shadow_x_blur;
+static double shadow_y_blur;
+
+static double spread_line_width;
+static double spread_x_blur;
+static double spread_y_blur;
+
+static double drop_x_blur;
+static double drop_y_blur;
+static double drop_x_offset;
+static double drop_y_offset;
+static double drop_line_width;
+
+static double x_offset;
+static double y_offset;
+
+SkMaskFilter *mf,*mf_spread;
+static kinetics_t *particles;
+
+static void particle_init ()
+{
+ line_width = 20.0;
+
+ /* Inset shadow */
+ shadow_x_blur = 5;
+ shadow_y_blur = 2;
+
+ x_offset = 6;
+ y_offset = 1;
+
+ /* Spread */
+ spread_x_blur = 5;
+ spread_y_blur = 2;
+ spread_line_width = 3;
+
+ /* Drop shadow */
+ drop_x_blur = 10;
+ drop_y_blur = 8;
+ drop_x_offset = -30;
+ drop_y_offset = -5;
+ drop_line_width = line_width;
+
+ SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
+ mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kInner_BlurStyle, (SkDoubleToScalar(drop_line_width)), flags);
+ flags = SkBlurMaskFilter::kNone_BlurFlag;
+ mf_spread = SkBlurMaskFilter::Create(SkBlurMaskFilter::kInner_BlurStyle, (SkDoubleToScalar(spread_line_width)), flags);
+}
+
+static void fill_particle (caskbench_context_t *ctx, shapes_t *shape)
+{
+ SkPaint *paint = ctx->skia_paint;
+ SkCanvas *canvas = ctx->skia_canvas;
+ /* Drop shadow */
+ paint->setMaskFilter(mf);
+ paint->setStrokeWidth(drop_line_width);
+ paint->setARGB(255*0.5, 0, 0, 0);
+ canvas->drawCircle(SkDoubleToScalar(shape->x+drop_x_offset), SkDoubleToScalar(shape->y+drop_y_offset), 40, *paint);
+ paint->setMaskFilter(mf_spread);
+ paint->setARGB(255, 0, 0, 0);
+ canvas->drawCircle(SkDoubleToScalar(shape->x-shadow_x_blur+3), SkDoubleToScalar(shape->y-shadow_y_blur), 40, *paint);
+ /* Ring */
+ skiaRandomizePaintColor(ctx);
+ paint->setStrokeWidth(line_width);
+ canvas->drawCircle(SkDoubleToScalar(shape->x), SkDoubleToScalar(shape->y), 40, *paint);
+
+ /* Spread */
+ paint->setMaskFilter(mf_spread);
+ paint->setStrokeWidth(spread_line_width);
+ paint->setARGB(255, 255, 255, 255);
+ canvas->drawCircle(SkDoubleToScalar(shape->x+spread_x_blur), SkDoubleToScalar(shape->y+spread_y_blur), 40, *paint);
+}
+
+int
+sk_setup_shadow(caskbench_context_t *ctx)
+{
+ if (ctx->size < 0)
+ return 0;
+ /* Animation & Shadow setup */
+ particles = (kinetics_t *) malloc (sizeof (kinetics_t) * ctx->size);
+ for (int i = 0; i < ctx->size; i++)
+ kinetics_init(&particles[i], ctx);
+
+ particle_init ();
+ /* Set Style and Stroke Width */
+ ctx->skia_paint->setStyle(SkPaint::kStroke_Style);
+ ctx->skia_paint->setStrokeWidth(20);
+
+ return 1;
+}
+
+void
+sk_teardown_shadow(void)
+{
+ free(particles);
+}
+
+int
+sk_test_shadow(caskbench_context_t *ctx)
+{
+ ctx->skia_canvas->drawColor(SK_ColorWHITE);
+
+ for (int i = 0; i < ctx->size; i++) {
+ shapes_t shape;
+ kinetics_t *particle = &particles[i];
+ kinetics_update(particle, 0.1);
+
+ shape_copy(&ctx->shape_defaults, &shape);
+ shape.width = particle->width;
+ shape.height = particle->height;
+ shape.x = particle->x;
+ shape.y = particle->y;
+ if (!shape.radius)
+ shape.radius = 40;
+
+ fill_particle (ctx, &shape);
+ }
+ 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 :