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

Side by Side Diff: bench/XfermodeBench.cpp

Issue 1140643004: Add _aa variants of Xfermode benches. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: go Created 5 years, 7 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 | « bench/Benchmark.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "Benchmark.h" 9 #include "Benchmark.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkPaint.h" 11 #include "SkPaint.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 #include "SkXfermode.h" 14 #include "SkXfermode.h"
15 15
16 // Benchmark that draws non-AA rects with an SkXfermode::Mode 16 // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
17 class XfermodeBench : public Benchmark { 17 class XfermodeBench : public Benchmark {
18 public: 18 public:
19 XfermodeBench(SkXfermode::Mode mode) { 19 XfermodeBench(SkXfermode::Mode mode, bool aa) {
20 fXfermode.reset(SkXfermode::Create(mode)); 20 fXfermode.reset(SkXfermode::Create(mode));
21 fAA = aa;
21 SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode); 22 SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode);
22 fName.printf("Xfermode_%s", SkXfermode::ModeName(mode)); 23 fName.printf("Xfermode_%s%s", SkXfermode::ModeName(mode), aa ? "_aa" : " ");
23 } 24 }
24 25
25 XfermodeBench(SkXfermode* xferMode, const char* name) { 26 XfermodeBench(SkXfermode* xferMode, const char* name, bool aa) {
26 SkASSERT(xferMode); 27 SkASSERT(xferMode);
27 fXfermode.reset(xferMode); 28 fXfermode.reset(xferMode);
28 fName.printf("Xfermode_%s", name); 29 fAA = aa;
30 fName.printf("Xfermode_%s%s", name, aa ? "_aa" : "");
29 } 31 }
30 32
31 protected: 33 protected:
32 const char* onGetName() override { return fName.c_str(); } 34 const char* onGetName() override { return fName.c_str(); }
33 35
34 void onDraw(const int loops, SkCanvas* canvas) override { 36 void onDraw(const int loops, SkCanvas* canvas) override {
37 const char* text = "Hamburgefons";
38 size_t len = strlen(text);
35 SkISize size = canvas->getDeviceSize(); 39 SkISize size = canvas->getDeviceSize();
36 SkRandom random; 40 SkRandom random;
37 for (int i = 0; i < loops; ++i) { 41 for (int i = 0; i < loops; ++i) {
38 SkPaint paint; 42 SkPaint paint;
39 paint.setXfermode(fXfermode.get()); 43 paint.setXfermode(fXfermode.get());
40 paint.setColor(random.nextU()); 44 paint.setColor(random.nextU());
41 SkScalar w = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntTo Scalar(kMaxSize)); 45 if (fAA) {
42 SkScalar h = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntTo Scalar(kMaxSize)); 46 // Draw text to exercise AA code paths.
43 SkRect rect = SkRect::MakeXYWH( 47 paint.setAntiAlias(true);
44 random.nextUScalar1() * (size.fWidth - w), 48 paint.setTextSize(random.nextRangeScalar(12, 96));
45 random.nextUScalar1() * (size.fHeight - h), 49 SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth),
46 w, 50 y = random.nextRangeScalar(0, (SkScalar)size.fHeight);
47 h 51 for (int j = 0; j < 1000; ++j) {
48 ); 52 canvas->drawText(text, len, x, y, paint);
49 for (int j = 0; j < 1000; ++j) { 53 }
50 canvas->drawRect(rect, paint); 54 } else {
55 // Draw rects to exercise non-AA code paths.
56 SkScalar w = random.nextRangeScalar(50, 100);
57 SkScalar h = random.nextRangeScalar(50, 100);
58 SkRect rect = SkRect::MakeXYWH(
59 random.nextUScalar1() * (size.fWidth - w),
60 random.nextUScalar1() * (size.fHeight - h),
61 w,
62 h
63 );
64 for (int j = 0; j < 1000; ++j) {
65 canvas->drawRect(rect, paint);
66 }
51 } 67 }
52 } 68 }
53 } 69 }
54 70
55 private: 71 private:
56 enum {
57 kMinSize = 50,
58 kMaxSize = 100,
59 };
60 SkAutoTUnref<SkXfermode> fXfermode; 72 SkAutoTUnref<SkXfermode> fXfermode;
61 SkString fName; 73 SkString fName;
74 bool fAA;
62 75
63 typedef Benchmark INHERITED; 76 typedef Benchmark INHERITED;
64 }; 77 };
65 78
66 class XferCreateBench : public Benchmark { 79 class XferCreateBench : public Benchmark {
67 public: 80 public:
68 bool isSuitableFor(Backend backend) override { 81 bool isSuitableFor(Backend backend) override {
69 return backend == kNonRendering_Backend; 82 return backend == kNonRendering_Backend;
70 } 83 }
71 84
72 protected: 85 protected:
73 const char* onGetName() override { return "xfermode_create"; } 86 const char* onGetName() override { return "xfermode_create"; }
74 87
75 void onDraw(const int loops, SkCanvas* canvas) override { 88 void onDraw(const int loops, SkCanvas* canvas) override {
76 for (int outer = 0; outer < loops * 10; ++outer) { 89 for (int outer = 0; outer < loops * 10; ++outer) {
77 for (int i = 0; i <= SkXfermode::kLastMode; ++i) { 90 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
78 SkXfermode* xfer = SkXfermode::Create(SkXfermode::Mode(i)); 91 SkXfermode* xfer = SkXfermode::Create(SkXfermode::Mode(i));
79 SkSafeUnref(xfer); 92 SkSafeUnref(xfer);
80 } 93 }
81 } 94 }
82 } 95 }
83 96
84 private: 97 private:
85 typedef Benchmark INHERITED; 98 typedef Benchmark INHERITED;
86 }; 99 };
87 100
88 ////////////////////////////////////////////////////////////////////////////// 101 //////////////////////////////////////////////////////////////////////////////
89 102
90 #define CONCAT_I(x, y) x ## y 103 #define BENCH(...) \
91 #define CONCAT(x, y) CONCAT_I(x, y) // allow for macro expansion 104 DEF_BENCH( return new XfermodeBench(__VA_ARGS__, true); ) \
92 #define BENCH(...) \ 105 DEF_BENCH( return new XfermodeBench(__VA_ARGS__, false); )
93 DEF_BENCH( return new XfermodeBench(__VA_ARGS__); );\
94
95 106
96 BENCH(SkXfermode::kClear_Mode) 107 BENCH(SkXfermode::kClear_Mode)
97 BENCH(SkXfermode::kSrc_Mode) 108 BENCH(SkXfermode::kSrc_Mode)
98 BENCH(SkXfermode::kDst_Mode) 109 BENCH(SkXfermode::kDst_Mode)
99 BENCH(SkXfermode::kSrcOver_Mode) 110 BENCH(SkXfermode::kSrcOver_Mode)
100 BENCH(SkXfermode::kDstOver_Mode) 111 BENCH(SkXfermode::kDstOver_Mode)
101 BENCH(SkXfermode::kSrcIn_Mode) 112 BENCH(SkXfermode::kSrcIn_Mode)
102 BENCH(SkXfermode::kDstIn_Mode) 113 BENCH(SkXfermode::kDstIn_Mode)
103 BENCH(SkXfermode::kSrcOut_Mode) 114 BENCH(SkXfermode::kSrcOut_Mode)
104 BENCH(SkXfermode::kDstOut_Mode) 115 BENCH(SkXfermode::kDstOut_Mode)
(...skipping 15 matching lines...) Expand all
120 BENCH(SkXfermode::kDifference_Mode) 131 BENCH(SkXfermode::kDifference_Mode)
121 BENCH(SkXfermode::kExclusion_Mode) 132 BENCH(SkXfermode::kExclusion_Mode)
122 BENCH(SkXfermode::kMultiply_Mode) 133 BENCH(SkXfermode::kMultiply_Mode)
123 134
124 BENCH(SkXfermode::kHue_Mode) 135 BENCH(SkXfermode::kHue_Mode)
125 BENCH(SkXfermode::kSaturation_Mode) 136 BENCH(SkXfermode::kSaturation_Mode)
126 BENCH(SkXfermode::kColor_Mode) 137 BENCH(SkXfermode::kColor_Mode)
127 BENCH(SkXfermode::kLuminosity_Mode) 138 BENCH(SkXfermode::kLuminosity_Mode)
128 139
129 DEF_BENCH(return new XferCreateBench;) 140 DEF_BENCH(return new XferCreateBench;)
OLDNEW
« no previous file with comments | « bench/Benchmark.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698