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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 public: | 86 public: |
87 BitmapBench(SkColorType ct, SkAlphaType at, bool forceUpdate, bool isVolatil
e, bool doScale) | 87 BitmapBench(SkColorType ct, SkAlphaType at, bool forceUpdate, bool isVolatil
e, bool doScale) |
88 : fColorType(ct) | 88 : fColorType(ct) |
89 , fAlphaType(at) | 89 , fAlphaType(at) |
90 , fForceUpdate(forceUpdate) | 90 , fForceUpdate(forceUpdate) |
91 , fIsVolatile(isVolatile) | 91 , fIsVolatile(isVolatile) |
92 , fDoScale(doScale) | 92 , fDoScale(doScale) |
93 {} | 93 {} |
94 | 94 |
95 protected: | 95 protected: |
96 virtual const char* onGetName() { | 96 const char* onGetName() override { |
97 fName.set("bitmap"); | 97 fName.set("bitmap"); |
98 fName.appendf("_%s%s", sk_tool_utils::colortype_name(fColorType), | 98 fName.appendf("_%s%s", sk_tool_utils::colortype_name(fColorType), |
99 kOpaque_SkAlphaType == fAlphaType ? "" : "_A"); | 99 kOpaque_SkAlphaType == fAlphaType ? "" : "_A"); |
100 if (fDoScale) { | 100 if (fDoScale) { |
101 fName.append("_scale"); | 101 fName.append("_scale"); |
102 } | 102 } |
103 if (fForceUpdate) { | 103 if (fForceUpdate) { |
104 fName.append("_update"); | 104 fName.append("_update"); |
105 } | 105 } |
106 if (fIsVolatile) { | 106 if (fIsVolatile) { |
107 fName.append("_volatile"); | 107 fName.append("_volatile"); |
108 } | 108 } |
109 | 109 |
110 return fName.c_str(); | 110 return fName.c_str(); |
111 } | 111 } |
112 | 112 |
113 virtual void onPreDraw() { | 113 void onPreDraw() override { |
114 SkBitmap bm; | 114 SkBitmap bm; |
115 | 115 |
116 if (kIndex_8_SkColorType == fColorType) { | 116 if (kIndex_8_SkColorType == fColorType) { |
117 bm.allocPixels(SkImageInfo::MakeN32(W, H, fAlphaType)); | 117 bm.allocPixels(SkImageInfo::MakeN32(W, H, fAlphaType)); |
118 } else { | 118 } else { |
119 bm.allocPixels(SkImageInfo::Make(W, H, fColorType, fAlphaType)); | 119 bm.allocPixels(SkImageInfo::Make(W, H, fColorType, fAlphaType)); |
120 } | 120 } |
121 bm.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorBLACK : 0); | 121 bm.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorBLACK : 0); |
122 | 122 |
123 onDrawIntoBitmap(bm); | 123 this->onDrawIntoBitmap(bm); |
124 | 124 |
125 if (kIndex_8_SkColorType == fColorType) { | 125 if (kIndex_8_SkColorType == fColorType) { |
126 convertToIndex666(bm, &fBitmap, fAlphaType); | 126 convertToIndex666(bm, &fBitmap, fAlphaType); |
127 } else { | 127 } else { |
128 fBitmap = bm; | 128 fBitmap = bm; |
129 } | 129 } |
130 | 130 |
131 fBitmap.setIsVolatile(fIsVolatile); | 131 fBitmap.setIsVolatile(fIsVolatile); |
132 } | 132 } |
133 | 133 |
134 virtual void onDraw(const int loops, SkCanvas* canvas) { | 134 void onDraw(const int loops, SkCanvas* canvas) override { |
135 if (fDoScale) { | 135 if (fDoScale) { |
136 canvas->scale(.99f, .99f); | 136 canvas->scale(.99f, .99f); |
137 } | 137 } |
138 SkIPoint dim = this->getSize(); | 138 SkIPoint dim = this->getSize(); |
139 SkRandom rand; | 139 SkRandom rand; |
140 | 140 |
141 SkPaint paint(fPaint); | 141 SkPaint paint(fPaint); |
142 this->setupPaint(&paint); | 142 this->setupPaint(&paint); |
143 | 143 |
144 const SkBitmap& bitmap = fBitmap; | 144 const SkBitmap& bitmap = fBitmap; |
145 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); | 145 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); |
146 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); | 146 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); |
147 | 147 |
148 for (int i = 0; i < loops; i++) { | 148 for (int i = 0; i < loops; i++) { |
149 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; | 149 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; |
150 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; | 150 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; |
151 | 151 |
152 if (fForceUpdate) | 152 if (fForceUpdate) |
153 bitmap.notifyPixelsChanged(); | 153 bitmap.notifyPixelsChanged(); |
154 | 154 |
155 canvas->drawBitmap(bitmap, x, y, &paint); | 155 canvas->drawBitmap(bitmap, x, y, &paint); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 virtual void onDrawIntoBitmap(const SkBitmap& bm) { | 159 virtual void onDrawIntoBitmap(const SkBitmap& bm) { |
160 const int w = bm.width(); | 160 const int w = bm.width(); |
161 const int h = bm.height(); | 161 const int h = bm.height(); |
162 | 162 |
163 SkCanvas canvas(bm); | 163 SkCanvas canvas(bm); |
164 SkPaint p; | 164 SkPaint p; |
165 p.setAntiAlias(true); | 165 p.setAntiAlias(true); |
166 p.setColor(SK_ColorRED); | 166 p.setColor(SK_ColorRED); |
167 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, | 167 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, |
168 SkIntToScalar(SkMin32(w, h))*3/8, p); | 168 SkIntToScalar(SkMin32(w, h))*3/8, p); |
169 | 169 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 uint32_t fFlags; | 201 uint32_t fFlags; |
202 SkString fFullName; | 202 SkString fFullName; |
203 public: | 203 public: |
204 FilterBitmapBench(SkColorType ct, SkAlphaType at, | 204 FilterBitmapBench(SkColorType ct, SkAlphaType at, |
205 bool forceUpdate, bool isVolitile, uint32_t flags) | 205 bool forceUpdate, bool isVolitile, uint32_t flags) |
206 : INHERITED(ct, at, forceUpdate, isVolitile, false) | 206 : INHERITED(ct, at, forceUpdate, isVolitile, false) |
207 , fFlags(flags) { | 207 , fFlags(flags) { |
208 } | 208 } |
209 | 209 |
210 protected: | 210 protected: |
211 virtual const char* onGetName() { | 211 const char* onGetName() override { |
212 fFullName.set(INHERITED::onGetName()); | 212 fFullName.set(INHERITED::onGetName()); |
213 if (fFlags & kScale_Flag) { | 213 if (fFlags & kScale_Flag) { |
214 fFullName.append("_scale"); | 214 fFullName.append("_scale"); |
215 } | 215 } |
216 if (fFlags & kRotate_Flag) { | 216 if (fFlags & kRotate_Flag) { |
217 fFullName.append("_rotate"); | 217 fFullName.append("_rotate"); |
218 } | 218 } |
219 if (isBilerp(fFlags)) { | 219 if (isBilerp(fFlags)) { |
220 fFullName.append("_bilerp"); | 220 fFullName.append("_bilerp"); |
221 } else if (isBicubic(fFlags)) { | 221 } else if (isBicubic(fFlags)) { |
222 fFullName.append("_bicubic"); | 222 fFullName.append("_bicubic"); |
223 } | 223 } |
224 | 224 |
225 return fFullName.c_str(); | 225 return fFullName.c_str(); |
226 } | 226 } |
227 | 227 |
228 virtual void onDraw(const int loops, SkCanvas* canvas) { | 228 void onDraw(const int loops, SkCanvas* canvas) override { |
229 SkISize dim = canvas->getDeviceSize(); | 229 SkISize dim = canvas->getDeviceSize(); |
230 if (fFlags & kScale_Flag) { | 230 if (fFlags & kScale_Flag) { |
231 const SkScalar x = SkIntToScalar(dim.fWidth) / 2; | 231 const SkScalar x = SkIntToScalar(dim.fWidth) / 2; |
232 const SkScalar y = SkIntToScalar(dim.fHeight) / 2; | 232 const SkScalar y = SkIntToScalar(dim.fHeight) / 2; |
233 | 233 |
234 canvas->translate(x, y); | 234 canvas->translate(x, y); |
235 // just enough so we can't take the sprite case | 235 // just enough so we can't take the sprite case |
236 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); | 236 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
237 canvas->translate(-x, -y); | 237 canvas->translate(-x, -y); |
238 } | 238 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 SkString fFullName; | 280 SkString fFullName; |
281 SourceAlpha fSourceAlpha; | 281 SourceAlpha fSourceAlpha; |
282 public: | 282 public: |
283 SourceAlphaBitmapBench(SourceAlpha alpha, SkColorType ct, | 283 SourceAlphaBitmapBench(SourceAlpha alpha, SkColorType ct, |
284 bool forceUpdate = false, bool bitmapVolatile = false) | 284 bool forceUpdate = false, bool bitmapVolatile = false) |
285 : INHERITED(ct, kPremul_SkAlphaType, forceUpdate, bitmapVolatile, false) | 285 : INHERITED(ct, kPremul_SkAlphaType, forceUpdate, bitmapVolatile, false) |
286 , fSourceAlpha(alpha) { | 286 , fSourceAlpha(alpha) { |
287 } | 287 } |
288 | 288 |
289 protected: | 289 protected: |
290 virtual const char* onGetName() { | 290 const char* onGetName() override { |
291 fFullName.set(INHERITED::onGetName()); | 291 fFullName.set(INHERITED::onGetName()); |
292 | 292 |
293 if (fSourceAlpha == kOpaque_SourceAlpha) { | 293 if (fSourceAlpha == kOpaque_SourceAlpha) { |
294 fFullName.append("_source_opaque"); | 294 fFullName.append("_source_opaque"); |
295 } else if (fSourceAlpha == kTransparent_SourceAlpha) { | 295 } else if (fSourceAlpha == kTransparent_SourceAlpha) { |
296 fFullName.append("_source_transparent"); | 296 fFullName.append("_source_transparent"); |
297 } else if (fSourceAlpha == kTwoStripes_SourceAlpha) { | 297 } else if (fSourceAlpha == kTwoStripes_SourceAlpha) { |
298 fFullName.append("_source_stripes_two"); | 298 fFullName.append("_source_stripes_two"); |
299 } else if (fSourceAlpha == kThreeStripes_SourceAlpha) { | 299 } else if (fSourceAlpha == kThreeStripes_SourceAlpha) { |
300 fFullName.append("_source_stripes_three"); | 300 fFullName.append("_source_stripes_three"); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 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); ) |
382 | 382 |
383 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); ) |
384 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); ) |
385 | 385 |
386 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} | 386 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} |
387 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kOpaque_Sou
rceAlpha, kN32_SkColorType); ) | 387 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kOpaque_Sou
rceAlpha, kN32_SkColorType); ) |
388 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTransparen
t_SourceAlpha, kN32_SkColorType); ) | 388 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTransparen
t_SourceAlpha, kN32_SkColorType); ) |
389 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTwoStripes
_SourceAlpha, kN32_SkColorType); ) | 389 DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTwoStripes
_SourceAlpha, kN32_SkColorType); ) |
390 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 |