OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 - matrix options: translate, scale, rotate, persp | 68 - matrix options: translate, scale, rotate, persp |
69 - tiling: none, repeat, mirror, clamp | 69 - tiling: none, repeat, mirror, clamp |
70 | 70 |
71 */ | 71 */ |
72 | 72 |
73 class BitmapBench : public Benchmark { | 73 class BitmapBench : public Benchmark { |
74 const SkColorType fColorType; | 74 const SkColorType fColorType; |
75 const SkAlphaType fAlphaType; | 75 const SkAlphaType fAlphaType; |
76 const bool fForceUpdate; //bitmap marked as dirty before each draw.
forces bitmap to be updated on device cache | 76 const bool fForceUpdate; //bitmap marked as dirty before each draw.
forces bitmap to be updated on device cache |
77 const bool fIsVolatile; | 77 const bool fIsVolatile; |
| 78 const bool fDoScale; |
78 | 79 |
79 SkBitmap fBitmap; | 80 SkBitmap fBitmap; |
80 SkPaint fPaint; | 81 SkPaint fPaint; |
81 SkString fName; | 82 SkString fName; |
82 | 83 |
83 enum { W = 128 }; | 84 enum { W = 128 }; |
84 enum { H = 128 }; | 85 enum { H = 128 }; |
85 public: | 86 public: |
86 BitmapBench(SkColorType ct, SkAlphaType at, bool forceUpdate = false, bool i
sVolatile = false) | 87 BitmapBench(SkColorType ct, SkAlphaType at, bool forceUpdate, bool isVolatil
e, bool doScale) |
87 : fColorType(ct) | 88 : fColorType(ct) |
88 , fAlphaType(at) | 89 , fAlphaType(at) |
89 , fForceUpdate(forceUpdate) | 90 , fForceUpdate(forceUpdate) |
90 , fIsVolatile(isVolatile) | 91 , fIsVolatile(isVolatile) |
| 92 , fDoScale(doScale) |
91 {} | 93 {} |
92 | 94 |
93 protected: | 95 protected: |
94 virtual const char* onGetName() { | 96 virtual const char* onGetName() { |
95 fName.set("bitmap"); | 97 fName.set("bitmap"); |
96 fName.appendf("_%s%s", sk_tool_utils::colortype_name(fColorType), | 98 fName.appendf("_%s%s", sk_tool_utils::colortype_name(fColorType), |
97 kOpaque_SkAlphaType == fAlphaType ? "" : "_A"); | 99 kOpaque_SkAlphaType == fAlphaType ? "" : "_A"); |
98 if (fForceUpdate) | 100 if (fDoScale) { |
| 101 fName.append("_scale"); |
| 102 } |
| 103 if (fForceUpdate) { |
99 fName.append("_update"); | 104 fName.append("_update"); |
100 if (fIsVolatile) | 105 } |
| 106 if (fIsVolatile) { |
101 fName.append("_volatile"); | 107 fName.append("_volatile"); |
| 108 } |
102 | 109 |
103 return fName.c_str(); | 110 return fName.c_str(); |
104 } | 111 } |
105 | 112 |
106 virtual void onPreDraw() { | 113 virtual void onPreDraw() { |
107 SkBitmap bm; | 114 SkBitmap bm; |
108 | 115 |
109 if (kIndex_8_SkColorType == fColorType) { | 116 if (kIndex_8_SkColorType == fColorType) { |
110 bm.allocPixels(SkImageInfo::MakeN32(W, H, fAlphaType)); | 117 bm.allocPixels(SkImageInfo::MakeN32(W, H, fAlphaType)); |
111 } else { | 118 } else { |
112 bm.allocPixels(SkImageInfo::Make(W, H, fColorType, fAlphaType)); | 119 bm.allocPixels(SkImageInfo::Make(W, H, fColorType, fAlphaType)); |
113 } | 120 } |
114 bm.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorBLACK : 0); | 121 bm.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorBLACK : 0); |
115 | 122 |
116 onDrawIntoBitmap(bm); | 123 onDrawIntoBitmap(bm); |
117 | 124 |
118 if (kIndex_8_SkColorType == fColorType) { | 125 if (kIndex_8_SkColorType == fColorType) { |
119 convertToIndex666(bm, &fBitmap, fAlphaType); | 126 convertToIndex666(bm, &fBitmap, fAlphaType); |
120 } else { | 127 } else { |
121 fBitmap = bm; | 128 fBitmap = bm; |
122 } | 129 } |
123 | 130 |
124 fBitmap.setIsVolatile(fIsVolatile); | 131 fBitmap.setIsVolatile(fIsVolatile); |
125 } | 132 } |
126 | 133 |
127 virtual void onDraw(const int loops, SkCanvas* canvas) { | 134 virtual void onDraw(const int loops, SkCanvas* canvas) { |
| 135 if (fDoScale) { |
| 136 canvas->scale(.99f, .99f); |
| 137 } |
128 SkIPoint dim = this->getSize(); | 138 SkIPoint dim = this->getSize(); |
129 SkRandom rand; | 139 SkRandom rand; |
130 | 140 |
131 SkPaint paint(fPaint); | 141 SkPaint paint(fPaint); |
132 this->setupPaint(&paint); | 142 this->setupPaint(&paint); |
133 | 143 |
134 const SkBitmap& bitmap = fBitmap; | 144 const SkBitmap& bitmap = fBitmap; |
135 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); | 145 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); |
136 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); | 146 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); |
137 | 147 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 static bool isBicubic(uint32_t flags) { | 196 static bool isBicubic(uint32_t flags) { |
187 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag | kBicubic_
Flag); | 197 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag | kBicubic_
Flag); |
188 } | 198 } |
189 | 199 |
190 class FilterBitmapBench : public BitmapBench { | 200 class FilterBitmapBench : public BitmapBench { |
191 uint32_t fFlags; | 201 uint32_t fFlags; |
192 SkString fFullName; | 202 SkString fFullName; |
193 public: | 203 public: |
194 FilterBitmapBench(SkColorType ct, SkAlphaType at, | 204 FilterBitmapBench(SkColorType ct, SkAlphaType at, |
195 bool forceUpdate, bool isVolitile, uint32_t flags) | 205 bool forceUpdate, bool isVolitile, uint32_t flags) |
196 : INHERITED(ct, at, forceUpdate, isVolitile) | 206 : INHERITED(ct, at, forceUpdate, isVolitile, false) |
197 , fFlags(flags) { | 207 , fFlags(flags) { |
198 } | 208 } |
199 | 209 |
200 protected: | 210 protected: |
201 virtual const char* onGetName() { | 211 virtual const char* onGetName() { |
202 fFullName.set(INHERITED::onGetName()); | 212 fFullName.set(INHERITED::onGetName()); |
203 if (fFlags & kScale_Flag) { | 213 if (fFlags & kScale_Flag) { |
204 fFullName.append("_scale"); | 214 fFullName.append("_scale"); |
205 } | 215 } |
206 if (fFlags & kRotate_Flag) { | 216 if (fFlags & kRotate_Flag) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 class SourceAlphaBitmapBench : public BitmapBench { | 275 class SourceAlphaBitmapBench : public BitmapBench { |
266 public: | 276 public: |
267 enum SourceAlpha { kOpaque_SourceAlpha, kTransparent_SourceAlpha, | 277 enum SourceAlpha { kOpaque_SourceAlpha, kTransparent_SourceAlpha, |
268 kTwoStripes_SourceAlpha, kThreeStripes_SourceAlpha}; | 278 kTwoStripes_SourceAlpha, kThreeStripes_SourceAlpha}; |
269 private: | 279 private: |
270 SkString fFullName; | 280 SkString fFullName; |
271 SourceAlpha fSourceAlpha; | 281 SourceAlpha fSourceAlpha; |
272 public: | 282 public: |
273 SourceAlphaBitmapBench(SourceAlpha alpha, SkColorType ct, | 283 SourceAlphaBitmapBench(SourceAlpha alpha, SkColorType ct, |
274 bool forceUpdate = false, bool bitmapVolatile = false) | 284 bool forceUpdate = false, bool bitmapVolatile = false) |
275 : INHERITED(ct, kPremul_SkAlphaType, forceUpdate, bitmapVolatile) | 285 : INHERITED(ct, kPremul_SkAlphaType, forceUpdate, bitmapVolatile, false) |
276 , fSourceAlpha(alpha) { | 286 , fSourceAlpha(alpha) { |
277 } | 287 } |
278 | 288 |
279 protected: | 289 protected: |
280 virtual const char* onGetName() { | 290 virtual const char* onGetName() { |
281 fFullName.set(INHERITED::onGetName()); | 291 fFullName.set(INHERITED::onGetName()); |
282 | 292 |
283 if (fSourceAlpha == kOpaque_SourceAlpha) { | 293 if (fSourceAlpha == kOpaque_SourceAlpha) { |
284 fFullName.append("_source_opaque"); | 294 fFullName.append("_source_opaque"); |
285 } else if (fSourceAlpha == kTransparent_SourceAlpha) { | 295 } else if (fSourceAlpha == kTransparent_SourceAlpha) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 r.set(SkIntToScalar(x), 0, SkIntToScalar(x+1), SkIntToScalar(h))
; | 352 r.set(SkIntToScalar(x), 0, SkIntToScalar(x+1), SkIntToScalar(h))
; |
343 canvas.drawRect(r, p); | 353 canvas.drawRect(r, p); |
344 } | 354 } |
345 } | 355 } |
346 } | 356 } |
347 | 357 |
348 private: | 358 private: |
349 typedef BitmapBench INHERITED; | 359 typedef BitmapBench INHERITED; |
350 }; | 360 }; |
351 | 361 |
352 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kPremul_SkAlphaType); ) | 362 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kPremul_SkAlphaType, false,
false, false); ) |
353 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType); ) | 363 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, false,
false, false); ) |
354 DEF_BENCH( return new BitmapBench(kRGB_565_SkColorType, kOpaque_SkAlphaType); ) | 364 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, false,
false, true); ) |
355 DEF_BENCH( return new BitmapBench(kIndex_8_SkColorType, kPremul_SkAlphaType); ) | 365 DEF_BENCH( return new BitmapBench(kRGB_565_SkColorType, kOpaque_SkAlphaType, fal
se, false, false); ) |
356 DEF_BENCH( return new BitmapBench(kIndex_8_SkColorType, kOpaque_SkAlphaType); ) | 366 DEF_BENCH( return new BitmapBench(kIndex_8_SkColorType, kPremul_SkAlphaType, fal
se, false, false); ) |
357 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, t
rue); ) | 367 DEF_BENCH( return new BitmapBench(kIndex_8_SkColorType, kOpaque_SkAlphaType, fal
se, false, false); ) |
358 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, f
alse); ) | 368 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, t
rue, false); ) |
| 369 DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, f
alse, false); ) |
359 | 370 |
360 // scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S
32_D16_filter_DX_SSE2 | 371 // scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S
32_D16_filter_DX_SSE2 |
361 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kBilerp_Flag); ) | 372 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kBilerp_Flag); ) |
362 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, f
alse, false, kScale_Flag | kBilerp_Flag); ) | 373 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, f
alse, false, kScale_Flag | kBilerp_Flag); ) |
363 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, true, kScale_Flag | kBilerp_Flag); ) | 374 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, true, kScale_Flag | kBilerp_Flag); ) |
364 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, false, kScale_Flag | kBilerp_Flag); ) | 375 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, false, kScale_Flag | kBilerp_Flag); ) |
365 | 376 |
366 // scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3} | 377 // scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3} |
367 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) | 378 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) |
368 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) | 379 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) |
369 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, true, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) | 380 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, true, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) |
370 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) | 381 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, t
rue, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) |
371 | 382 |
372 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); ) | 383 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); ) |
373 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); ) | 384 DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); ) |
374 | 385 |
375 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} | 386 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} |
376 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kOpaque_Sou
rceAlpha, kN32_SkColorType); ) | 387 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kOpaque_Sou
rceAlpha, kN32_SkColorType); ) |
377 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTransparen
t_SourceAlpha, kN32_SkColorType); ) | 388 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTransparen
t_SourceAlpha, kN32_SkColorType); ) |
378 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTwoStripes
_SourceAlpha, kN32_SkColorType); ) | 389 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTwoStripes
_SourceAlpha, kN32_SkColorType); ) |
379 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kThreeStrip
es_SourceAlpha, kN32_SkColorType); ) | 390 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kThreeStrip
es_SourceAlpha, kN32_SkColorType); ) |
OLD | NEW |