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