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

Side by Side Diff: bench/ImageFilterCollapse.cpp

Issue 1822623002: switch colorfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 9 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 | « bench/ColorFilterBench.cpp ('k') | gm/blurredclippedcircle.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 2014 Google Inc. 2 * Copyright 2014 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 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 10 matching lines...) Expand all
21 // the passes are collapsed in one. 21 // the passes are collapsed in one.
22 22
23 class BaseImageFilterCollapseBench : public Benchmark { 23 class BaseImageFilterCollapseBench : public Benchmark {
24 public: 24 public:
25 BaseImageFilterCollapseBench(): fImageFilter(nullptr) {} 25 BaseImageFilterCollapseBench(): fImageFilter(nullptr) {}
26 ~BaseImageFilterCollapseBench() { 26 ~BaseImageFilterCollapseBench() {
27 SkSafeUnref(fImageFilter); 27 SkSafeUnref(fImageFilter);
28 } 28 }
29 29
30 protected: 30 protected:
31 void doPreDraw(SkColorFilter* colorFilters[], int nFilters) { 31 void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) {
32 // Create a chain of ImageFilters from colorFilters 32 // Create a chain of ImageFilters from colorFilters
33 fImageFilter = nullptr; 33 fImageFilter = nullptr;
34 for(int i = nFilters; i --> 0;) { 34 for(int i = nFilters; i --> 0;) {
35 SkAutoTUnref<SkImageFilter> filter( 35 SkAutoTUnref<SkImageFilter> filter(
36 SkColorFilterImageFilter::Create(colorFilters[i], fImage Filter, nullptr) 36 SkColorFilterImageFilter::Create(colorFilters[i].get(), fIma geFilter, nullptr)
37 ); 37 );
38 SkRefCnt_SafeAssign(fImageFilter, filter.get()); 38 SkRefCnt_SafeAssign(fImageFilter, filter.get());
39 } 39 }
40 } 40 }
41 41
42 void onDraw(int loops, SkCanvas* canvas) override { 42 void onDraw(int loops, SkCanvas* canvas) override {
43 makeBitmap(); 43 makeBitmap();
44 44
45 for(int i = 0; i < loops; i++) { 45 for(int i = 0; i < loops; i++) {
46 SkPaint paint; 46 SkPaint paint;
(...skipping 19 matching lines...) Expand all
66 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN, 66 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN,
67 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE 67 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
68 }; 68 };
69 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_AR RAY_COUNT(colors), 69 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_AR RAY_COUNT(colors),
70 SkShader::kClamp_TileMode)) ; 70 SkShader::kClamp_TileMode)) ;
71 canvas.drawPaint(paint); 71 canvas.drawPaint(paint);
72 } 72 }
73 }; 73 };
74 74
75 class TableCollapseBench: public BaseImageFilterCollapseBench { 75 class TableCollapseBench: public BaseImageFilterCollapseBench {
76 public:
77 virtual ~TableCollapseBench() {}
78
79 protected: 76 protected:
80 virtual const char* onGetName() override { 77 const char* onGetName() override {
81 return "image_filter_collapse_table"; 78 return "image_filter_collapse_table";
82 } 79 }
83 80
84 virtual void onDelayedSetup() override { 81 void onDelayedSetup() override {
85 for (int i = 0; i < 256; ++i) { 82 for (int i = 0; i < 256; ++i) {
86 int n = i >> 5; 83 int n = i >> 5;
87 table1[i] = (n << 5) | (n << 2) | (n >> 1); 84 table1[i] = (n << 5) | (n << 2) | (n >> 1);
88 85
89 table2[i] = i * i / 255; 86 table2[i] = i * i / 255;
90 87
91 float fi = i / 255.0f; 88 float fi = i / 255.0f;
92 table3[i] = static_cast<uint8_t>(sqrtf(fi) * 255); 89 table3[i] = static_cast<uint8_t>(sqrtf(fi) * 255);
93 } 90 }
94 91
95 SkColorFilter* colorFilters[] = { 92 sk_sp<SkColorFilter> colorFilters[] = {
96 SkTableColorFilter::Create(table1), 93 SkTableColorFilter::Make(table1),
97 SkTableColorFilter::Create(table2), 94 SkTableColorFilter::Make(table2),
98 SkTableColorFilter::Create(table3), 95 SkTableColorFilter::Make(table3),
99 }; 96 };
100 97
101 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); 98 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
102
103 for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) {
104 colorFilters[i]->unref();
105 }
106 } 99 }
107 100
108 private: 101 private:
109 uint8_t table1[256], table2[256], table3[256]; 102 uint8_t table1[256], table2[256], table3[256];
110 }; 103 };
111 104
112 static SkColorFilter* make_brightness(float amount) { 105 static sk_sp<SkColorFilter> make_brightness(float amount) {
113 SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255)); 106 SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255));
114 SkScalar matrix[20] = { 1, 0, 0, 0, amount255, 107 SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
115 0, 1, 0, 0, amount255, 108 0, 1, 0, 0, amount255,
116 0, 0, 1, 0, amount255, 109 0, 0, 1, 0, amount255,
117 0, 0, 0, 1, 0 }; 110 0, 0, 0, 1, 0 };
118 return SkColorMatrixFilter::Create(matrix); 111 return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
119 } 112 }
120 113
121 static SkColorFilter* make_grayscale() { 114 static sk_sp<SkColorFilter> make_grayscale() {
122 SkScalar matrix[20]; 115 SkScalar matrix[20];
123 memset(matrix, 0, 20 * sizeof(SkScalar)); 116 memset(matrix, 0, 20 * sizeof(SkScalar));
124 matrix[0] = matrix[5] = matrix[10] = 0.2126f; 117 matrix[0] = matrix[5] = matrix[10] = 0.2126f;
125 matrix[1] = matrix[6] = matrix[11] = 0.7152f; 118 matrix[1] = matrix[6] = matrix[11] = 0.7152f;
126 matrix[2] = matrix[7] = matrix[12] = 0.0722f; 119 matrix[2] = matrix[7] = matrix[12] = 0.0722f;
127 matrix[18] = 1.0f; 120 matrix[18] = 1.0f;
128 return SkColorMatrixFilter::Create(matrix); 121 return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
129 } 122 }
130 123
131 class MatrixCollapseBench: public BaseImageFilterCollapseBench { 124 class MatrixCollapseBench: public BaseImageFilterCollapseBench {
132 public:
133 virtual ~MatrixCollapseBench() {}
134
135 protected: 125 protected:
136 virtual const char* onGetName() override { 126 const char* onGetName() override {
137 return "image_filter_collapse_matrix"; 127 return "image_filter_collapse_matrix";
138 } 128 }
139 129
140 virtual void onDelayedSetup() override { 130 void onDelayedSetup() override {
141 SkColorFilter* colorFilters[] = { 131 sk_sp<SkColorFilter> colorFilters[] = {
142 make_brightness(0.1f), 132 make_brightness(0.1f),
143 make_grayscale(), 133 make_grayscale(),
144 make_brightness(-0.1f), 134 make_brightness(-0.1f),
145 }; 135 };
146 136
147 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); 137 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
148
149 for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) {
150 colorFilters[i]->unref();
151 }
152 } 138 }
153 }; 139 };
154 140
155 DEF_BENCH(return new TableCollapseBench;) 141 DEF_BENCH(return new TableCollapseBench;)
156 DEF_BENCH(return new MatrixCollapseBench;) 142 DEF_BENCH(return new MatrixCollapseBench;)
OLDNEW
« no previous file with comments | « bench/ColorFilterBench.cpp ('k') | gm/blurredclippedcircle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698