Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: bench/RotatedRectBench.cpp

Issue 425263003: Add rotated rects benchmarks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/RotatedRectBench.cpp
diff --git a/bench/RotatedRectBench.cpp b/bench/RotatedRectBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..522d358c3b4653f443c4988a0d095e4c55fededc
--- /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);)
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698