OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkBenchmark.h" |
| 9 #include "SkCanvas.h" |
| 10 #include "SkPaint.h" |
| 11 #include "SkRandom.h" |
| 12 #include "SkShader.h" |
| 13 #include "SkString.h" |
| 14 #include "SkBlurMask.h" |
| 15 |
| 16 class BitmapScaleBench: public SkBenchmark { |
| 17 int fLoopCount; |
| 18 int fInputSize; |
| 19 int fOutputSize; |
| 20 SkString fName; |
| 21 |
| 22 public: |
| 23 BitmapScaleBench(void *param, int is, int os) : INHERITED(param) { |
| 24 fInputSize = is; |
| 25 fOutputSize = os; |
| 26 |
| 27 fLoopCount = 100; |
| 28 } |
| 29 |
| 30 protected: |
| 31 |
| 32 SkBitmap fInputBitmap, fOutputBitmap; |
| 33 SkMatrix fMatrix; |
| 34 |
| 35 virtual const char* onGetName() { |
| 36 return fName.c_str(); |
| 37 } |
| 38 |
| 39 int inputSize() const { |
| 40 return fInputSize; |
| 41 } |
| 42 |
| 43 int outputSize() const { |
| 44 return fOutputSize; |
| 45 } |
| 46 |
| 47 float scale() const { |
| 48 return float(outputSize())/inputSize(); |
| 49 } |
| 50 |
| 51 SkIPoint onGetSize() SK_OVERRIDE { |
| 52 return SkIPoint::Make( fOutputSize, fOutputSize ); |
| 53 } |
| 54 |
| 55 void setName(const char * name) { |
| 56 fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize ); |
| 57 } |
| 58 |
| 59 virtual void onPreDraw() { |
| 60 fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fInputSize, fInputSi
ze); |
| 61 fInputBitmap.allocPixels(); |
| 62 fInputBitmap.eraseColor(SK_ColorWHITE); |
| 63 fInputBitmap.setIsOpaque(true); |
| 64 |
| 65 fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fOutputSize, fOutpu
tSize); |
| 66 fOutputBitmap.allocPixels(); |
| 67 fOutputBitmap.setIsOpaque(true); |
| 68 |
| 69 fMatrix.setScale( scale(), scale() ); |
| 70 } |
| 71 |
| 72 virtual void onDraw(SkCanvas*) { |
| 73 SkPaint paint; |
| 74 this->setupPaint(&paint); |
| 75 |
| 76 preBenchSetup(); |
| 77 |
| 78 for (int i = 0; i < SkBENCHLOOP(fLoopCount); i++) { |
| 79 doScaleImage(); |
| 80 } |
| 81 } |
| 82 |
| 83 virtual void doScaleImage() = 0; |
| 84 virtual void preBenchSetup() {} |
| 85 private: |
| 86 typedef SkBenchmark INHERITED; |
| 87 }; |
| 88 |
| 89 class BitmapFilterScaleBench: public BitmapScaleBench { |
| 90 public: |
| 91 BitmapFilterScaleBench(void *param, int is, int os) : INHERITED(param, is, o
s) { |
| 92 setName( "filter" ); |
| 93 } |
| 94 protected: |
| 95 virtual void doScaleImage() SK_OVERRIDE { |
| 96 SkCanvas canvas( fOutputBitmap ); |
| 97 SkPaint paint; |
| 98 |
| 99 paint.setFlags( SkPaint::kHighQualityFilterBitmap_Flag | SkPaint::kFilte
rBitmap_Flag ); |
| 100 |
| 101 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); |
| 102 } |
| 103 private: |
| 104 typedef BitmapScaleBench INHERITED; |
| 105 }; |
| 106 |
| 107 class BitmapDirectScaleBench: public BitmapScaleBench { |
| 108 public: |
| 109 BitmapDirectScaleBench(void *param, int is, int os) : INHERITED(param, is, o
s) { |
| 110 setName( "direct" ); |
| 111 } |
| 112 protected: |
| 113 virtual void doScaleImage() SK_OVERRIDE { |
| 114 fInputBitmap.scale( &fOutputBitmap ); |
| 115 } |
| 116 private: |
| 117 typedef BitmapScaleBench INHERITED; |
| 118 }; |
| 119 |
| 120 |
| 121 DEF_BENCH(return new BitmapFilterScaleBench(p, 10, 90);) |
| 122 DEF_BENCH(return new BitmapFilterScaleBench(p, 30, 90);) |
| 123 DEF_BENCH(return new BitmapFilterScaleBench(p, 80, 90);) |
| 124 // DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 90);) |
| 125 // DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 80);) |
| 126 // DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 30);) |
| 127 // DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 10);) |
| 128 |
| 129 DEF_BENCH(return new BitmapDirectScaleBench(p, 10, 90);) |
| 130 DEF_BENCH(return new BitmapDirectScaleBench(p, 30, 90);) |
| 131 DEF_BENCH(return new BitmapDirectScaleBench(p, 80, 90);) |
| 132 // DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 90);) |
| 133 // DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 80);) |
| 134 // DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 30);) |
| 135 // DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 10);) |
OLD | NEW |