aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/RotatedRectBench.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-07-30 08:58:20 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-30 08:58:20 -0700
commit3342ed55e1e0b2f9f4847250927013ae74e125e3 (patch)
tree486b920257e4b8f3cd2adb56806b339db4f914cf /bench/RotatedRectBench.cpp
parentb5294e8d453866ae0dc5a0304c1ca969ef3c7670 (diff)
Add rotated rects benchmarks
R=robertphillips@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/425263003
Diffstat (limited to 'bench/RotatedRectBench.cpp')
-rw-r--r--bench/RotatedRectBench.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/bench/RotatedRectBench.cpp b/bench/RotatedRectBench.cpp
new file mode 100644
index 0000000000..522d358c3b
--- /dev/null
+++ b/bench/RotatedRectBench.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2014 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"
+
+/** This benchmark tests rendering rotated rectangles. It can optionally apply AA and/or change the
+ paint color between each rect. */
+class RotRectBench: public Benchmark {
+public:
+ RotRectBench(bool aa, bool changeColor)
+ : fAA(aa)
+ , fChangeColor(changeColor) {
+ this->makeName();
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); }
+
+ virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
+ SkPaint paint;
+ paint.setAntiAlias(fAA);
+ SkColor color = 0xFF000000;
+
+ int w = canvas->getBaseLayerSize().width();
+ int h = canvas->getBaseLayerSize().height();
+
+ static const SkScalar kRectW = 25.1f;
+ static const SkScalar kRectH = 25.9f;
+
+ SkMatrix rotate;
+ // This value was chosen so that we frequently hit the axis-aligned case.
+ rotate.setRotate(30.f, kRectW / 2, kRectH / 2);
+ SkMatrix m = rotate;
+
+ SkScalar tx = 0, ty = 0;
+
+ for (int i = 0; i < loops; ++i) {
+ canvas->save();
+ canvas->translate(tx, ty);
+ canvas->concat(m);
+ paint.setColor(color);
+ if (fChangeColor) {
+ color += 0x010203;
+ color |= 0xFF000000;
+ }
+ canvas->drawRect(SkRect::MakeWH(kRectW, kRectH), paint);
+ canvas->restore();
+
+ tx += kRectW + 2;
+ if (tx > w) {
+ tx = 0;
+ ty += kRectH + 2;
+ if (ty > h) {
+ ty = 0;
+ }
+ }
+
+ m.postConcat(rotate);
+ }
+ }
+
+private:
+ void makeName() {
+ fName = "rotated_rects";
+ if (fAA) {
+ fName.append("_aa");
+ } else {
+ fName.append("_bw");
+ }
+ if (fChangeColor) {
+ fName.append("_change_color");
+ } else {
+ fName.append("_same_color");
+ }
+ }
+
+ bool fAA;
+ bool fChangeColor;
+ SkString fName;
+
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH(return new RotRectBench(true, true);)
+DEF_BENCH(return new RotRectBench(true, false);)
+DEF_BENCH(return new RotRectBench(false, true);)
+DEF_BENCH(return new RotRectBench(false, false);)