OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDisplacementMapEffect.h" | 11 #include "SkDisplacementMapEffect.h" |
12 | 12 |
13 #define FILTER_WIDTH_SMALL 32 | 13 #define FILTER_WIDTH_SMALL 32 |
14 #define FILTER_HEIGHT_SMALL 32 | 14 #define FILTER_HEIGHT_SMALL 32 |
15 #define FILTER_WIDTH_LARGE 256 | 15 #define FILTER_WIDTH_LARGE 256 |
16 #define FILTER_HEIGHT_LARGE 256 | 16 #define FILTER_HEIGHT_LARGE 256 |
17 | 17 |
18 class DisplacementBaseBench : public Benchmark { | 18 class DisplacementBaseBench : public Benchmark { |
19 public: | 19 public: |
20 DisplacementBaseBench(bool small) : | 20 DisplacementBaseBench(bool small) : |
21 fInitialized(false), fIsSmall(small) { | 21 fInitialized(false), fIsSmall(small) { |
22 } | 22 } |
23 | 23 |
24 protected: | 24 protected: |
25 void onPreDraw() SK_OVERRIDE { | 25 void onPreDraw() override { |
26 if (!fInitialized) { | 26 if (!fInitialized) { |
27 this->makeBitmap(); | 27 this->makeBitmap(); |
28 this->makeCheckerboard(); | 28 this->makeCheckerboard(); |
29 fInitialized = true; | 29 fInitialized = true; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 void makeBitmap() { | 33 void makeBitmap() { |
34 const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 34 const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
35 const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARG
E; | 35 const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARG
E; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 bool fIsSmall; | 84 bool fIsSmall; |
85 typedef Benchmark INHERITED; | 85 typedef Benchmark INHERITED; |
86 }; | 86 }; |
87 | 87 |
88 class DisplacementZeroBench : public DisplacementBaseBench { | 88 class DisplacementZeroBench : public DisplacementBaseBench { |
89 public: | 89 public: |
90 DisplacementZeroBench(bool small) : INHERITED(small) { | 90 DisplacementZeroBench(bool small) : INHERITED(small) { |
91 } | 91 } |
92 | 92 |
93 protected: | 93 protected: |
94 const char* onGetName() SK_OVERRIDE { | 94 const char* onGetName() override { |
95 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_
large"; | 95 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_
large"; |
96 } | 96 } |
97 | 97 |
98 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 98 void onDraw(const int loops, SkCanvas* canvas) override { |
99 SkPaint paint; | 99 SkPaint paint; |
100 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard))
; | 100 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard))
; |
101 // No displacement effect | 101 // No displacement effect |
102 paint.setImageFilter(SkDisplacementMapEffect::Create( | 102 paint.setImageFilter(SkDisplacementMapEffect::Create( |
103 SkDisplacementMapEffect::kR_ChannelSelectorType, | 103 SkDisplacementMapEffect::kR_ChannelSelectorType, |
104 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre
f(); | 104 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre
f(); |
105 | 105 |
106 for (int i = 0; i < loops; i++) { | 106 for (int i = 0; i < loops; i++) { |
107 this->drawClippedBitmap(canvas, 0, 0, paint); | 107 this->drawClippedBitmap(canvas, 0, 0, paint); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 private: | 111 private: |
112 typedef DisplacementBaseBench INHERITED; | 112 typedef DisplacementBaseBench INHERITED; |
113 }; | 113 }; |
114 | 114 |
115 class DisplacementAlphaBench : public DisplacementBaseBench { | 115 class DisplacementAlphaBench : public DisplacementBaseBench { |
116 public: | 116 public: |
117 DisplacementAlphaBench(bool small) : INHERITED(small) { | 117 DisplacementAlphaBench(bool small) : INHERITED(small) { |
118 } | 118 } |
119 | 119 |
120 protected: | 120 protected: |
121 const char* onGetName() SK_OVERRIDE { | 121 const char* onGetName() override { |
122 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg
e"; | 122 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg
e"; |
123 } | 123 } |
124 | 124 |
125 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 125 void onDraw(const int loops, SkCanvas* canvas) override { |
126 SkPaint paint; | 126 SkPaint paint; |
127 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard))
; | 127 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard))
; |
128 // Displacement, with 1 alpha component (which isn't pre-multiplied) | 128 // Displacement, with 1 alpha component (which isn't pre-multiplied) |
129 paint.setImageFilter(SkDisplacementMapEffect::Create( | 129 paint.setImageFilter(SkDisplacementMapEffect::Create( |
130 SkDisplacementMapEffect::kB_ChannelSelectorType, | 130 SkDisplacementMapEffect::kB_ChannelSelectorType, |
131 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr
ef(); | 131 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr
ef(); |
132 for (int i = 0; i < loops; i++) { | 132 for (int i = 0; i < loops; i++) { |
133 drawClippedBitmap(canvas, 100, 0, paint); | 133 drawClippedBitmap(canvas, 100, 0, paint); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 private: | 137 private: |
138 typedef DisplacementBaseBench INHERITED; | 138 typedef DisplacementBaseBench INHERITED; |
139 }; | 139 }; |
140 | 140 |
141 class DisplacementFullBench : public DisplacementBaseBench { | 141 class DisplacementFullBench : public DisplacementBaseBench { |
142 public: | 142 public: |
143 DisplacementFullBench(bool small) : INHERITED(small) { | 143 DisplacementFullBench(bool small) : INHERITED(small) { |
144 } | 144 } |
145 | 145 |
146 protected: | 146 protected: |
147 const char* onGetName() SK_OVERRIDE { | 147 const char* onGetName() override { |
148 return isSmall() ? "displacement_full_small" : "displacement_full_large"
; | 148 return isSmall() ? "displacement_full_small" : "displacement_full_large"
; |
149 } | 149 } |
150 | 150 |
151 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 151 void onDraw(const int loops, SkCanvas* canvas) override { |
152 SkPaint paint; | 152 SkPaint paint; |
153 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard))
; | 153 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard))
; |
154 // Displacement, with 2 non-alpha components | 154 // Displacement, with 2 non-alpha components |
155 paint.setImageFilter(SkDisplacementMapEffect::Create( | 155 paint.setImageFilter(SkDisplacementMapEffect::Create( |
156 SkDisplacementMapEffect::kR_ChannelSelectorType, | 156 SkDisplacementMapEffect::kR_ChannelSelectorType, |
157 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr
ef(); | 157 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr
ef(); |
158 for (int i = 0; i < loops; ++i) { | 158 for (int i = 0; i < loops; ++i) { |
159 this->drawClippedBitmap(canvas, 200, 0, paint); | 159 this->drawClippedBitmap(canvas, 200, 0, paint); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 private: | 163 private: |
164 typedef DisplacementBaseBench INHERITED; | 164 typedef DisplacementBaseBench INHERITED; |
165 }; | 165 }; |
166 | 166 |
167 /////////////////////////////////////////////////////////////////////////////// | 167 /////////////////////////////////////////////////////////////////////////////// |
168 | 168 |
169 DEF_BENCH( return new DisplacementZeroBench(true); ) | 169 DEF_BENCH( return new DisplacementZeroBench(true); ) |
170 DEF_BENCH( return new DisplacementAlphaBench(true); ) | 170 DEF_BENCH( return new DisplacementAlphaBench(true); ) |
171 DEF_BENCH( return new DisplacementFullBench(true); ) | 171 DEF_BENCH( return new DisplacementFullBench(true); ) |
172 DEF_BENCH( return new DisplacementZeroBench(false); ) | 172 DEF_BENCH( return new DisplacementZeroBench(false); ) |
173 DEF_BENCH( return new DisplacementAlphaBench(false); ) | 173 DEF_BENCH( return new DisplacementAlphaBench(false); ) |
174 DEF_BENCH( return new DisplacementFullBench(false); ) | 174 DEF_BENCH( return new DisplacementFullBench(false); ) |
OLD | NEW |