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

Side by Side Diff: bench/BlurRectBench.cpp

Issue 23701006: Push sigma-based blur interface into our GMs/benches/tests/samplecode (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: cleaned up Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « bench/BlurBench.cpp ('k') | bench/RectoriBench.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 2013 Google Inc. 2 * Copyright 2013 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 "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkRandom.h" 11 #include "SkRandom.h"
12 #include "SkShader.h" 12 #include "SkShader.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 #include "SkBlurMask.h" 14 #include "SkBlurMask.h"
15 15
16 #define SMALL SkIntToScalar(2) 16 #define SMALL SkIntToScalar(2)
17 #define REAL SkFloatToScalar(1.5f) 17 #define REAL SkFloatToScalar(1.5f)
18 static const SkScalar kMedium = SkIntToScalar(5);
18 #define BIG SkIntToScalar(10) 19 #define BIG SkIntToScalar(10)
20 static const SkScalar kMedBig = SkIntToScalar(20);
19 #define REALBIG SkFloatToScalar(30.5f) 21 #define REALBIG SkFloatToScalar(30.5f)
20 22
21 class BlurRectBench: public SkBenchmark { 23 class BlurRectBench: public SkBenchmark {
22 int fLoopCount; 24 int fLoopCount;
23 SkScalar fRadius; 25 SkScalar fRadius;
24 SkString fName; 26 SkString fName;
25 27
26 public: 28 public:
27 BlurRectBench(void *param, SkScalar rad) : INHERITED(param) { 29 BlurRectBench(void *param, SkScalar rad) : INHERITED(param) {
28 fRadius = rad; 30 fRadius = rad;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 public: 78 public:
77 BlurRectDirectBench(void *param, SkScalar rad) : INHERITED(param, rad) { 79 BlurRectDirectBench(void *param, SkScalar rad) : INHERITED(param, rad) {
78 SkString name; 80 SkString name;
79 81
80 if (SkScalarFraction(rad) != 0) { 82 if (SkScalarFraction(rad) != 0) {
81 name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad)); 83 name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad));
82 } else { 84 } else {
83 name.printf("blurrect_direct_%d", SkScalarRoundToInt(rad)); 85 name.printf("blurrect_direct_%d", SkScalarRoundToInt(rad));
84 } 86 }
85 87
86 setName(name); 88 this->setName(name);
87 } 89 }
88 protected: 90 protected:
89 virtual void makeBlurryRect(const SkRect& r) SK_OVERRIDE { 91 virtual void makeBlurryRect(const SkRect& r) SK_OVERRIDE {
90 SkMask mask; 92 SkMask mask;
91 SkBlurMask::BlurRect(&mask, r, this->radius(), SkBlurMask::kNormal_Style ); 93 SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()),
94 &mask, r, SkBlurMask::kNormal_Style);
92 SkMask::FreeImage(mask.fImage); 95 SkMask::FreeImage(mask.fImage);
93 } 96 }
94 private: 97 private:
95 typedef BlurRectBench INHERITED; 98 typedef BlurRectBench INHERITED;
96 }; 99 };
97 100
98 class BlurRectSeparableBench: public BlurRectBench { 101 class BlurRectSeparableBench: public BlurRectBench {
99 102
100 public: 103 public:
101 BlurRectSeparableBench(void *param, SkScalar rad) : INHERITED(param, rad) { 104 BlurRectSeparableBench(void *param, SkScalar rad) : INHERITED(param, rad) {
(...skipping 18 matching lines...) Expand all
120 123
121 SkMask fSrcMask; 124 SkMask fSrcMask;
122 private: 125 private:
123 typedef BlurRectBench INHERITED; 126 typedef BlurRectBench INHERITED;
124 }; 127 };
125 128
126 class BlurRectBoxFilterBench: public BlurRectSeparableBench { 129 class BlurRectBoxFilterBench: public BlurRectSeparableBench {
127 public: 130 public:
128 BlurRectBoxFilterBench(void *param, SkScalar rad) : INHERITED(param, rad) { 131 BlurRectBoxFilterBench(void *param, SkScalar rad) : INHERITED(param, rad) {
129 SkString name; 132 SkString name;
133
130 if (SkScalarFraction(rad) != 0) { 134 if (SkScalarFraction(rad) != 0) {
131 name.printf("blurrect_boxfilter_%.2f", SkScalarToFloat(rad)); 135 name.printf("blurrect_boxfilter_%.2f", SkScalarToFloat(rad));
132 } else { 136 } else {
133 name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad)); 137 name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad));
134 } 138 }
135 setName(name); 139
140 this->setName(name);
136 } 141 }
137 142
138 protected: 143 protected:
139 144
140 virtual void makeBlurryRect(const SkRect&) SK_OVERRIDE { 145 virtual void makeBlurryRect(const SkRect&) SK_OVERRIDE {
141 SkMask mask; 146 SkMask mask;
142 mask.fImage = NULL; 147 mask.fImage = NULL;
143 SkBlurMask::Blur(&mask, fSrcMask, this->radius(), 148 SkBlurMask::BoxBlur(&mask, fSrcMask, SkBlurMask::ConvertRadiusToSigma(th is->radius()),
144 SkBlurMask::kNormal_Style, 149 SkBlurMask::kNormal_Style,
145 SkBlurMask::kHigh_Quality); 150 SkBlurMask::kHigh_Quality);
146 SkMask::FreeImage(mask.fImage); 151 SkMask::FreeImage(mask.fImage);
147 } 152 }
148 private: 153 private:
149 typedef BlurRectSeparableBench INHERITED; 154 typedef BlurRectSeparableBench INHERITED;
150 }; 155 };
151 156
152 class BlurRectGaussianBench: public BlurRectSeparableBench { 157 class BlurRectGaussianBench: public BlurRectSeparableBench {
153 public: 158 public:
154 BlurRectGaussianBench(void *param, SkScalar rad) : INHERITED(param, rad) { 159 BlurRectGaussianBench(void *param, SkScalar rad) : INHERITED(param, rad) {
155 SkString name; 160 SkString name;
161
156 if (SkScalarFraction(rad) != 0) { 162 if (SkScalarFraction(rad) != 0) {
157 name.printf("blurrect_gaussian_%.2f", SkScalarToFloat(rad)); 163 name.printf("blurrect_gaussian_%.2f", SkScalarToFloat(rad));
158 } else { 164 } else {
159 name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad)); 165 name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad));
160 } 166 }
161 setName(name); 167
168 this->setName(name);
162 } 169 }
163 170
164 protected: 171 protected:
165 172
166 virtual void makeBlurryRect(const SkRect&) SK_OVERRIDE { 173 virtual void makeBlurryRect(const SkRect&) SK_OVERRIDE {
167 SkMask mask; 174 SkMask mask;
168 mask.fImage = NULL; 175 mask.fImage = NULL;
169 SkBlurMask::BlurGroundTruth(&mask, fSrcMask, this->radius(), 176 SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radiu s()),
170 SkBlurMask::kNormal_Style); 177 &mask, fSrcMask, SkBlurMask::kNormal_Style);
171 SkMask::FreeImage(mask.fImage); 178 SkMask::FreeImage(mask.fImage);
172 } 179 }
173 private: 180 private:
174 typedef BlurRectSeparableBench INHERITED; 181 typedef BlurRectSeparableBench INHERITED;
175 }; 182 };
176 183
177 DEF_BENCH(return new BlurRectBoxFilterBench(p, SMALL);) 184 DEF_BENCH(return new BlurRectBoxFilterBench(p, SMALL);)
178 DEF_BENCH(return new BlurRectBoxFilterBench(p, BIG);) 185 DEF_BENCH(return new BlurRectBoxFilterBench(p, BIG);)
179 DEF_BENCH(return new BlurRectBoxFilterBench(p, REALBIG);) 186 DEF_BENCH(return new BlurRectBoxFilterBench(p, REALBIG);)
180 DEF_BENCH(return new BlurRectBoxFilterBench(p, REAL);) 187 DEF_BENCH(return new BlurRectBoxFilterBench(p, REAL);)
181 DEF_BENCH(return new BlurRectGaussianBench(p, SMALL);) 188 DEF_BENCH(return new BlurRectGaussianBench(p, SMALL);)
182 DEF_BENCH(return new BlurRectGaussianBench(p, BIG);) 189 DEF_BENCH(return new BlurRectGaussianBench(p, BIG);)
183 DEF_BENCH(return new BlurRectGaussianBench(p, REALBIG);) 190 DEF_BENCH(return new BlurRectGaussianBench(p, REALBIG);)
184 DEF_BENCH(return new BlurRectGaussianBench(p, REAL);) 191 DEF_BENCH(return new BlurRectGaussianBench(p, REAL);)
185 DEF_BENCH(return new BlurRectDirectBench(p, SMALL);) 192 DEF_BENCH(return new BlurRectDirectBench(p, SMALL);)
186 DEF_BENCH(return new BlurRectDirectBench(p, BIG);) 193 DEF_BENCH(return new BlurRectDirectBench(p, BIG);)
187 DEF_BENCH(return new BlurRectDirectBench(p, REALBIG);) 194 DEF_BENCH(return new BlurRectDirectBench(p, REALBIG);)
188 DEF_BENCH(return new BlurRectDirectBench(p, REAL);) 195 DEF_BENCH(return new BlurRectDirectBench(p, REAL);)
189 196
190 DEF_BENCH(return new BlurRectDirectBench(p, SkIntToScalar(5));) 197 DEF_BENCH(return new BlurRectDirectBench(p, kMedium);)
191 DEF_BENCH(return new BlurRectDirectBench(p, SkIntToScalar(20));) 198 DEF_BENCH(return new BlurRectDirectBench(p, kMedBig);)
192 199
193 DEF_BENCH(return new BlurRectBoxFilterBench(p, SkIntToScalar(5));) 200 DEF_BENCH(return new BlurRectBoxFilterBench(p, kMedium);)
194 DEF_BENCH(return new BlurRectBoxFilterBench(p, SkIntToScalar(20));) 201 DEF_BENCH(return new BlurRectBoxFilterBench(p, kMedBig);)
195 202
196 #if 0 203 #if 0
197 // disable Gaussian benchmarks; the algorithm works well enough 204 // disable Gaussian benchmarks; the algorithm works well enough
198 // and serves as a baseline for ground truth, but it's too slow 205 // and serves as a baseline for ground truth, but it's too slow
199 // to use in production for non-trivial radii, so no real point 206 // to use in production for non-trivial radii, so no real point
200 // in having the bots benchmark it all the time. 207 // in having the bots benchmark it all the time.
201 208
202 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(1));) 209 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(1));)
203 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(2));) 210 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(2));)
204 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(3));) 211 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(3));)
205 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(4));) 212 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(4));)
206 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(5));) 213 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(5));)
207 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(6));) 214 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(6));)
208 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(7));) 215 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(7));)
209 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(8));) 216 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(8));)
210 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(9));) 217 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(9));)
211 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(10));) 218 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(10));)
212 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(11));) 219 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(11));)
213 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(12));) 220 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(12));)
214 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(13));) 221 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(13));)
215 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(14));) 222 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(14));)
216 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(15));) 223 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(15));)
217 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(16));) 224 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(16));)
218 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(17));) 225 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(17));)
219 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(18));) 226 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(18));)
220 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(19));) 227 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(19));)
221 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(20));) 228 DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(20));)
222 #endif 229 #endif
OLDNEW
« no previous file with comments | « bench/BlurBench.cpp ('k') | bench/RectoriBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698