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

Side by Side Diff: bench/BitmapBench.cpp

Issue 13060004: Partial reapply of r5364 minus the non-neon code path. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 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
« no previous file with comments | « no previous file | src/opts/SkBlitRow_opts_arm_neon.cpp » ('j') | 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 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[] = { 16 static const char* gTileName[] = {
17 "clamp", "repeat", "mirror" 17 "clamp", "repeat", "mirror"
18 }; 18 };
19 19
20 static const char* gConfigName[] = { 20 static const char* gConfigName[] = {
21 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" 21 "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
22 }; 22 };
23 23
24 static void drawIntoBitmap(const SkBitmap& bm) {
25 const int w = bm.width();
26 const int h = bm.height();
27
28 SkCanvas canvas(bm);
29 SkPaint p;
30 p.setAntiAlias(true);
31 p.setColor(SK_ColorRED);
32 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
33 SkIntToScalar(SkMin32(w, h))*3/8, p);
34
35 SkRect r;
36 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
37 p.setStyle(SkPaint::kStroke_Style);
38 p.setStrokeWidth(SkIntToScalar(4));
39 p.setColor(SK_ColorBLUE);
40 canvas.drawRect(r, p);
41 }
42
43 static int conv6ToByte(int x) { 24 static int conv6ToByte(int x) {
44 return x * 0xFF / 5; 25 return x * 0xFF / 5;
45 } 26 }
46 27
47 static int convByteTo6(int x) { 28 static int convByteTo6(int x) {
48 return x * 5 / 255; 29 return x * 5 / 255;
49 } 30 }
50 31
51 static uint8_t compute666Index(SkPMColor c) { 32 static uint8_t compute666Index(SkPMColor c) {
52 int r = SkGetPackedR32(c); 33 int r = SkGetPackedR32(c);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 - tiling: none, repeat, mirror, clamp 76 - tiling: none, repeat, mirror, clamp
96 77
97 */ 78 */
98 79
99 class BitmapBench : public SkBenchmark { 80 class BitmapBench : public SkBenchmark {
100 SkBitmap fBitmap; 81 SkBitmap fBitmap;
101 SkPaint fPaint; 82 SkPaint fPaint;
102 bool fIsOpaque; 83 bool fIsOpaque;
103 bool fForceUpdate; //bitmap marked as dirty before each draw. forces bitmap to be updated on device cache 84 bool fForceUpdate; //bitmap marked as dirty before each draw. forces bitmap to be updated on device cache
104 int fTileX, fTileY; // -1 means don't use shader 85 int fTileX, fTileY; // -1 means don't use shader
86 bool fIsVolatile;
87 SkBitmap::Config fConfig;
105 SkString fName; 88 SkString fName;
106 enum { N = SkBENCHLOOP(300) }; 89 enum { N = SkBENCHLOOP(300) };
90 enum { W = 128 };
91 enum { H = 128 };
107 public: 92 public:
108 BitmapBench(void* param, bool isOpaque, SkBitmap::Config c, 93 BitmapBench(void* param, bool isOpaque, SkBitmap::Config c,
109 bool forceUpdate = false, bool bitmapVolatile = false, 94 bool forceUpdate = false, bool bitmapVolatile = false,
110 int tx = -1, int ty = -1) 95 int tx = -1, int ty = -1)
111 : INHERITED(param), fIsOpaque(isOpaque), fForceUpdate(forceUpdate), fTil eX(tx), fTileY(ty) { 96 : INHERITED(param)
112 const int w = 128; 97 , fIsOpaque(isOpaque)
113 const int h = 128; 98 , fForceUpdate(forceUpdate)
114 SkBitmap bm; 99 , fTileX(tx)
115 100 , fTileY(ty)
116 if (SkBitmap::kIndex8_Config == c) { 101 , fIsVolatile(bitmapVolatile)
117 bm.setConfig(SkBitmap::kARGB_8888_Config, w, h); 102 , fConfig(c) {
118 } else {
119 bm.setConfig(c, w, h);
120 }
121 bm.allocPixels();
122 bm.eraseColor(isOpaque ? SK_ColorBLACK : 0);
123
124 drawIntoBitmap(bm);
125
126 if (SkBitmap::kIndex8_Config == c) {
127 convertToIndex666(bm, &fBitmap);
128 } else {
129 fBitmap = bm;
130 }
131
132 if (fBitmap.getColorTable()) {
133 fBitmap.getColorTable()->setIsOpaque(isOpaque);
134 }
135 fBitmap.setIsOpaque(isOpaque);
136 fBitmap.setIsVolatile(bitmapVolatile);
137 } 103 }
138 104
139 protected: 105 protected:
140 virtual const char* onGetName() { 106 virtual const char* onGetName() {
141 fName.set("bitmap"); 107 fName.set("bitmap");
142 if (fTileX >= 0) { 108 if (fTileX >= 0) {
143 fName.appendf("_%s", gTileName[fTileX]); 109 fName.appendf("_%s", gTileName[fTileX]);
144 if (fTileY != fTileX) { 110 if (fTileY != fTileX) {
145 fName.appendf("_%s", gTileName[fTileY]); 111 fName.appendf("_%s", gTileName[fTileY]);
146 } 112 }
147 } 113 }
148 fName.appendf("_%s%s", gConfigName[fBitmap.config()], 114 fName.appendf("_%s%s", gConfigName[fConfig],
149 fIsOpaque ? "" : "_A"); 115 fIsOpaque ? "" : "_A");
150 if (fForceUpdate) 116 if (fForceUpdate)
151 fName.append("_update"); 117 fName.append("_update");
152 if (fBitmap.isVolatile()) 118 if (fIsVolatile)
153 fName.append("_volatile"); 119 fName.append("_volatile");
154 120
155 return fName.c_str(); 121 return fName.c_str();
156 } 122 }
157 123
124 virtual void onPreDraw() {
125 SkBitmap bm;
126
127 if (SkBitmap::kIndex8_Config == fConfig) {
128 bm.setConfig(SkBitmap::kARGB_8888_Config, W, H);
129 } else {
130 bm.setConfig(fConfig, W, H);
131 }
132
133 bm.allocPixels();
134 bm.eraseColor(fIsOpaque ? SK_ColorBLACK : 0);
135
136 onDrawIntoBitmap(bm);
137
138 if (SkBitmap::kIndex8_Config == fConfig) {
139 convertToIndex666(bm, &fBitmap);
140 } else {
141 fBitmap = bm;
142 }
143
144 if (fBitmap.getColorTable()) {
145 fBitmap.getColorTable()->setIsOpaque(fIsOpaque);
146 }
147 fBitmap.setIsOpaque(fIsOpaque);
148 fBitmap.setIsVolatile(fIsVolatile);
149 }
150
158 virtual void onDraw(SkCanvas* canvas) { 151 virtual void onDraw(SkCanvas* canvas) {
159 SkIPoint dim = this->getSize(); 152 SkIPoint dim = this->getSize();
160 SkRandom rand; 153 SkRandom rand;
161 154
162 SkPaint paint(fPaint); 155 SkPaint paint(fPaint);
163 this->setupPaint(&paint); 156 this->setupPaint(&paint);
164 157
165 const SkBitmap& bitmap = fBitmap; 158 const SkBitmap& bitmap = fBitmap;
166 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); 159 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2);
167 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); 160 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2);
168 161
169 for (int i = 0; i < N; i++) { 162 for (int i = 0; i < N; i++) {
170 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; 163 SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
171 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; 164 SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
172 165
173 if (fForceUpdate) 166 if (fForceUpdate)
174 bitmap.notifyPixelsChanged(); 167 bitmap.notifyPixelsChanged();
175 168
176 canvas->drawBitmap(bitmap, x, y, &paint); 169 canvas->drawBitmap(bitmap, x, y, &paint);
177 } 170 }
178 } 171 }
179 172
173 virtual void onDrawIntoBitmap(const SkBitmap& bm) {
174 const int w = bm.width();
175 const int h = bm.height();
176
177 SkCanvas canvas(bm);
178 SkPaint p;
179 p.setAntiAlias(true);
180 p.setColor(SK_ColorRED);
181 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
182 SkIntToScalar(SkMin32(w, h))*3/8, p);
183
184 SkRect r;
185 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
186 p.setStyle(SkPaint::kStroke_Style);
187 p.setStrokeWidth(SkIntToScalar(4));
188 p.setColor(SK_ColorBLUE);
189 canvas.drawRect(r, p);
190 }
191
180 private: 192 private:
181 typedef SkBenchmark INHERITED; 193 typedef SkBenchmark INHERITED;
182 }; 194 };
183 195
184 /** Explicitly invoke some filter types to improve coverage of acceleration 196 /** Explicitly invoke some filter types to improve coverage of acceleration
185 procs. */ 197 procs. */
186 198
187 class FilterBitmapBench : public BitmapBench { 199 class FilterBitmapBench : public BitmapBench {
188 bool fScale; 200 bool fScale;
189 bool fRotate; 201 bool fRotate;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 246 }
235 247
236 this->setForceFilter(fFilter); 248 this->setForceFilter(fFilter);
237 INHERITED::onDraw(canvas); 249 INHERITED::onDraw(canvas);
238 } 250 }
239 251
240 private: 252 private:
241 typedef BitmapBench INHERITED; 253 typedef BitmapBench INHERITED;
242 }; 254 };
243 255
256 /** Verify optimizations that test source alpha values. */
257
258 class SourceAlphaBitmapBench : public BitmapBench {
259 public:
260 enum SourceAlpha { kOpaque_SourceAlpha, kTransparent_SourceAlpha,
261 kTwoStripes_SourceAlpha, kThreeStripes_SourceAlpha};
262 private:
263 SkString fFullName;
264 SourceAlpha fSourceAlpha;
265 public:
266 SourceAlphaBitmapBench(void* param, SourceAlpha alpha, SkBitmap::Config c,
267 bool forceUpdate = false, bool bitmapVolatile = false,
268 int tx = -1, int ty = -1)
269 : INHERITED(param, false, c, forceUpdate, bitmapVolatile, tx, ty)
270 , fSourceAlpha(alpha) {
271 }
272
273 protected:
274 virtual const char* onGetName() {
275 fFullName.set(INHERITED::onGetName());
276
277 if (fSourceAlpha == kOpaque_SourceAlpha) {
278 fFullName.append("_source_opaque");
279 } else if (fSourceAlpha == kTransparent_SourceAlpha) {
280 fFullName.append("_source_transparent");
281 } else if (fSourceAlpha == kTwoStripes_SourceAlpha) {
282 fFullName.append("_source_stripes_two");
283 } else if (fSourceAlpha == kThreeStripes_SourceAlpha) {
284 fFullName.append("_source_stripes_three");
285 }
286
287 return fFullName.c_str();
288 }
289
290 virtual void onDrawIntoBitmap(const SkBitmap& bm) SK_OVERRIDE {
291 const int w = bm.width();
292 const int h = bm.height();
293
294 if (kOpaque_SourceAlpha == fSourceAlpha) {
295 bm.eraseColor(SK_ColorBLACK);
296 } else if (kTransparent_SourceAlpha == fSourceAlpha) {
297 bm.eraseColor(0);
298 } else if (kTwoStripes_SourceAlpha == fSourceAlpha) {
299 bm.eraseColor(0);
300
301 SkCanvas canvas(bm);
302 SkPaint p;
303 p.setAntiAlias(false);
304 p.setStyle(SkPaint::kFill_Style);
305 p.setColor(SK_ColorRED);
306
307 // Draw red vertical stripes on transparent background
308 SkRect r;
309 for (int x = 0; x < w; x+=2)
310 {
311 r.set(SkIntToScalar(x), 0, SkIntToScalar(x+1), SkIntToScalar(h)) ;
312 canvas.drawRect(r, p);
313 }
314
315 } else if (kThreeStripes_SourceAlpha == fSourceAlpha) {
316 bm.eraseColor(0);
317
318 SkCanvas canvas(bm);
319 SkPaint p;
320 p.setAntiAlias(false);
321 p.setStyle(SkPaint::kFill_Style);
322
323 // Draw vertical stripes on transparent background with a pattern
324 // where the first pixel is fully transparent, the next is semi-tran sparent
325 // and the third is fully opaque.
326 SkRect r;
327 for (int x = 0; x < w; x++)
328 {
329 if (x % 3 == 0) {
330 continue; // Keep transparent
331 } else if (x % 3 == 1) {
332 p.setColor(SkColorSetARGB(127, 127, 127, 127)); // Semi-tran sparent
333 } else if (x % 3 == 2) {
334 p.setColor(SK_ColorRED); // Opaque
335 }
336 r.set(SkIntToScalar(x), 0, SkIntToScalar(x+1), SkIntToScalar(h)) ;
337 canvas.drawRect(r, p);
338 }
339 }
340 }
341
342 private:
343 typedef BitmapBench INHERITED;
344 };
244 static SkBenchmark* Fact0(void* p) { return new BitmapBench(p, false, SkBitmap:: kARGB_8888_Config); } 345 static SkBenchmark* Fact0(void* p) { return new BitmapBench(p, false, SkBitmap:: kARGB_8888_Config); }
245 static SkBenchmark* Fact1(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_8888_Config); } 346 static SkBenchmark* Fact1(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_8888_Config); }
246 static SkBenchmark* Fact2(void* p) { return new BitmapBench(p, true, SkBitmap::k RGB_565_Config); } 347 static SkBenchmark* Fact2(void* p) { return new BitmapBench(p, true, SkBitmap::k RGB_565_Config); }
247 static SkBenchmark* Fact3(void* p) { return new BitmapBench(p, false, SkBitmap:: kARGB_4444_Config); } 348 static SkBenchmark* Fact3(void* p) { return new BitmapBench(p, false, SkBitmap:: kARGB_4444_Config); }
248 static SkBenchmark* Fact4(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_4444_Config); } 349 static SkBenchmark* Fact4(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_4444_Config); }
249 static SkBenchmark* Fact5(void* p) { return new BitmapBench(p, false, SkBitmap:: kIndex8_Config); } 350 static SkBenchmark* Fact5(void* p) { return new BitmapBench(p, false, SkBitmap:: kIndex8_Config); }
250 static SkBenchmark* Fact6(void* p) { return new BitmapBench(p, true, SkBitmap::k Index8_Config); } 351 static SkBenchmark* Fact6(void* p) { return new BitmapBench(p, true, SkBitmap::k Index8_Config); }
251 static SkBenchmark* Fact7(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_8888_Config, true, true); } 352 static SkBenchmark* Fact7(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_8888_Config, true, true); }
252 static SkBenchmark* Fact8(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_8888_Config, true, false); } 353 static SkBenchmark* Fact8(void* p) { return new BitmapBench(p, true, SkBitmap::k ARGB_8888_Config, true, false); }
253 354
254 // scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S 32_D16_filter_DX_SSE2 355 // scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S 32_D16_filter_DX_SSE2
255 static SkBenchmark* Fact9(void* p) { return new FilterBitmapBench(p, false, SkBi tmap::kARGB_8888_Config, false, false, -1, -1, true, false, true); } 356 static SkBenchmark* Fact9(void* p) { return new FilterBitmapBench(p, false, SkBi tmap::kARGB_8888_Config, false, false, -1, -1, true, false, true); }
256 static SkBenchmark* Fact10(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, false, false, -1, -1, true, false, true); } 357 static SkBenchmark* Fact10(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, false, false, -1, -1, true, false, true); }
257 static SkBenchmark* Fact11(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, true, -1, -1, true, false, true); } 358 static SkBenchmark* Fact11(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, true, -1, -1, true, false, true); }
258 static SkBenchmark* Fact12(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, false, -1, -1, true, false, true); } 359 static SkBenchmark* Fact12(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, false, -1, -1, true, false, true); }
259 360
260 // scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3} 361 // scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3}
261 static SkBenchmark* Fact13(void* p) { return new FilterBitmapBench(p, false, SkB itmap::kARGB_8888_Config, false, false, -1, -1, true, true, true); } 362 static SkBenchmark* Fact13(void* p) { return new FilterBitmapBench(p, false, SkB itmap::kARGB_8888_Config, false, false, -1, -1, true, true, true); }
262 static SkBenchmark* Fact14(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, false, false, -1, -1, true, true, true); } 363 static SkBenchmark* Fact14(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, false, false, -1, -1, true, true, true); }
263 static SkBenchmark* Fact15(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, true, -1, -1, true, true, true); } 364 static SkBenchmark* Fact15(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, true, -1, -1, true, true, true); }
264 static SkBenchmark* Fact16(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, false, -1, -1, true, true, true); } 365 static SkBenchmark* Fact16(void* p) { return new FilterBitmapBench(p, true, SkBi tmap::kARGB_8888_Config, true, false, -1, -1, true, true, true); }
265 366
367 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon}
368 static SkBenchmark* Fact17(void* p) { return new SourceAlphaBitmapBench(p, Sourc eAlphaBitmapBench::kOpaque_SourceAlpha, SkBitmap::kARGB_8888_Config); }
369 static SkBenchmark* Fact18(void* p) { return new SourceAlphaBitmapBench(p, Sourc eAlphaBitmapBench::kTransparent_SourceAlpha, SkBitmap::kARGB_8888_Config); }
370 static SkBenchmark* Fact19(void* p) { return new SourceAlphaBitmapBench(p, Sourc eAlphaBitmapBench::kTwoStripes_SourceAlpha, SkBitmap::kARGB_8888_Config); }
371 static SkBenchmark* Fact20(void* p) { return new SourceAlphaBitmapBench(p, Sourc eAlphaBitmapBench::kThreeStripes_SourceAlpha, SkBitmap::kARGB_8888_Config); }
372
266 static BenchRegistry gReg0(Fact0); 373 static BenchRegistry gReg0(Fact0);
267 static BenchRegistry gReg1(Fact1); 374 static BenchRegistry gReg1(Fact1);
268 static BenchRegistry gReg2(Fact2); 375 static BenchRegistry gReg2(Fact2);
269 static BenchRegistry gReg3(Fact3); 376 static BenchRegistry gReg3(Fact3);
270 static BenchRegistry gReg4(Fact4); 377 static BenchRegistry gReg4(Fact4);
271 static BenchRegistry gReg5(Fact5); 378 static BenchRegistry gReg5(Fact5);
272 static BenchRegistry gReg6(Fact6); 379 static BenchRegistry gReg6(Fact6);
273 static BenchRegistry gReg7(Fact7); 380 static BenchRegistry gReg7(Fact7);
274 static BenchRegistry gReg8(Fact8); 381 static BenchRegistry gReg8(Fact8);
275 382
276 static BenchRegistry gReg9(Fact9); 383 static BenchRegistry gReg9(Fact9);
277 static BenchRegistry gReg10(Fact10); 384 static BenchRegistry gReg10(Fact10);
278 static BenchRegistry gReg11(Fact11); 385 static BenchRegistry gReg11(Fact11);
279 static BenchRegistry gReg12(Fact12); 386 static BenchRegistry gReg12(Fact12);
280 387
281 static BenchRegistry gReg13(Fact13); 388 static BenchRegistry gReg13(Fact13);
282 static BenchRegistry gReg14(Fact14); 389 static BenchRegistry gReg14(Fact14);
283 static BenchRegistry gReg15(Fact15); 390 static BenchRegistry gReg15(Fact15);
284 static BenchRegistry gReg16(Fact16); 391 static BenchRegistry gReg16(Fact16);
392
393 static BenchRegistry gReg17(Fact17);
394 static BenchRegistry gReg18(Fact18);
395 static BenchRegistry gReg19(Fact19);
396 static BenchRegistry gReg20(Fact20);
OLDNEW
« no previous file with comments | « no previous file | src/opts/SkBlitRow_opts_arm_neon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698