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 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 35 | const char* onGetName() override { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 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 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 51 | SkIPoint onGetSize() override { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 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 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 59 | void onPreDraw() override { |
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 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 68 | void onDraw(const int loops, SkCanvas*) override { |
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: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 91 | void doScaleImage() override { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 92 | SkCanvas canvas( fOutputBitmap ); |
| 93 | SkPaint paint; |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 94 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 95 | paint.setFilterQuality(kHigh_SkFilterQuality); |
commit-bot@chromium.org | 1b28f6f | 2014-03-06 17:16:37 +0000 | [diff] [blame] | 96 | fInputBitmap.notifyPixelsChanged(); |
Florin Malita | c54d8db | 2014-12-10 12:02:16 -0500 | [diff] [blame] | 97 | canvas.concat(fMatrix); |
| 98 | canvas.drawBitmap(fInputBitmap, 0, 0, &paint ); |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 99 | } |
| 100 | private: |
| 101 | typedef BitmapScaleBench INHERITED; |
| 102 | }; |
| 103 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 104 | DEF_BENCH(return new BitmapFilterScaleBench(10, 90);) |
| 105 | DEF_BENCH(return new BitmapFilterScaleBench(30, 90);) |
| 106 | DEF_BENCH(return new BitmapFilterScaleBench(80, 90);) |
| 107 | DEF_BENCH(return new BitmapFilterScaleBench(90, 90);) |
| 108 | DEF_BENCH(return new BitmapFilterScaleBench(90, 80);) |
| 109 | DEF_BENCH(return new BitmapFilterScaleBench(90, 30);) |
| 110 | DEF_BENCH(return new BitmapFilterScaleBench(90, 10);) |
| 111 | DEF_BENCH(return new BitmapFilterScaleBench(256, 64);) |
| 112 | DEF_BENCH(return new BitmapFilterScaleBench(64, 256);) |