OLD | NEW |
---|---|
(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 | |
robertphillips
2014/07/30 14:55:22
offX, offY ? transX, transY ?
bsalomon
2014/07/30 15:46:39
Done.
| |
41 SkScalar x = 0, y = 0; | |
42 | |
robertphillips
2014/07/30 14:55:22
++i ?
bsalomon
2014/07/30 15:46:39
Done.
| |
43 for (int i = 0; i < loops; i++) { | |
44 canvas->save(); | |
45 canvas->translate(x, y); | |
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 x += kRectW + 2; | |
56 if (x > w) { | |
57 x = 0; | |
58 y += kRectH + 2; | |
59 if (y > h) { | |
60 y = 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);) | |
OLD | NEW |