| OLD | NEW |
| 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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 */ | 74 */ |
| 75 | 75 |
| 76 class BitmapBench : public SkBenchmark { | 76 class BitmapBench : public SkBenchmark { |
| 77 SkBitmap fBitmap; | 77 SkBitmap fBitmap; |
| 78 SkPaint fPaint; | 78 SkPaint fPaint; |
| 79 bool fIsOpaque; | 79 bool fIsOpaque; |
| 80 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 |
| 81 bool fIsVolatile; | 81 bool fIsVolatile; |
| 82 SkBitmap::Config fConfig; | 82 SkBitmap::Config fConfig; |
| 83 SkString fName; | 83 SkString fName; |
| 84 enum { BICUBIC_DUR_SCALE = 20 }; | |
| 85 enum { N = SkBENCHLOOP(15 * BICUBIC_DUR_SCALE) }; | |
| 86 enum { W = 128 }; | 84 enum { W = 128 }; |
| 87 enum { H = 128 }; | 85 enum { H = 128 }; |
| 88 public: | 86 public: |
| 89 BitmapBench(void* param, bool isOpaque, SkBitmap::Config c, | 87 BitmapBench(void* param, bool isOpaque, SkBitmap::Config c, |
| 90 bool forceUpdate = false, bool bitmapVolatile = false) | 88 bool forceUpdate = false, bool bitmapVolatile = false) |
| 91 : INHERITED(param) | 89 : INHERITED(param) |
| 92 , fIsOpaque(isOpaque) | 90 , fIsOpaque(isOpaque) |
| 93 , fForceUpdate(forceUpdate) | 91 , fForceUpdate(forceUpdate) |
| 94 , fIsVolatile(bitmapVolatile) | 92 , fIsVolatile(bitmapVolatile) |
| 95 , fConfig(c) { | 93 , fConfig(c) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 SkIPoint dim = this->getSize(); | 137 SkIPoint dim = this->getSize(); |
| 140 SkRandom rand; | 138 SkRandom rand; |
| 141 | 139 |
| 142 SkPaint paint(fPaint); | 140 SkPaint paint(fPaint); |
| 143 this->setupPaint(&paint); | 141 this->setupPaint(&paint); |
| 144 | 142 |
| 145 const SkBitmap& bitmap = fBitmap; | 143 const SkBitmap& bitmap = fBitmap; |
| 146 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); | 144 const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2); |
| 147 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); | 145 const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2); |
| 148 | 146 |
| 149 int count = N; | 147 for (int i = 0; i < this->getLoops(); i++) { |
| 150 #ifdef SK_RELEASE | |
| 151 // in DEBUG, N is always 1 | |
| 152 if (SkPaint::kHigh_FilterLevel == paint.getFilterLevel()) { | |
| 153 count /= BICUBIC_DUR_SCALE; | |
| 154 } | |
| 155 #endif | |
| 156 for (int i = 0; i < count; i++) { | |
| 157 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; | 148 SkScalar x = x0 + rand.nextUScalar1() * dim.fX; |
| 158 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; | 149 SkScalar y = y0 + rand.nextUScalar1() * dim.fY; |
| 159 | 150 |
| 160 if (fForceUpdate) | 151 if (fForceUpdate) |
| 161 bitmap.notifyPixelsChanged(); | 152 bitmap.notifyPixelsChanged(); |
| 162 | 153 |
| 163 canvas->drawBitmap(bitmap, x, y, &paint); | 154 canvas->drawBitmap(bitmap, x, y, &paint); |
| 164 } | 155 } |
| 165 } | 156 } |
| 166 | 157 |
| 167 virtual float onGetDurationScale() SK_OVERRIDE { | |
| 168 SkPaint paint; | |
| 169 this->setupPaint(&paint); | |
| 170 #ifdef SK_DEBUG | |
| 171 return 1; | |
| 172 #else | |
| 173 return SkPaint::kHigh_FilterLevel == paint.getFilterLevel() ? | |
| 174 (float)BICUBIC_DUR_SCALE : 1; | |
| 175 #endif | |
| 176 } | |
| 177 | |
| 178 virtual void onDrawIntoBitmap(const SkBitmap& bm) { | 158 virtual void onDrawIntoBitmap(const SkBitmap& bm) { |
| 179 const int w = bm.width(); | 159 const int w = bm.width(); |
| 180 const int h = bm.height(); | 160 const int h = bm.height(); |
| 181 | 161 |
| 182 SkCanvas canvas(bm); | 162 SkCanvas canvas(bm); |
| 183 SkPaint p; | 163 SkPaint p; |
| 184 p.setAntiAlias(true); | 164 p.setAntiAlias(true); |
| 185 p.setColor(SK_ColorRED); | 165 p.setColor(SK_ColorRED); |
| 186 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, | 166 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2, |
| 187 SkIntToScalar(SkMin32(w, h))*3/8, p); | 167 SkIntToScalar(SkMin32(w, h))*3/8, p); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 212 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag); | 192 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag); |
| 213 } | 193 } |
| 214 | 194 |
| 215 static bool isBicubic(uint32_t flags) { | 195 static bool isBicubic(uint32_t flags) { |
| 216 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag | kBicubic_
Flag); | 196 return (flags & (kBilerp_Flag | kBicubic_Flag)) == (kBilerp_Flag | kBicubic_
Flag); |
| 217 } | 197 } |
| 218 | 198 |
| 219 class FilterBitmapBench : public BitmapBench { | 199 class FilterBitmapBench : public BitmapBench { |
| 220 uint32_t fFlags; | 200 uint32_t fFlags; |
| 221 SkString fFullName; | 201 SkString fFullName; |
| 222 enum { N = SkBENCHLOOP(300) }; | |
| 223 public: | 202 public: |
| 224 FilterBitmapBench(void* param, bool isOpaque, SkBitmap::Config c, | 203 FilterBitmapBench(void* param, bool isOpaque, SkBitmap::Config c, |
| 225 bool forceUpdate, bool isVolitile, uint32_t flags) | 204 bool forceUpdate, bool isVolitile, uint32_t flags) |
| 226 : INHERITED(param, isOpaque, c, forceUpdate, isVolitile) | 205 : INHERITED(param, isOpaque, c, forceUpdate, isVolitile) |
| 227 , fFlags(flags) { | 206 , fFlags(flags) { |
| 228 } | 207 } |
| 229 | 208 |
| 230 protected: | 209 protected: |
| 231 virtual const char* onGetName() { | 210 virtual const char* onGetName() { |
| 232 fFullName.set(INHERITED::onGetName()); | 211 fFullName.set(INHERITED::onGetName()); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr
ue, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) | 379 DEF_BENCH( return new FilterBitmapBench(p, true, SkBitmap::kARGB_8888_Config, tr
ue, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); ) |
| 401 | 380 |
| 402 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f
alse, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); ) | 381 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f
alse, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); ) |
| 403 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); ) | 382 DEF_BENCH( return new FilterBitmapBench(p, false, SkBitmap::kARGB_8888_Config, f
alse, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); ) |
| 404 | 383 |
| 405 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} | 384 // source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon} |
| 406 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kOpaque_
SourceAlpha, SkBitmap::kARGB_8888_Config); ) | 385 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kOpaque_
SourceAlpha, SkBitmap::kARGB_8888_Config); ) |
| 407 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTranspa
rent_SourceAlpha, SkBitmap::kARGB_8888_Config); ) | 386 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTranspa
rent_SourceAlpha, SkBitmap::kARGB_8888_Config); ) |
| 408 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTwoStri
pes_SourceAlpha, SkBitmap::kARGB_8888_Config); ) | 387 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kTwoStri
pes_SourceAlpha, SkBitmap::kARGB_8888_Config); ) |
| 409 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kThreeSt
ripes_SourceAlpha, SkBitmap::kARGB_8888_Config); ) | 388 DEF_BENCH( return new SourceAlphaBitmapBench(p, SourceAlphaBitmapBench::kThreeSt
ripes_SourceAlpha, SkBitmap::kARGB_8888_Config); ) |
| OLD | NEW |