senorblanco@chromium.org | c3799ad | 2013-02-08 16:40: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 | |
| 8 | #include "SkBenchmark.h" |
| 9 | #include "SkCanvas.h" |
senorblanco@chromium.org | c3799ad | 2013-02-08 16:40:14 +0000 | [diff] [blame] | 10 | #include "SkShader.h" |
| 11 | #include "SkString.h" |
| 12 | #include "SkBicubicImageFilter.h" |
| 13 | |
| 14 | // This bench exercises SkBicubicImageFilter, upsampling a 40x40 input to |
| 15 | // 100x100, 400x100, 100x400, and 400x400. |
| 16 | |
| 17 | class BicubicBench : public SkBenchmark { |
| 18 | SkSize fScale; |
| 19 | SkString fName; |
| 20 | |
| 21 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame^] | 22 | BicubicBench(float x, float y) |
| 23 | : fScale(SkSize::Make(SkFloatToScalar(x), SkFloatToScalar(y))) { |
senorblanco@chromium.org | c3799ad | 2013-02-08 16:40:14 +0000 | [diff] [blame] | 24 | fName.printf("bicubic_%gx%g", |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame^] | 25 | SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight)); |
senorblanco@chromium.org | c3799ad | 2013-02-08 16:40:14 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | protected: |
| 29 | virtual const char* onGetName() { |
| 30 | return fName.c_str(); |
| 31 | } |
| 32 | |
| 33 | virtual void onDraw(SkCanvas* canvas) { |
| 34 | SkPaint paint; |
| 35 | this->setupPaint(&paint); |
| 36 | |
| 37 | paint.setAntiAlias(true); |
| 38 | |
senorblanco@chromium.org | c3799ad | 2013-02-08 16:40:14 +0000 | [diff] [blame] | 39 | SkRect r = SkRect::MakeWH(40, 40); |
| 40 | SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(fScale)); |
| 41 | paint.setImageFilter(bicubic); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 42 | |
| 43 | for (int i = 0; i < this->getLoops(); i++) { |
| 44 | canvas->save(); |
| 45 | canvas->clipRect(r); |
| 46 | canvas->drawOval(r, paint); |
| 47 | canvas->restore(); |
| 48 | } |
senorblanco@chromium.org | c3799ad | 2013-02-08 16:40:14 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | private: |
| 52 | typedef SkBenchmark INHERITED; |
| 53 | }; |
| 54 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame^] | 55 | DEF_BENCH( return new BicubicBench(10.0f, 10.0f); ) |
| 56 | DEF_BENCH( return new BicubicBench(2.5f, 10.0f); ) |
| 57 | DEF_BENCH( return new BicubicBench(10.0f, 2.5f); ) |
| 58 | DEF_BENCH( return new BicubicBench(2.5f, 2.5f); ) |