| senorblanco@chromium.org | 5faa2dc | 2012-09-18 20:32:34 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2012 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 | #include "SkBenchmark.h" | 
|  | 8 | #include "SkCanvas.h" | 
|  | 9 | #include "SkPaint.h" | 
|  | 10 | #include "SkRandom.h" | 
|  | 11 | #include "SkString.h" | 
|  | 12 | #include "SkMatrixConvolutionImageFilter.h" | 
|  | 13 |  | 
|  | 14 | class MatrixConvolutionBench : public SkBenchmark { | 
| senorblanco@chromium.org | 5faa2dc | 2012-09-18 20:32:34 +0000 | [diff] [blame] | 15 | public: | 
| senorblanco@chromium.org | 8640d50 | 2012-09-25 14:32:42 +0000 | [diff] [blame] | 16 | MatrixConvolutionBench(void* param, SkMatrixConvolutionImageFilter::TileMode tileMode, bool convolveAlpha) | 
| senorblanco@chromium.org | 5faa2dc | 2012-09-18 20:32:34 +0000 | [diff] [blame] | 17 | : INHERITED(param), fName("matrixconvolution") { | 
|  | 18 | SkISize kernelSize = SkISize::Make(3, 3); | 
|  | 19 | SkScalar kernel[9] = { | 
|  | 20 | SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 
|  | 21 | SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 
|  | 22 | SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 
|  | 23 | }; | 
|  | 24 | SkScalar gain = SkFloatToScalar(0.3f), bias = SkIntToScalar(100); | 
|  | 25 | SkIPoint target = SkIPoint::Make(1, 1); | 
| senorblanco@chromium.org | 8640d50 | 2012-09-25 14:32:42 +0000 | [diff] [blame] | 26 | fFilter = new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, target, tileMode, convolveAlpha); | 
| senorblanco@chromium.org | 5faa2dc | 2012-09-18 20:32:34 +0000 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
|  | 29 | ~MatrixConvolutionBench() { | 
|  | 30 | fFilter->unref(); | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | protected: | 
|  | 34 | virtual const char* onGetName() { | 
|  | 35 | return fName.c_str(); | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | virtual void onDraw(SkCanvas* canvas) { | 
|  | 39 | SkPaint paint; | 
|  | 40 | this->setupPaint(&paint); | 
|  | 41 | paint.setAntiAlias(true); | 
| commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame^] | 42 | SkRandom rand; | 
| senorblanco@chromium.org | 5faa2dc | 2012-09-18 20:32:34 +0000 | [diff] [blame] | 43 | for (int i = 0; i < SkBENCHLOOP(3); i++) { | 
|  | 44 | SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, | 
|  | 45 | rand.nextUScalar1() * 400); | 
|  | 46 | paint.setImageFilter(fFilter); | 
|  | 47 | canvas->drawOval(r, paint); | 
|  | 48 | } | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | private: | 
|  | 52 | typedef SkBenchmark INHERITED; | 
|  | 53 | SkMatrixConvolutionImageFilter* fFilter; | 
|  | 54 | SkString fName; | 
|  | 55 | }; | 
|  | 56 |  | 
| senorblanco@chromium.org | 8640d50 | 2012-09-25 14:32:42 +0000 | [diff] [blame] | 57 | static SkBenchmark* Fact00(void* p) { return new MatrixConvolutionBench(p, SkMatrixConvolutionImageFilter::kClamp_TileMode, true); } | 
|  | 58 | static SkBenchmark* Fact01(void* p) { return new MatrixConvolutionBench(p, SkMatrixConvolutionImageFilter::kRepeat_TileMode, true); } | 
|  | 59 | static SkBenchmark* Fact02(void* p) { return new MatrixConvolutionBench(p, SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, true); } | 
|  | 60 | static SkBenchmark* Fact03(void* p) { return new MatrixConvolutionBench(p, SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, false); } | 
| senorblanco@chromium.org | 5faa2dc | 2012-09-18 20:32:34 +0000 | [diff] [blame] | 61 |  | 
|  | 62 | static BenchRegistry gReg00(Fact00); | 
|  | 63 | static BenchRegistry gReg01(Fact01); | 
|  | 64 | static BenchRegistry gReg02(Fact02); | 
| senorblanco@chromium.org | 8640d50 | 2012-09-25 14:32:42 +0000 | [diff] [blame] | 65 | static BenchRegistry gReg03(Fact03); |