Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 13 #include "SkShader.h" | 13 #include "SkShader.h" |
| 14 #include "SkString.h" | 14 #include "SkString.h" |
| 15 | 15 |
| 16 class BitmapScaleBench: public Benchmark { | 16 class BitmapFractionalBench: public Benchmark { |
| 17 int fLoopCount; | |
| 18 int fInputSize; | 17 int fInputSize; |
| 19 int fOutputSize; | 18 int fOutputSize; |
| 20 SkString fName; | |
| 21 | 19 |
| 22 public: | 20 public: |
| 23 BitmapScaleBench( int is, int os) { | 21 BitmapFractionalBench( int is ) { |
| 24 fInputSize = is; | 22 fInputSize = is; |
| 25 fOutputSize = os; | 23 fOutputSize = 2*is; |
| 26 | |
| 27 fLoopCount = 20; | |
| 28 } | 24 } |
| 29 | 25 |
| 30 protected: | 26 protected: |
| 31 | 27 |
| 32 SkBitmap fInputBitmap, fOutputBitmap; | 28 SkBitmap fInputBitmap, fOutputBitmap; |
| 33 SkMatrix fMatrix; | 29 SkMatrix fMatrix; |
| 34 | 30 |
| 35 virtual const char* onGetName() { | 31 virtual const char* onGetName() { |
| 36 return fName.c_str(); | 32 return "bitmap_fractional_bench"; |
| 37 } | 33 } |
| 38 | 34 |
| 39 int inputSize() const { | 35 int inputSize() const { |
| 40 return fInputSize; | 36 return fInputSize; |
| 41 } | 37 } |
| 42 | 38 |
| 43 int outputSize() const { | 39 int outputSize() const { |
| 44 return fOutputSize; | 40 return fOutputSize; |
| 45 } | 41 } |
| 46 | 42 |
| 47 float scale() const { | |
| 48 return float(outputSize())/inputSize(); | |
| 49 } | |
| 50 | |
| 51 SkIPoint onGetSize() SK_OVERRIDE { | 43 SkIPoint onGetSize() SK_OVERRIDE { |
| 52 return SkIPoint::Make( fOutputSize, fOutputSize ); | 44 return SkIPoint::Make( fOutputSize, fOutputSize ); |
| 53 } | 45 } |
| 54 | 46 |
| 55 void setName(const char * name) { | |
| 56 fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize ); | |
| 57 } | |
| 58 | |
| 59 virtual void onPreDraw() { | 47 virtual void onPreDraw() { |
| 60 fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true); | 48 fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true); |
| 61 fInputBitmap.eraseColor(SK_ColorWHITE); | 49 fInputBitmap.eraseColor(SK_ColorWHITE); |
| 62 | 50 |
| 63 fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true); | 51 fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true); |
| 64 | |
| 65 fMatrix.setScale( scale(), scale() ); | |
| 66 } | 52 } |
| 67 | 53 |
| 68 virtual void onDraw(const int loops, SkCanvas*) { | 54 virtual void onDraw(const int loops, SkCanvas*) { |
| 69 SkPaint paint; | 55 SkPaint paint; |
| 70 this->setupPaint(&paint); | 56 this->setupPaint(&paint); |
| 71 | 57 |
| 72 preBenchSetup(); | 58 preBenchSetup(); |
| 73 | 59 |
| 60 SkCanvas canvas( fOutputBitmap ); | |
| 61 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); | |
| 62 fInputBitmap.notifyPixelsChanged(); | |
| 63 | |
| 74 for (int i = 0; i < loops; i++) { | 64 for (int i = 0; i < loops; i++) { |
| 75 doScaleImage(); | 65 // re-scale the image by a variety of close, fractional scales |
| 66 for (int j = 0 ; j < 10 ; j++) { | |
| 67 fMatrix = SkMatrix::I(); | |
| 68 fMatrix.setScale( 1 + j/3.f, 1 + j/3.f ); | |
| 69 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); | |
| 70 } | |
| 71 // Now try some fractional translates | |
| 72 for (int j = 0 ; j < 10 ; j++) { | |
| 73 fMatrix = SkMatrix::I(); | |
| 74 fMatrix.setTranslate( j/3.f, j/3.f ); | |
| 75 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); | |
| 76 } | |
| 77 // Finally, some fractional translates with non-identity scale. | |
| 78 for (int j = 0 ; j < 10 ; j++) { | |
| 79 fMatrix = SkMatrix::I(); | |
| 80 fMatrix.setTranslate( j/3.f, j/3.f ); | |
| 81 fMatrix.preScale( 1.5, 1.5 ); | |
|
reed1
2014/08/25 17:10:15
may get some warnings of double->float here.
| |
| 82 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); | |
| 83 } | |
| 76 } | 84 } |
| 77 } | 85 } |
| 78 | 86 |
| 79 virtual void doScaleImage() = 0; | |
| 80 virtual void preBenchSetup() {} | 87 virtual void preBenchSetup() {} |
| 81 private: | 88 private: |
| 82 typedef Benchmark INHERITED; | 89 typedef Benchmark INHERITED; |
| 83 }; | 90 }; |
| 84 | 91 |
| 85 class BitmapFilterScaleBench: public BitmapScaleBench { | 92 DEF_BENCH(return new BitmapFractionalBench(256);) |
| 86 public: | |
| 87 BitmapFilterScaleBench( int is, int os) : INHERITED(is, os) { | |
| 88 setName( "filter" ); | |
| 89 } | |
| 90 protected: | |
| 91 virtual void doScaleImage() SK_OVERRIDE { | |
| 92 SkCanvas canvas( fOutputBitmap ); | |
| 93 SkPaint paint; | |
| 94 | |
| 95 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); | |
| 96 fInputBitmap.notifyPixelsChanged(); | |
| 97 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); | |
| 98 } | |
| 99 private: | |
| 100 typedef BitmapScaleBench INHERITED; | |
| 101 }; | |
| 102 | |
| 103 DEF_BENCH(return new BitmapFilterScaleBench(10, 90);) | |
| 104 DEF_BENCH(return new BitmapFilterScaleBench(30, 90);) | |
| 105 DEF_BENCH(return new BitmapFilterScaleBench(80, 90);) | |
| 106 DEF_BENCH(return new BitmapFilterScaleBench(90, 90);) | |
| 107 DEF_BENCH(return new BitmapFilterScaleBench(90, 80);) | |
| 108 DEF_BENCH(return new BitmapFilterScaleBench(90, 30);) | |
| 109 DEF_BENCH(return new BitmapFilterScaleBench(90, 10);) | |
| 110 DEF_BENCH(return new BitmapFilterScaleBench(256, 64);) | |
| 111 DEF_BENCH(return new BitmapFilterScaleBench(64, 256);) | |
| OLD | NEW |