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

Side by Side Diff: bench/BitmapBench.cpp

Issue 16069010: extend SkBenchmark to allow a bench to return a durationScale, which allows it to perform fewer act… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkString.h" 14 #include "SkString.h"
15 15
16 static const char* gTileName[] = {
17 "clamp", "repeat", "mirror"
18 };
19
20 static const char* gConfigName[] = { 16 static const char* gConfigName[] = {
21 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" 17 "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
22 }; 18 };
23 19
24 static int conv6ToByte(int x) { 20 static int conv6ToByte(int x) {
25 return x * 0xFF / 5; 21 return x * 0xFF / 5;
26 } 22 }
27 23
28 static int convByteTo6(int x) { 24 static int convByteTo6(int x) {
29 return x * 5 / 255; 25 return x * 5 / 255;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 - matrix options: translate, scale, rotate, persp 71 - matrix options: translate, scale, rotate, persp
76 - tiling: none, repeat, mirror, clamp 72 - tiling: none, repeat, mirror, clamp
77 73
78 */ 74 */
79 75
80 class BitmapBench : public SkBenchmark { 76 class BitmapBench : public SkBenchmark {
81 SkBitmap fBitmap; 77 SkBitmap fBitmap;
82 SkPaint fPaint; 78 SkPaint fPaint;
83 bool fIsOpaque; 79 bool fIsOpaque;
84 bool fForceUpdate; //bitmap marked as dirty before each draw. forces bitmap to be updated on device cache 80 bool fForceUpdate; //bitmap marked as dirty before each draw. forces bitmap to be updated on device cache
85 int fTileX, fTileY; // -1 means don't use shader
86 bool fIsVolatile; 81 bool fIsVolatile;
87 SkBitmap::Config fConfig; 82 SkBitmap::Config fConfig;
88 SkString fName; 83 SkString fName;
89 enum { N = SkBENCHLOOP(300) }; 84 enum { BICUBIC_DUR_SCALE = 20 };
85 enum { N = SkBENCHLOOP(15 * BICUBIC_DUR_SCALE) };
90 enum { W = 128 }; 86 enum { W = 128 };
91 enum { H = 128 }; 87 enum { H = 128 };
92 public: 88 public:
93 BitmapBench(void* param, bool isOpaque, SkBitmap::Config c, 89 BitmapBench(void* param, bool isOpaque, SkBitmap::Config c,
94 bool forceUpdate = false, bool bitmapVolatile = false, 90 bool forceUpdate = false, bool bitmapVolatile = false)
95 int tx = -1, int ty = -1)
96 : INHERITED(param) 91 : INHERITED(param)
97 , fIsOpaque(isOpaque) 92 , fIsOpaque(isOpaque)
98 , fForceUpdate(forceUpdate) 93 , fForceUpdate(forceUpdate)
99 , fTileX(tx)
100 , fTileY(ty)
101 , fIsVolatile(bitmapVolatile) 94 , fIsVolatile(bitmapVolatile)
102 , fConfig(c) { 95 , fConfig(c) {
103 } 96 }
104 97
105 protected: 98 protected:
106 virtual const char* onGetName() { 99 virtual const char* onGetName() {
107 fName.set("bitmap"); 100 fName.set("bitmap");
108 if (fTileX >= 0) {
109 fName.appendf("_%s", gTileName[fTileX]);
110 if (fTileY != fTileX) {
111 fName.appendf("_%s", gTileName[fTileY]);
112 }
113 }
114 fName.appendf("_%s%s", gConfigName[fConfig], 101 fName.appendf("_%s%s", gConfigName[fConfig],
115 fIsOpaque ? "" : "_A"); 102 fIsOpaque ? "" : "_A");
116 if (fForceUpdate) 103 if (fForceUpdate)
117 fName.append("_update"); 104 fName.append("_update");
118 if (fIsVolatile) 105 if (fIsVolatile)
119 fName.append("_volatile"); 106 fName.append("_volatile");
120 107
121 return fName.c_str(); 108 return fName.c_str();
122 } 109 }
123 110
(...skipping 28 matching lines...) Expand all
152 SkIPoint dim = this->getSize(); 139 SkIPoint dim = this->getSize();
153 SkRandom rand; 140 SkRandom rand;
154 141
155 SkPaint paint(fPaint); 142 SkPaint paint(fPaint);
156 this->setupPaint(&paint); 143 this->setupPaint(&paint);
157 144
158 const SkBitmap& bitmap = fBitmap; 145 const SkBitmap& bitmap = fBitmap;
159 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); 146 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2);
160 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); 147 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2);
161 148
162 for (int i = 0; i < N; i++) { 149 int count = N;
robertphillips 2013/05/29 13:14:17 make sure count remains 1 in debug?
reed1 2013/05/29 15:02:30 Done.
150 if (paint.getFlags() & SkPaint::kBicubicFilterBitmap_Flag) {
151 count /= BICUBIC_DUR_SCALE;
152 }
153 for (int i = 0; i < count; i++) {
163 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; 154 SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
164 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; 155 SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
165 156
166 if (fForceUpdate) 157 if (fForceUpdate)
167 bitmap.notifyPixelsChanged(); 158 bitmap.notifyPixelsChanged();
168 159
169 canvas->drawBitmap(bitmap, x, y, &paint); 160 canvas->drawBitmap(bitmap, x, y, &paint);
170 } 161 }
171 } 162 }
172 163
164 virtual float onGetDurationScale() SK_OVERRIDE {
165 SkPaint paint;
166 this->setupPaint(&paint);
167
robertphillips 2013/05/29 13:14:17 return 1 in debug?
reed1 2013/05/29 15:02:30 Done.
168 return (paint.getFlags() & SkPaint::kBicubicFilterBitmap_Flag) ?
169 BICUBIC_DUR_SCALE : 1;
170 }
171
173 virtual void onDrawIntoBitmap(const SkBitmap& bm) { 172 virtual void onDrawIntoBitmap(const SkBitmap& bm) {
174 const int w = bm.width(); 173 const int w = bm.width();
175 const int h = bm.height(); 174 const int h = bm.height();
176 175
177 SkCanvas canvas(bm); 176 SkCanvas canvas(bm);
178 SkPaint p; 177 SkPaint p;
179 p.setAntiAlias(true); 178 p.setAntiAlias(true);
180 p.setColor(SK_ColorRED); 179 p.setColor(SK_ColorRED);
181 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, 180 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
182 SkIntToScalar(SkMin32(w, h))*3/8, p); 181 SkIntToScalar(SkMin32(w, h))*3/8, p);
183 182
184 SkRect r; 183 SkRect r;
185 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); 184 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
186 p.setStyle(SkPaint::kStroke_Style); 185 p.setStyle(SkPaint::kStroke_Style);
187 p.setStrokeWidth(SkIntToScalar(4)); 186 p.setStrokeWidth(SkIntToScalar(4));
188 p.setColor(SK_ColorBLUE); 187 p.setColor(SK_ColorBLUE);
189 canvas.drawRect(r, p); 188 canvas.drawRect(r, p);
190 } 189 }
191 190
192 private: 191 private:
193 typedef SkBenchmark INHERITED; 192 typedef SkBenchmark INHERITED;
194 }; 193 };
195 194
196 /** Explicitly invoke some filter types to improve coverage of acceleration 195 /** Explicitly invoke some filter types to improve coverage of acceleration
197 procs. */ 196 procs. */
198 197
198 enum Flags {
199 kScale_Flag = 1 << 0,
200 kRotate_Flag = 1 << 1,
201 kBilerp_Flag = 1 << 2,
202 kBicubic_Flag = 1 << 3,
203 };
204
205 static bool isBilerp(uint32_t flags) {
206 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag);
207 }
208
209 static bool isBicubic(uint32_t flags) {
210 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag | kBicubic_ Flag);
211 }
212
199 class FilterBitmapBench : public BitmapBench { 213 class FilterBitmapBench : public BitmapBench {
200 bool fScale; 214 uint32_t fFlags;
201 bool fRotate;
202 bool fFilter;
203 SkString fFullName; 215 SkString fFullName;
204 enum { N = SkBENCHLOOP(300) }; 216 enum { N = SkBENCHLOOP(300) };
205 public: 217 public:
206 FilterBitmapBench(void* param, bool isOpaque, SkBitmap::Config c, 218 FilterBitmapBench(void* param, bool isOpaque, SkBitmap::Config c,
207 bool forceUpdate = false, bool bitmapVolatile = false, 219 bool forceUpdate, bool isVolitile, uint32_t flags)
208 int tx = -1, int ty = -1, bool addScale = false, 220 : INHERITED(param, isOpaque, c, forceUpdate, isVolitile)
209 bool addRotate = false, bool addFilter = false) 221 , fFlags(flags) {
210 : INHERITED(param, isOpaque, c, forceUpdate, bitmapVolatile, tx, ty)
211 , fScale(addScale), fRotate(addRotate), fFilter(addFilter) {
212
213 } 222 }
214 223
215 protected: 224 protected:
216 virtual const char* onGetName() { 225 virtual const char* onGetName() {
217 fFullName.set(INHERITED::onGetName()); 226 fFullName.set(INHERITED::onGetName());
218 if (fScale) 227 if (fFlags & kScale_Flag) {
219 fFullName.append("_scale"); 228 fFullName.append("_scale");
220 if (fRotate) 229 }
230 if (fFlags & kRotate_Flag) {
221 fFullName.append("_rotate"); 231 fFullName.append("_rotate");
222 if (fFilter) 232 }
223 fFullName.append("_filter"); 233 if (isBilerp(fFlags)) {
234 fFullName.append("_bilerp");
235 } else if (isBicubic(fFlags)) {
236 fFullName.append("_bicubic");
237 }
224 238
225 return fFullName.c_str(); 239 return fFullName.c_str();
226 } 240 }
227 241
228 virtual void onDraw(SkCanvas* canvas) { 242 virtual void onDraw(SkCanvas* canvas) {
229 SkISize dim = canvas->getDeviceSize(); 243 SkISize dim = canvas->getDeviceSize();
230 if (fScale) { 244 if (fFlags & kScale_Flag) {
231 const SkScalar x = SkIntToScalar(dim.fWidth) / 2; 245 const SkScalar x = SkIntToScalar(dim.fWidth) / 2;
232 const SkScalar y = SkIntToScalar(dim.fHeight) / 2; 246 const SkScalar y = SkIntToScalar(dim.fHeight) / 2;
233 247
234 canvas->translate(x, y); 248 canvas->translate(x, y);
235 // just enough so we can't take the sprite case 249 // just enough so we can't take the sprite case
236 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); 250 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100);
237 canvas->translate(-x, -y); 251 canvas->translate(-x, -y);
238 } 252 }
239 if (fRotate) { 253 if (fFlags & kRotate_Flag) {
240 const SkScalar x = SkIntToScalar(dim.fWidth) / 2; 254 const SkScalar x = SkIntToScalar(dim.fWidth) / 2;
241 const SkScalar y = SkIntToScalar(dim.fHeight) / 2; 255 const SkScalar y = SkIntToScalar(dim.fHeight) / 2;
242 256
243 canvas->translate(x, y); 257 canvas->translate(x, y);
244 canvas->rotate(SkIntToScalar(35)); 258 canvas->rotate(SkIntToScalar(35));
245 canvas->translate(-x, -y); 259 canvas->translate(-x, -y);
246 } 260 }
247 261
248 this->setForceFilter(fFilter); 262 uint32_t orMask = 0;
263 uint32_t clearMask = SkPaint::kFilterBitmap_Flag | SkPaint::kBicubicFilt erBitmap_Flag;
264 if (fFlags & kBilerp_Flag) {
265 orMask |= SkPaint::kFilterBitmap_Flag;
266 }
267 if (fFlags & kBicubic_Flag) {
268 orMask |= SkPaint::kBicubicFilterBitmap_Flag;
269 }
270 this->setPaintFlags(orMask, clearMask);
271
249 INHERITED::onDraw(canvas); 272 INHERITED::onDraw(canvas);
250 } 273 }
251 274
252 private: 275 private:
253 typedef BitmapBench INHERITED; 276 typedef BitmapBench INHERITED;
254 }; 277 };
255 278
256 /** Verify optimizations that test source alpha values. */ 279 /** Verify optimizations that test source alpha values. */
257 280
258 class SourceAlphaBitmapBench : public BitmapBench { 281 class SourceAlphaBitmapBench : public BitmapBench {
259 public: 282 public:
260 enum SourceAlpha { kOpaque_SourceAlpha, kTransparent_SourceAlpha, 283 enum SourceAlpha { kOpaque_SourceAlpha, kTransparent_SourceAlpha,
261 kTwoStripes_SourceAlpha, kThreeStripes_SourceAlpha}; 284 kTwoStripes_SourceAlpha, kThreeStripes_SourceAlpha};
262 private: 285 private:
263 SkString fFullName; 286 SkString fFullName;
264 SourceAlpha fSourceAlpha; 287 SourceAlpha fSourceAlpha;
265 public: 288 public:
266 SourceAlphaBitmapBench(void* param, SourceAlpha alpha, SkBitmap::Config c, 289 SourceAlphaBitmapBench(void* param, SourceAlpha alpha, SkBitmap::Config c,
267 bool forceUpdate = false, bool bitmapVolatile = false, 290 bool forceUpdate = false, bool bitmapVolatile = false)
268 int tx = -1, int ty = -1) 291 : INHERITED(param, false, c, forceUpdate, bitmapVolatile)
269 : INHERITED(param, false, c, forceUpdate, bitmapVolatile, tx, ty)
270 , fSourceAlpha(alpha) { 292 , fSourceAlpha(alpha) {
271 } 293 }
272 294
273 protected: 295 protected:
274 virtual const char* onGetName() { 296 virtual const char* onGetName() {
275 fFullName.set(INHERITED::onGetName()); 297 fFullName.set(INHERITED::onGetName());
276 298
277 if (fSourceAlpha == kOpaque_SourceAlpha) { 299 if (fSourceAlpha == kOpaque_SourceAlpha) {
278 fFullName.append("_source_opaque"); 300 fFullName.append("_source_opaque");
279 } else if (fSourceAlpha == kTransparent_SourceAlpha) { 301 } else if (fSourceAlpha == kTransparent_SourceAlpha) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config); ) 369 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config); )
348 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kRGB_565_Config); ) 370 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kRGB_565_Config); )
349 DEF_BENCH( return new BitmapBench(p, false, SkBitmap::kARGB_4444_Config); ) 371 DEF_BENCH( return new BitmapBench(p, false, SkBitmap::kARGB_4444_Config); )
350 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_4444_Config); ) 372 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_4444_Config); )
351 DEF_BENCH( return new BitmapBench(p, false, SkBitmap::kIndex8_Config); ) 373 DEF_BENCH( return new BitmapBench(p, false, SkBitmap::kIndex8_Config); )
352 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kIndex8_Config); ) 374 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kIndex8_Config); )
353 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, tr ue); ) 375 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, tr ue); )
354 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, fa lse); ) 376 DEF_BENCH( return new BitmapBench(p, true, SkBitmap::kARGB_8888_Config, true, fa lse); )
355 377
356 // scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S 32_D16_filter_DX_SSE2 378 // scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S 32_D16_filter_DX_SSE2
357 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f alse, false, -1, -1, true, false, true); ) 379 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f alse, false, kScale_Flag | kBilerp_Flag); )
358 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, fa lse, false, -1, -1, true, false, true); ) 380 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, fa lse, false, kScale_Flag | kBilerp_Flag); )
359 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, true, -1, -1, true, false, true); ) 381 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, true, kScale_Flag | kBilerp_Flag); )
360 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, false, -1, -1, true, false, true); ) 382 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, false, kScale_Flag | kBilerp_Flag); )
361 383
362 // scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3} 384 // scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3}
363 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f alse, false, -1, -1, true, true, true); ) 385 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
364 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, fa lse, false, -1, -1, true, true, true); ) 386 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, fa lse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
365 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, true, -1, -1, true, true, true); ) 387 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, true, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
366 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, false, -1, -1, true, true, true); ) 388 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr ue, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
389
390 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f alse, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); )
391 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); )
367 392
368 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} 393 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon}
369 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kOpaque_ SourceAlpha, SkBitmap::kARGB_8888_Config); ) 394 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kOpaque_ SourceAlpha, SkBitmap::kARGB_8888_Config); )
370 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTranspa rent_SourceAlpha, SkBitmap::kARGB_8888_Config); ) 395 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTranspa rent_SourceAlpha, SkBitmap::kARGB_8888_Config); )
371 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTwoStri pes_SourceAlpha, SkBitmap::kARGB_8888_Config); ) 396 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTwoStri pes_SourceAlpha, SkBitmap::kARGB_8888_Config); )
372 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kThreeSt ripes_SourceAlpha, SkBitmap::kARGB_8888_Config); ) 397 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kThreeSt ripes_SourceAlpha, SkBitmap::kARGB_8888_Config); )
OLDNEW
« no previous file with comments | « bench/BenchTimer.cpp ('k') | bench/SkBenchmark.h » ('j') | bench/SkBenchmark.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698