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

Side by Side Diff: bench/GradientBench.cpp

Issue 321253002: Simple GPU based dithering (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sync to head Created 6 years, 6 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 | expectations/gm/ignored-tests.txt » ('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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
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 16 matching lines...) Expand all
27 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 27 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
28 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 28 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
29 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 29 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
30 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 30 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
31 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 31 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1 0 lines, 50 colors 34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1 0 lines, 50 colors
35 }; 35 };
36 36
37 static const SkColor gShallowColors[] = { 0xFF555555, 0xFF444444 };
38
37 // We have several special-cases depending on the number (and spacing) of colors , so 39 // We have several special-cases depending on the number (and spacing) of colors , so
38 // try to exercise those here. 40 // try to exercise those here.
39 static const GradData gGradData[] = { 41 static const GradData gGradData[] = {
40 { 2, gColors, NULL, "" }, 42 { 2, gColors, NULL, "" },
41 { 50, gColors, NULL, "_hicolor" }, // many color gradient 43 { 50, gColors, NULL, "_hicolor" }, // many color gradient
42 { 3, gColors, NULL, "_3color" }, 44 { 3, gColors, NULL, "_3color" },
45 { 2, gShallowColors, NULL, "_shallow" },
43 }; 46 };
44 47
45 /// Ignores scale 48 /// Ignores scale
46 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, 49 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
47 SkShader::TileMode tm, float scale) { 50 SkShader::TileMode tm, float scale) {
48 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm); 51 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm);
49 } 52 }
50 53
51 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, 54 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
52 SkShader::TileMode tm, float scale) { 55 SkShader::TileMode tm, float scale) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 SkDEBUGFAIL("unknown geometry type"); 196 SkDEBUGFAIL("unknown geometry type");
194 return "error"; 197 return "error";
195 } 198 }
196 } 199 }
197 200
198 /////////////////////////////////////////////////////////////////////////////// 201 ///////////////////////////////////////////////////////////////////////////////
199 202
200 class GradientBench : public Benchmark { 203 class GradientBench : public Benchmark {
201 SkString fName; 204 SkString fName;
202 SkShader* fShader; 205 SkShader* fShader;
206 bool fDither;
203 enum { 207 enum {
204 W = 400, 208 W = 400,
205 H = 400, 209 H = 400,
206 kRepeat = 15, 210 kRepeat = 15,
207 }; 211 };
208 public: 212 public:
213 SkShader* makeShader(GradType gradType, GradData data, SkShader::TileMode tm , float scale) {
214 const SkPoint pts[2] = {
215 { 0, 0 },
216 { SkIntToScalar(W), SkIntToScalar(H) }
217 };
218
219 return gGrads[gradType].fMaker(pts, data, tm, scale);
220 }
221
209 GradientBench(GradType gradType, 222 GradientBench(GradType gradType,
210 GradData data = gGradData[0], 223 GradData data = gGradData[0],
211 SkShader::TileMode tm = SkShader::kClamp_TileMode, 224 SkShader::TileMode tm = SkShader::kClamp_TileMode,
212 GeomType geomType = kRect_GeomType, 225 GeomType geomType = kRect_GeomType,
213 float scale = 1.0f) { 226 float scale = 1.0f) {
214 fName.printf("gradient_%s_%s", gGrads[gradType].fName, 227 fName.printf("gradient_%s_%s", gGrads[gradType].fName,
215 tilemodename(tm)); 228 tilemodename(tm));
216 if (geomType != kRect_GeomType) { 229 if (geomType != kRect_GeomType) {
217 fName.append("_"); 230 fName.append("_");
218 fName.append(geomtypename(geomType)); 231 fName.append(geomtypename(geomType));
219 } 232 }
220 233
221 if (scale != 1.f) { 234 if (scale != 1.f) {
222 fName.appendf("_scale_%g", scale); 235 fName.appendf("_scale_%g", scale);
223 } 236 }
224 237
225 fName.append(data.fName); 238 fName.append(data.fName);
226 239
227 const SkPoint pts[2] = { 240 fDither = false;
228 { 0, 0 }, 241 fShader = this->makeShader(gradType, data, tm, scale);
229 { SkIntToScalar(W), SkIntToScalar(H) } 242 fGeomType = geomType;
230 }; 243 }
231 244
232 fShader = gGrads[gradType].fMaker(pts, data, tm, scale); 245 GradientBench(GradType gradType, GradData data, bool dither) {
233 fGeomType = geomType; 246 const char *tmname = tilemodename(SkShader::kClamp_TileMode);
247 fName.printf("gradient_%s_%s", gGrads[gradType].fName, tmname);
248 fName.append(data.fName);
249
250 fDither = dither;
251 if (dither) {
252 fName.appendf("_dither");
253 }
254
255 fShader = this->makeShader(gradType, data, SkShader::kClamp_TileMode, 1. 0f);
256 fGeomType = kRect_GeomType;
234 } 257 }
235 258
236 virtual ~GradientBench() { 259 virtual ~GradientBench() {
237 fShader->unref(); 260 fShader->unref();
238 } 261 }
239 262
240 protected: 263 protected:
241 virtual const char* onGetName() { 264 virtual const char* onGetName() {
242 return fName.c_str(); 265 return fName.c_str();
243 } 266 }
244 267
245 virtual void onDraw(const int loops, SkCanvas* canvas) { 268 virtual void onDraw(const int loops, SkCanvas* canvas) {
246 SkPaint paint; 269 SkPaint paint;
247 this->setupPaint(&paint); 270 this->setupPaint(&paint);
248 271
249 paint.setShader(fShader); 272 paint.setShader(fShader);
273 if (fDither) {
274 paint.setDither(true);
275 }
250 276
251 SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) }; 277 SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
252 for (int i = 0; i < loops * kRepeat; i++) { 278 for (int i = 0; i < loops * kRepeat; i++) {
253 switch (fGeomType) { 279 switch (fGeomType) {
254 case kRect_GeomType: 280 case kRect_GeomType:
255 canvas->drawRect(r, paint); 281 canvas->drawRect(r, paint);
256 break; 282 break;
257 case kOval_GeomType: 283 case kOval_GeomType:
258 canvas->drawOval(r, paint); 284 canvas->drawOval(r, paint);
259 break; 285 break;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 DEF_BENCH( return new GradientBench(kConicalZero_GradType); ) 323 DEF_BENCH( return new GradientBench(kConicalZero_GradType); )
298 DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[1]); ) 324 DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[1]); )
299 DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[2]); ) 325 DEF_BENCH( return new GradientBench(kConicalZero_GradType, gGradData[2]); )
300 DEF_BENCH( return new GradientBench(kConicalOut_GradType); ) 326 DEF_BENCH( return new GradientBench(kConicalOut_GradType); )
301 DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[1]); ) 327 DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[1]); )
302 DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[2]); ) 328 DEF_BENCH( return new GradientBench(kConicalOut_GradType, gGradData[2]); )
303 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType); ) 329 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType); )
304 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[1]); ) 330 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[1]); )
305 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[2]); ) 331 DEF_BENCH( return new GradientBench(kConicalOutZero_GradType, gGradData[2]); )
306 332
333 // Dithering
334 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[3], true); )
335 DEF_BENCH( return new GradientBench(kLinear_GradType, gGradData[3], false); )
336 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[3], true); )
337 DEF_BENCH( return new GradientBench(kRadial_GradType, gGradData[3], false); )
338 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[3], true); )
339 DEF_BENCH( return new GradientBench(kSweep_GradType, gGradData[3], false); )
340 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[3], true); )
341 DEF_BENCH( return new GradientBench(kConical_GradType, gGradData[3], false); )
342
307 /////////////////////////////////////////////////////////////////////////////// 343 ///////////////////////////////////////////////////////////////////////////////
308 344
309 class Gradient2Bench : public Benchmark { 345 class Gradient2Bench : public Benchmark {
310 SkString fName; 346 SkString fName;
311 bool fHasAlpha; 347 bool fHasAlpha;
312 348
313 public: 349 public:
314 Gradient2Bench(bool hasAlpha) { 350 Gradient2Bench(bool hasAlpha) {
315 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque"); 351 fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque");
316 fHasAlpha = hasAlpha; 352 fHasAlpha = hasAlpha;
(...skipping 28 matching lines...) Expand all
345 canvas->drawRect(r, paint); 381 canvas->drawRect(r, paint);
346 } 382 }
347 } 383 }
348 384
349 private: 385 private:
350 typedef Benchmark INHERITED; 386 typedef Benchmark INHERITED;
351 }; 387 };
352 388
353 DEF_BENCH( return new Gradient2Bench(false); ) 389 DEF_BENCH( return new Gradient2Bench(false); )
354 DEF_BENCH( return new Gradient2Bench(true); ) 390 DEF_BENCH( return new Gradient2Bench(true); )
OLDNEW
« no previous file with comments | « no previous file | expectations/gm/ignored-tests.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698