humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
| 9 | #include "SkBlurMask.h" |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
| 13 | #include "SkShader.h" |
| 14 | #include "SkString.h" |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 15 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 16 | class BitmapScaleBench: public Benchmark { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 17 | int fLoopCount; |
| 18 | int fInputSize; |
| 19 | int fOutputSize; |
| 20 | SkString fName; |
| 21 | |
| 22 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 23 | BitmapScaleBench( int is, int os) { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 24 | fInputSize = is; |
| 25 | fOutputSize = os; |
| 26 | |
humper@google.com | 523521c | 2013-07-11 20:28:30 +0000 | [diff] [blame] | 27 | fLoopCount = 20; |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | protected: |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 31 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 32 | SkBitmap fInputBitmap, fOutputBitmap; |
| 33 | SkMatrix fMatrix; |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 34 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 35 | virtual const char* onGetName() { |
| 36 | return fName.c_str(); |
| 37 | } |
| 38 | |
| 39 | int inputSize() const { |
| 40 | return fInputSize; |
| 41 | } |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 42 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 43 | int outputSize() const { |
| 44 | return fOutputSize; |
| 45 | } |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 46 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 47 | float scale() const { |
| 48 | return float(outputSize())/inputSize(); |
| 49 | } |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 50 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 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 | } |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 58 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 59 | virtual void onPreDraw() { |
reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 60 | fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true); |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 61 | fInputBitmap.eraseColor(SK_ColorWHITE); |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 62 | |
reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 63 | fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true); |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 64 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 65 | fMatrix.setScale( scale(), scale() ); |
| 66 | } |
| 67 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 68 | virtual void onDraw(const int loops, SkCanvas*) { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 69 | SkPaint paint; |
| 70 | this->setupPaint(&paint); |
| 71 | |
| 72 | preBenchSetup(); |
| 73 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 74 | for (int i = 0; i < loops; i++) { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 75 | doScaleImage(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | virtual void doScaleImage() = 0; |
| 80 | virtual void preBenchSetup() {} |
| 81 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 82 | typedef Benchmark INHERITED; |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | class BitmapFilterScaleBench: public BitmapScaleBench { |
| 86 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 87 | BitmapFilterScaleBench( int is, int os) : INHERITED(is, os) { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 88 | setName( "filter" ); |
| 89 | } |
| 90 | protected: |
| 91 | virtual void doScaleImage() SK_OVERRIDE { |
| 92 | SkCanvas canvas( fOutputBitmap ); |
| 93 | SkPaint paint; |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 94 | |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 95 | paint.setFilterLevel(SkPaint::kHigh_FilterLevel); |
commit-bot@chromium.org | 1b28f6f | 2014-03-06 17:16:37 +0000 | [diff] [blame] | 96 | fInputBitmap.notifyPixelsChanged(); |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 97 | canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); |
| 98 | } |
| 99 | private: |
| 100 | typedef BitmapScaleBench INHERITED; |
| 101 | }; |
| 102 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 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);) |