aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ShadowBench.cpp
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2017-05-18 14:31:19 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-18 18:57:24 +0000
commit72f4891bf8e11fed52cb4e524a537f8c8625f093 (patch)
treed571162b30e1d04250c043f1a692d11e987bf909 /bench/ShadowBench.cpp
parent887e557ded0aa606fd5463250a2e8d3abebd7505 (diff)
Add microbench for shadows
Based on Android's shadowgrid2. Change-Id: I33209b6b84fc63a762405c4988afbdbffcc170d6 Reviewed-on: https://skia-review.googlesource.com/17360 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'bench/ShadowBench.cpp')
-rwxr-xr-xbench/ShadowBench.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/bench/ShadowBench.cpp b/bench/ShadowBench.cpp
new file mode 100755
index 0000000000..82c4f95d4b
--- /dev/null
+++ b/bench/ShadowBench.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "Benchmark.h"
+#include "SkCanvas.h"
+#include "SkPaint.h"
+#include "SkDrawShadowRec.h"
+#include "SkShadowUtils.h"
+
+class ShadowBench : public Benchmark {
+// Draws a set of shadowed rrects filling the canvas, in various modes:
+// * opaque or transparent
+// * use analytic fast path or geometric tessellation
+public:
+ ShadowBench(bool transparent, bool forceGeometric)
+ : fTransparent(transparent)
+ , fForceGeometric(forceGeometric) {
+ computeName("shadows");
+ }
+
+ bool isVisual() override { return true; }
+
+protected:
+ enum {
+ kWidth = 640,
+ kHeight = 480,
+ kRRSize = 50,
+ kRRRadius = 6,
+ kRRSpace = 8,
+ kRRStep = kRRSize + kRRSpace,
+ kElevation = 16,
+ kNumRRects = ((kWidth - kRRSpace) / kRRStep)*((kHeight - kRRSpace) / kRRStep)
+ };
+
+ void computeName(const char root[]) {
+ static const char kTransChars[2] = {
+ 'o', 't'
+ };
+ static const char kGeomChars[2] = {
+ 'a', 'g'
+ };
+
+ fBaseName.printf("%s_%c_%c", root, kTransChars[fTransparent], kGeomChars[fForceGeometric]);
+ }
+
+ void genRRects() {
+ int i = 0;
+ for (int x = kRRSpace; x < kWidth - kRRStep; x += kRRStep) {
+ for (int y = kRRSpace; y < kHeight - kRRStep; y += kRRStep) {
+ SkRect rect = SkRect::MakeXYWH(x, y, kRRSize, kRRSize);
+ fRRects[i].addRRect(SkRRect::MakeRectXY(rect, kRRRadius, kRRRadius));
+ ++i;
+ }
+ }
+ SkASSERT(i == kNumRRects);
+ }
+
+ const char* onGetName() override { return fBaseName.c_str(); }
+
+ void onDelayedSetup() override {
+ fRec.fZPlaneParams = SkPoint3::Make(0, 0, kElevation);
+ fRec.fLightPos = SkPoint3::Make(270, 0, 600);
+ fRec.fLightRadius = 800;
+ fRec.fAmbientAlpha = 0.1f;
+ fRec.fSpotAlpha = 0.25f;
+ fRec.fColor = SK_ColorBLACK;
+ fRec.fFlags = 0;
+ if (fTransparent) {
+ fRec.fFlags |= SkShadowFlags::kTransparentOccluder_ShadowFlag;
+ }
+ if (fForceGeometric) {
+ fRec.fFlags |= SkShadowFlags::kGeometricOnly_ShadowFlag;
+ }
+
+ this->genRRects();
+ }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ SkPaint paint;
+ paint.setColor(SK_ColorWHITE);
+ this->setupPaint(&paint);
+
+ for (int i = 0; i < loops; ++i) {
+ // use the private canvas call so we don't include the time to stuff data in the Rec
+ canvas->private_draw_shadow_rec(fRRects[i % kNumRRects], fRec);
+ }
+ }
+
+private:
+ SkString fBaseName;
+
+ SkPath fRRects[kNumRRects];
+ SkDrawShadowRec fRec;
+ int fTransparent;
+ int fForceGeometric;
+
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH(return new ShadowBench(false, false);)
+DEF_BENCH(return new ShadowBench(false, true);)
+DEF_BENCH(return new ShadowBench(true, false);)
+DEF_BENCH(return new ShadowBench(true, true);)
+