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