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 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkColorFilterImageFilter.h" | 9 #include "SkColorFilterImageFilter.h" |
10 #include "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 public: | 66 public: |
67 ColorFilterDimBrightBench(bool small) : INHERITED(small) { | 67 ColorFilterDimBrightBench(bool small) : INHERITED(small) { |
68 } | 68 } |
69 | 69 |
70 protected: | 70 protected: |
71 virtual const char* onGetName() SK_OVERRIDE { | 71 virtual const char* onGetName() SK_OVERRIDE { |
72 return isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bri
ght_large"; | 72 return isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bri
ght_large"; |
73 } | 73 } |
74 | 74 |
75 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 75 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
76 SkRect r = getFilterRect(); | 76 SkRect r = getFilterRect(); |
77 SkPaint paint; | 77 SkPaint paint; |
78 paint.setColor(SK_ColorRED); | 78 paint.setColor(SK_ColorRED); |
79 | 79 |
80 for (int i = 0; i < this->getLoops(); i++) { | 80 for (int i = 0; i < loops; i++) { |
81 for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4
f) { | 81 for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4
f) { |
82 SkAutoTUnref<SkImageFilter> dim(make_brightness(-brightness)); | 82 SkAutoTUnref<SkImageFilter> dim(make_brightness(-brightness)); |
83 SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, d
im)); | 83 SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, d
im)); |
84 paint.setImageFilter(bright); | 84 paint.setImageFilter(bright); |
85 canvas->drawRect(r, paint); | 85 canvas->drawRect(r, paint); |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 typedef ColorFilterBaseBench INHERITED; | 91 typedef ColorFilterBaseBench INHERITED; |
92 }; | 92 }; |
93 | 93 |
94 class ColorFilterBrightGrayBench : public ColorFilterBaseBench { | 94 class ColorFilterBrightGrayBench : public ColorFilterBaseBench { |
95 | 95 |
96 public: | 96 public: |
97 ColorFilterBrightGrayBench(bool small) : INHERITED(small) { | 97 ColorFilterBrightGrayBench(bool small) : INHERITED(small) { |
98 } | 98 } |
99 | 99 |
100 protected: | 100 protected: |
101 virtual const char* onGetName() SK_OVERRIDE { | 101 virtual const char* onGetName() SK_OVERRIDE { |
102 return isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright
_gray_large"; | 102 return isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright
_gray_large"; |
103 } | 103 } |
104 | 104 |
105 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 105 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
106 SkRect r = getFilterRect(); | 106 SkRect r = getFilterRect(); |
107 SkPaint paint; | 107 SkPaint paint; |
108 paint.setColor(SK_ColorRED); | 108 paint.setColor(SK_ColorRED); |
109 for (int i = 0; i < this->getLoops(); i++) { | 109 for (int i = 0; i < loops; i++) { |
110 SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f)); | 110 SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f)); |
111 SkAutoTUnref<SkImageFilter> grayscale(make_grayscale(brightness)); | 111 SkAutoTUnref<SkImageFilter> grayscale(make_grayscale(brightness)); |
112 paint.setImageFilter(grayscale); | 112 paint.setImageFilter(grayscale); |
113 canvas->drawRect(r, paint); | 113 canvas->drawRect(r, paint); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 private: | 117 private: |
118 typedef ColorFilterBaseBench INHERITED; | 118 typedef ColorFilterBaseBench INHERITED; |
119 }; | 119 }; |
120 | 120 |
121 class ColorFilterGrayBrightBench : public ColorFilterBaseBench { | 121 class ColorFilterGrayBrightBench : public ColorFilterBaseBench { |
122 | 122 |
123 public: | 123 public: |
124 ColorFilterGrayBrightBench(bool small) : INHERITED(small) { | 124 ColorFilterGrayBrightBench(bool small) : INHERITED(small) { |
125 } | 125 } |
126 | 126 |
127 protected: | 127 protected: |
128 virtual const char* onGetName() SK_OVERRIDE { | 128 virtual const char* onGetName() SK_OVERRIDE { |
129 return isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_b
right_large"; | 129 return isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_b
right_large"; |
130 } | 130 } |
131 | 131 |
132 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 132 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
133 SkRect r = getFilterRect(); | 133 SkRect r = getFilterRect(); |
134 SkPaint paint; | 134 SkPaint paint; |
135 paint.setColor(SK_ColorRED); | 135 paint.setColor(SK_ColorRED); |
136 for (int i = 0; i < this->getLoops(); i++) { | 136 for (int i = 0; i < loops; i++) { |
137 SkAutoTUnref<SkImageFilter> grayscale(make_grayscale()); | 137 SkAutoTUnref<SkImageFilter> grayscale(make_grayscale()); |
138 SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f, graysca
le)); | 138 SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f, graysca
le)); |
139 paint.setImageFilter(brightness); | 139 paint.setImageFilter(brightness); |
140 canvas->drawRect(r, paint); | 140 canvas->drawRect(r, paint); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 private: | 144 private: |
145 typedef ColorFilterBaseBench INHERITED; | 145 typedef ColorFilterBaseBench INHERITED; |
146 }; | 146 }; |
147 | 147 |
148 class ColorFilterBlueBrightBench : public ColorFilterBaseBench { | 148 class ColorFilterBlueBrightBench : public ColorFilterBaseBench { |
149 | 149 |
150 public: | 150 public: |
151 ColorFilterBlueBrightBench(bool small) : INHERITED(small) { | 151 ColorFilterBlueBrightBench(bool small) : INHERITED(small) { |
152 } | 152 } |
153 | 153 |
154 protected: | 154 protected: |
155 virtual const char* onGetName() SK_OVERRIDE { | 155 virtual const char* onGetName() SK_OVERRIDE { |
156 return isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_b
right_large"; | 156 return isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_b
right_large"; |
157 } | 157 } |
158 | 158 |
159 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 159 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
160 SkRect r = getFilterRect(); | 160 SkRect r = getFilterRect(); |
161 SkPaint paint; | 161 SkPaint paint; |
162 paint.setColor(SK_ColorRED); | 162 paint.setColor(SK_ColorRED); |
163 for (int i = 0; i < this->getLoops(); i++) { | 163 for (int i = 0; i < loops; i++) { |
164 SkAutoTUnref<SkImageFilter> blue(make_mode_blue()); | 164 SkAutoTUnref<SkImageFilter> blue(make_mode_blue()); |
165 SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f, blue)); | 165 SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f, blue)); |
166 paint.setImageFilter(brightness); | 166 paint.setImageFilter(brightness); |
167 canvas->drawRect(r, paint); | 167 canvas->drawRect(r, paint); |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 private: | 171 private: |
172 typedef ColorFilterBaseBench INHERITED; | 172 typedef ColorFilterBaseBench INHERITED; |
173 }; | 173 }; |
174 | 174 |
175 class ColorFilterBrightBlueBench : public ColorFilterBaseBench { | 175 class ColorFilterBrightBlueBench : public ColorFilterBaseBench { |
176 | 176 |
177 public: | 177 public: |
178 ColorFilterBrightBlueBench(bool small) : INHERITED(small) { | 178 ColorFilterBrightBlueBench(bool small) : INHERITED(small) { |
179 } | 179 } |
180 | 180 |
181 protected: | 181 protected: |
182 virtual const char* onGetName() SK_OVERRIDE { | 182 virtual const char* onGetName() SK_OVERRIDE { |
183 return isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright
_blue_large"; | 183 return isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright
_blue_large"; |
184 } | 184 } |
185 | 185 |
186 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 186 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
187 SkRect r = getFilterRect(); | 187 SkRect r = getFilterRect(); |
188 SkPaint paint; | 188 SkPaint paint; |
189 paint.setColor(SK_ColorRED); | 189 paint.setColor(SK_ColorRED); |
190 for (int i = 0; i < this->getLoops(); i++) { | 190 for (int i = 0; i < loops; i++) { |
191 SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f)); | 191 SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f)); |
192 SkAutoTUnref<SkImageFilter> blue(make_mode_blue(brightness)); | 192 SkAutoTUnref<SkImageFilter> blue(make_mode_blue(brightness)); |
193 paint.setImageFilter(blue); | 193 paint.setImageFilter(blue); |
194 canvas->drawRect(r, paint); | 194 canvas->drawRect(r, paint); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 private: | 198 private: |
199 typedef ColorFilterBaseBench INHERITED; | 199 typedef ColorFilterBaseBench INHERITED; |
200 }; | 200 }; |
201 | 201 |
202 class ColorFilterBrightBench : public ColorFilterBaseBench { | 202 class ColorFilterBrightBench : public ColorFilterBaseBench { |
203 | 203 |
204 public: | 204 public: |
205 ColorFilterBrightBench(bool small) : INHERITED(small) { | 205 ColorFilterBrightBench(bool small) : INHERITED(small) { |
206 } | 206 } |
207 | 207 |
208 protected: | 208 protected: |
209 virtual const char* onGetName() SK_OVERRIDE { | 209 virtual const char* onGetName() SK_OVERRIDE { |
210 return isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_larg
e"; | 210 return isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_larg
e"; |
211 } | 211 } |
212 | 212 |
213 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 213 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
214 SkRect r = getFilterRect(); | 214 SkRect r = getFilterRect(); |
215 SkPaint paint; | 215 SkPaint paint; |
216 paint.setColor(SK_ColorRED); | 216 paint.setColor(SK_ColorRED); |
217 for (int i = 0; i < this->getLoops(); i++) { | 217 for (int i = 0; i < loops; i++) { |
218 SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f)); | 218 SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f)); |
219 paint.setImageFilter(brightness); | 219 paint.setImageFilter(brightness); |
220 canvas->drawRect(r, paint); | 220 canvas->drawRect(r, paint); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 private: | 224 private: |
225 typedef ColorFilterBaseBench INHERITED; | 225 typedef ColorFilterBaseBench INHERITED; |
226 }; | 226 }; |
227 | 227 |
228 class ColorFilterBlueBench : public ColorFilterBaseBench { | 228 class ColorFilterBlueBench : public ColorFilterBaseBench { |
229 | 229 |
230 public: | 230 public: |
231 ColorFilterBlueBench(bool small) : INHERITED(small) { | 231 ColorFilterBlueBench(bool small) : INHERITED(small) { |
232 } | 232 } |
233 | 233 |
234 protected: | 234 protected: |
235 virtual const char* onGetName() SK_OVERRIDE { | 235 virtual const char* onGetName() SK_OVERRIDE { |
236 return isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large"; | 236 return isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large"; |
237 } | 237 } |
238 | 238 |
239 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 239 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
240 SkRect r = getFilterRect(); | 240 SkRect r = getFilterRect(); |
241 SkPaint paint; | 241 SkPaint paint; |
242 paint.setColor(SK_ColorRED); | 242 paint.setColor(SK_ColorRED); |
243 for (int i = 0; i < this->getLoops(); i++) { | 243 for (int i = 0; i < loops; i++) { |
244 SkAutoTUnref<SkImageFilter> blue(make_mode_blue()); | 244 SkAutoTUnref<SkImageFilter> blue(make_mode_blue()); |
245 paint.setImageFilter(blue); | 245 paint.setImageFilter(blue); |
246 canvas->drawRect(r, paint); | 246 canvas->drawRect(r, paint); |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 private: | 250 private: |
251 typedef ColorFilterBaseBench INHERITED; | 251 typedef ColorFilterBaseBench INHERITED; |
252 }; | 252 }; |
253 | 253 |
254 class ColorFilterGrayBench : public ColorFilterBaseBench { | 254 class ColorFilterGrayBench : public ColorFilterBaseBench { |
255 | 255 |
256 public: | 256 public: |
257 ColorFilterGrayBench(bool small) : INHERITED(small) { | 257 ColorFilterGrayBench(bool small) : INHERITED(small) { |
258 } | 258 } |
259 | 259 |
260 protected: | 260 protected: |
261 virtual const char* onGetName() SK_OVERRIDE { | 261 virtual const char* onGetName() SK_OVERRIDE { |
262 return isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large"; | 262 return isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large"; |
263 } | 263 } |
264 | 264 |
265 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 265 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
266 SkRect r = getFilterRect(); | 266 SkRect r = getFilterRect(); |
267 SkPaint paint; | 267 SkPaint paint; |
268 paint.setColor(SK_ColorRED); | 268 paint.setColor(SK_ColorRED); |
269 for (int i = 0; i < this->getLoops(); i++) { | 269 for (int i = 0; i < loops; i++) { |
270 SkAutoTUnref<SkImageFilter> grayscale(make_grayscale()); | 270 SkAutoTUnref<SkImageFilter> grayscale(make_grayscale()); |
271 paint.setImageFilter(grayscale); | 271 paint.setImageFilter(grayscale); |
272 canvas->drawRect(r, paint); | 272 canvas->drawRect(r, paint); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 private: | 276 private: |
277 typedef ColorFilterBaseBench INHERITED; | 277 typedef ColorFilterBaseBench INHERITED; |
278 }; | 278 }; |
279 | 279 |
280 class TableColorFilterBench : public ColorFilterBaseBench { | 280 class TableColorFilterBench : public ColorFilterBaseBench { |
281 | 281 |
282 public: | 282 public: |
283 TableColorFilterBench(bool small) : INHERITED(small) { | 283 TableColorFilterBench(bool small) : INHERITED(small) { |
284 } | 284 } |
285 | 285 |
286 protected: | 286 protected: |
287 virtual const char* onGetName() SK_OVERRIDE { | 287 virtual const char* onGetName() SK_OVERRIDE { |
288 return isSmall() ? "table_colorfilter_small" : "table_colorfilter_large"
; | 288 return isSmall() ? "table_colorfilter_small" : "table_colorfilter_large"
; |
289 } | 289 } |
290 | 290 |
291 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 291 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
292 SkRect r = getFilterRect(); | 292 SkRect r = getFilterRect(); |
293 SkPaint paint; | 293 SkPaint paint; |
294 paint.setColor(SK_ColorRED); | 294 paint.setColor(SK_ColorRED); |
295 for (int i = 0; i < this->getLoops(); i++) { | 295 for (int i = 0; i < loops; i++) { |
296 SkAutoTUnref<SkColorFilter> table_filter(make_table_filter()); | 296 SkAutoTUnref<SkColorFilter> table_filter(make_table_filter()); |
297 paint.setColorFilter(table_filter); | 297 paint.setColorFilter(table_filter); |
298 canvas->drawRect(r, paint); | 298 canvas->drawRect(r, paint); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 private: | 302 private: |
303 static void fill_table_data(uint8_t table[]) { | 303 static void fill_table_data(uint8_t table[]) { |
304 for (int i = 0; i < 256; ++i) { | 304 for (int i = 0; i < 256; ++i) { |
305 int n = i >> 5; | 305 int n = i >> 5; |
(...skipping 13 matching lines...) Expand all Loading... |
319 | 319 |
320 public: | 320 public: |
321 LumaColorFilterBench(bool small) : INHERITED(small) { | 321 LumaColorFilterBench(bool small) : INHERITED(small) { |
322 } | 322 } |
323 | 323 |
324 protected: | 324 protected: |
325 virtual const char* onGetName() SK_OVERRIDE { | 325 virtual const char* onGetName() SK_OVERRIDE { |
326 return isSmall() ? "luma_colorfilter_small" : "luma_colorfilter_large"; | 326 return isSmall() ? "luma_colorfilter_small" : "luma_colorfilter_large"; |
327 } | 327 } |
328 | 328 |
329 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 329 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
330 SkRect r = getFilterRect(); | 330 SkRect r = getFilterRect(); |
331 SkPaint paint; | 331 SkPaint paint; |
332 paint.setColor(SK_ColorRED); | 332 paint.setColor(SK_ColorRED); |
333 | 333 |
334 for (int i = 0; i < this->getLoops(); i++) { | 334 for (int i = 0; i < loops; i++) { |
335 SkAutoTUnref<SkColorFilter> luma_filter(SkLumaColorFilter::Create())
; | 335 SkAutoTUnref<SkColorFilter> luma_filter(SkLumaColorFilter::Create())
; |
336 paint.setColorFilter(luma_filter); | 336 paint.setColorFilter(luma_filter); |
337 canvas->drawRect(r, paint); | 337 canvas->drawRect(r, paint); |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 private: | 341 private: |
342 typedef ColorFilterBaseBench INHERITED; | 342 typedef ColorFilterBaseBench INHERITED; |
343 }; | 343 }; |
344 | 344 |
(...skipping 13 matching lines...) Expand all Loading... |
358 DEF_BENCH( return new ColorFilterDimBrightBench(false); ) | 358 DEF_BENCH( return new ColorFilterDimBrightBench(false); ) |
359 DEF_BENCH( return new ColorFilterBrightGrayBench(false); ) | 359 DEF_BENCH( return new ColorFilterBrightGrayBench(false); ) |
360 DEF_BENCH( return new ColorFilterGrayBrightBench(false); ) | 360 DEF_BENCH( return new ColorFilterGrayBrightBench(false); ) |
361 DEF_BENCH( return new ColorFilterBlueBrightBench(false); ) | 361 DEF_BENCH( return new ColorFilterBlueBrightBench(false); ) |
362 DEF_BENCH( return new ColorFilterBrightBlueBench(false); ) | 362 DEF_BENCH( return new ColorFilterBrightBlueBench(false); ) |
363 DEF_BENCH( return new ColorFilterBrightBench(false); ) | 363 DEF_BENCH( return new ColorFilterBrightBench(false); ) |
364 DEF_BENCH( return new ColorFilterBlueBench(false); ) | 364 DEF_BENCH( return new ColorFilterBlueBench(false); ) |
365 DEF_BENCH( return new ColorFilterGrayBench(false); ) | 365 DEF_BENCH( return new ColorFilterGrayBench(false); ) |
366 DEF_BENCH( return new TableColorFilterBench(false); ) | 366 DEF_BENCH( return new TableColorFilterBench(false); ) |
367 DEF_BENCH( return new LumaColorFilterBench(false); ) | 367 DEF_BENCH( return new LumaColorFilterBench(false); ) |
OLD | NEW |