Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: bench/MatrixConvolutionBench.cpp

Issue 1869833002: Update MatrixConvolutionImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | fuzz/FilterFuzz.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "Benchmark.h" 7 #include "Benchmark.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkMatrixConvolutionImageFilter.h" 9 #include "SkMatrixConvolutionImageFilter.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkRandom.h" 11 #include "SkRandom.h"
12 #include "SkString.h" 12 #include "SkString.h"
13 13
14 class MatrixConvolutionBench : public Benchmark { 14 class MatrixConvolutionBench : public Benchmark {
15 public: 15 public:
16 MatrixConvolutionBench(SkMatrixConvolutionImageFilter::TileMode tileMode, bo ol convolveAlpha) 16 MatrixConvolutionBench(SkMatrixConvolutionImageFilter::TileMode tileMode, bo ol convolveAlpha)
17 : fName("matrixconvolution") { 17 : fName("matrixconvolution") {
18 SkISize kernelSize = SkISize::Make(3, 3); 18 SkISize kernelSize = SkISize::Make(3, 3);
19 SkScalar kernel[9] = { 19 SkScalar kernel[9] = {
20 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 20 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
21 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 21 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
22 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 22 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
23 }; 23 };
24 SkScalar gain = 0.3f, bias = SkIntToScalar(100); 24 SkScalar gain = 0.3f, bias = SkIntToScalar(100);
25 SkIPoint kernelOffset = SkIPoint::Make(1, 1); 25 SkIPoint kernelOffset = SkIPoint::Make(1, 1);
26 fFilter = SkMatrixConvolutionImageFilter::Create(kernelSize, kernel, gai n, bias, kernelOffset, tileMode, convolveAlpha); 26 fFilter = SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, gain, bias,
27 } 27 kernelOffset, tileMode, c onvolveAlpha,
28 28 nullptr);
29 ~MatrixConvolutionBench() {
30 fFilter->unref();
31 } 29 }
32 30
33 protected: 31 protected:
34 virtual const char* onGetName() { 32 virtual const char* onGetName() {
35 return fName.c_str(); 33 return fName.c_str();
36 } 34 }
37 35
38 virtual void onDraw(int loops, SkCanvas* canvas) { 36 virtual void onDraw(int loops, SkCanvas* canvas) {
39 SkPaint paint; 37 SkPaint paint;
40 this->setupPaint(&paint); 38 this->setupPaint(&paint);
41 paint.setAntiAlias(true); 39 paint.setAntiAlias(true);
42 SkRandom rand; 40 SkRandom rand;
43 for (int i = 0; i < loops; i++) { 41 for (int i = 0; i < loops; i++) {
44 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, 42 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
45 rand.nextUScalar1() * 400); 43 rand.nextUScalar1() * 400);
46 paint.setImageFilter(fFilter); 44 paint.setImageFilter(fFilter);
47 canvas->drawOval(r, paint); 45 canvas->drawOval(r, paint);
48 } 46 }
49 } 47 }
50 48
51 private: 49 private:
50 sk_sp<SkImageFilter> fFilter;
51 SkString fName;
52
52 typedef Benchmark INHERITED; 53 typedef Benchmark INHERITED;
53 SkImageFilter* fFilter;
54 SkString fName;
55 }; 54 };
56 55
57 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kCl amp_TileMode, true); ) 56 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kCl amp_TileMode, true); )
58 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kRe peat_TileMode, true); ) 57 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kRe peat_TileMode, true); )
59 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kCl ampToBlack_TileMode, true); ) 58 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kCl ampToBlack_TileMode, true); )
60 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kCl ampToBlack_TileMode, false); ) 59 DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kCl ampToBlack_TileMode, false); )
OLDNEW
« no previous file with comments | « no previous file | fuzz/FilterFuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698