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

Side by Side 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, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Benchmark.h"
9 #include "SkCanvas.h"
10 #include "SkPaint.h"
11
12 /** This benchmark tests rendering rotated rectangles. It can optionally apply A A and/or change the
13 paint color between each rect. */
14 class RotRectBench: public Benchmark {
15 public:
16 RotRectBench(bool aa, bool changeColor)
17 : fAA(aa)
18 , fChangeColor(changeColor) {
19 this->makeName();
20 }
21
22 protected:
23 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); }
24
25 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
26 SkPaint paint;
27 paint.setAntiAlias(fAA);
28 SkColor color = 0xFF000000;
29
30 int w = canvas->getBaseLayerSize().width();
31 int h = canvas->getBaseLayerSize().height();
32
33 static const SkScalar kRectW = 25.1f;
34 static const SkScalar kRectH = 25.9f;
35
36 SkMatrix rotate;
37 // This value was chosen so that we frequently hit the axis-aligned case .
38 rotate.setRotate(30.f, kRectW / 2, kRectH / 2);
39 SkMatrix m = rotate;
40
41 SkScalar tx = 0, ty = 0;
42
43 for (int i = 0; i < loops; ++i) {
44 canvas->save();
45 canvas->translate(tx, ty);
46 canvas->concat(m);
47 paint.setColor(color);
48 if (fChangeColor) {
49 color += 0x010203;
50 color |= 0xFF000000;
51 }
52 canvas->drawRect(SkRect::MakeWH(kRectW, kRectH), paint);
53 canvas->restore();
54
55 tx += kRectW + 2;
56 if (tx > w) {
57 tx = 0;
58 ty += kRectH + 2;
59 if (ty > h) {
60 ty = 0;
61 }
62 }
63
64 m.postConcat(rotate);
65 }
66 }
67
68 private:
69 void makeName() {
70 fName = "rotated_rects";
71 if (fAA) {
72 fName.append("_aa");
73 } else {
74 fName.append("_bw");
75 }
76 if (fChangeColor) {
77 fName.append("_change_color");
78 } else {
79 fName.append("_same_color");
80 }
81 }
82
83 bool fAA;
84 bool fChangeColor;
85 SkString fName;
86
87 typedef Benchmark INHERITED;
88 };
89
90 DEF_BENCH(return new RotRectBench(true, true);)
91 DEF_BENCH(return new RotRectBench(true, false);)
92 DEF_BENCH(return new RotRectBench(false, true);)
93 DEF_BENCH(return new RotRectBench(false, false);)
OLDNEW
« 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