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

Side by Side Diff: gm/blurrect.cpp

Issue 134533006: merge multiple blurrect GMs into one GM and add scaling (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | « no previous file | no next file » | 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 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 path.addRect(rect); 50 path.addRect(rect);
51 path.setFillType(SkPath::kEvenOdd_FillType); 51 path.setFillType(SkPath::kEvenOdd_FillType);
52 52
53 canvas->drawPath(path, p); 53 canvas->drawPath(path, p);
54 } 54 }
55 55
56 #include "SkGradientShader.h" 56 #include "SkGradientShader.h"
57 57
58 typedef void (*PaintProc)(SkPaint*, SkScalar width); 58 typedef void (*PaintProc)(SkPaint*, SkScalar width);
59 59
60 static const char* gBlurStyle2Name[] = {
61 "normal",
62 "solid",
63 "outer",
64 "inner"
65 };
66
67 class BlurRectGM : public skiagm::GM { 60 class BlurRectGM : public skiagm::GM {
68 SkAutoTUnref<SkMaskFilter> fMaskFilter; 61 SkAutoTUnref<SkMaskFilter> fMaskFilters[SkBlurMaskFilter::kBlurStyleCount] ;
69 SkString fName; 62 SkString fName;
70 PaintProc fPProc;
71 SkAlpha fAlpha; 63 SkAlpha fAlpha;
72 public: 64 public:
73 BlurRectGM(const char name[], PaintProc pproc, U8CPU alpha, 65 BlurRectGM(const char name[], U8CPU alpha)
74 SkBlurMaskFilter::BlurStyle bs) 66 : fName(name)
75 : fMaskFilter(SkBlurMaskFilter::Create(bs, 67 , fAlpha(SkToU8(alpha)) {
76 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(STRO KE_WIDTH/2)),
77 SkBlurMaskFilter::kHighQuality_BlurFlag))
78 , fName(name)
79 , fPProc(pproc)
80 , fAlpha(SkToU8(alpha)) {
81 fName.appendf("_%s", gBlurStyle2Name[bs]);
82 } 68 }
83 69
84 protected: 70 protected:
71 virtual void onOnceBeforeDraw() SK_OVERRIDE {
72 for (int i = 0; i < SkBlurMaskFilter::kBlurStyleCount; ++i) {
73 fMaskFilters[i].reset(SkBlurMaskFilter::Create((SkBlurMaskFilter::Bl urStyle) i,
74 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar (STROKE_WIDTH/2)),
75 SkBlurMaskFilter::kHighQuality_BlurFlag));
76 }
77 }
78
85 virtual SkString onShortName() { 79 virtual SkString onShortName() {
86 return fName; 80 return fName;
87 } 81 }
88 82
89 virtual SkISize onISize() { 83 virtual SkISize onISize() {
90 return SkISize::Make(640, 480); 84 return SkISize::Make(440, 820);
91 } 85 }
92 86
93 virtual void onDraw(SkCanvas* canvas) { 87 virtual void onDraw(SkCanvas* canvas) {
94 canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2); 88 canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2);
95 89
96 SkRect r = { 0, 0, 250, 120 }; 90 SkRect r = { 0, 0, 100, 50 };
91 SkScalar scales[] = { SK_Scalar1, 0.6f };
97 92
98 SkPaint paint; 93 for (size_t s = 0; s < SK_ARRAY_COUNT(scales); ++s) {
99 paint.setMaskFilter(fMaskFilter); 94 canvas->save();
100 if (fPProc) { 95 for (size_t f = 0; f < SK_ARRAY_COUNT(fMaskFilters); ++f) {
101 fPProc(&paint, r.width()); 96 SkPaint paint;
97 paint.setMaskFilter(fMaskFilters[f]);
98 paint.setAlpha(fAlpha);
99
100 static const Proc procs[] = {
101 fill_rect, draw_donut, draw_donut_skewed
102 };
103
104 canvas->save();
105 canvas->scale(scales[s], scales[s]);
106 this->drawProcs(canvas, r, paint, false, procs, SK_ARRAY_COUNT(p rocs));
107 canvas->translate(r.width() * 4/3, 0);
108 this->drawProcs(canvas, r, paint, true, procs, SK_ARRAY_COUNT(pr ocs));
109 canvas->restore();
110
111 canvas->translate(0, SK_ARRAY_COUNT(procs) * r.height() * 4/3 * scales[s]);
112 }
113 canvas->restore();
114 canvas->translate(2 * r.width() * 4/3 * scales[s], 0);
102 } 115 }
103 paint.setAlpha(fAlpha);
104
105 static const Proc procs[] = {
106 fill_rect, draw_donut, draw_donut_skewed
107 };
108
109 this->drawProcs(canvas, r, paint, false, procs, SK_ARRAY_COUNT(procs));
110 canvas->translate(r.width() * 4/3, 0);
111 this->drawProcs(canvas, r, paint, true, procs, SK_ARRAY_COUNT(procs));
112 } 116 }
113 117
114 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } 118 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; }
115 119
116 private: 120 private:
117 void drawProcs(SkCanvas* canvas, const SkRect& r, const SkPaint& paint, 121 void drawProcs(SkCanvas* canvas, const SkRect& r, const SkPaint& paint,
118 bool doClip, const Proc procs[], size_t procsCount) { 122 bool doClip, const Proc procs[], size_t procsCount) {
119 SkAutoCanvasRestore acr(canvas, true); 123 SkAutoCanvasRestore acr(canvas, true);
120 for (size_t i = 0; i < procsCount; ++i) { 124 for (size_t i = 0; i < procsCount; ++i) {
121 if (doClip) { 125 if (doClip) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 virtual SkBlurMask::Quality getQuality() { 301 virtual SkBlurMask::Quality getQuality() {
298 return SkBlurMask::kHigh_Quality; 302 return SkBlurMask::kHigh_Quality;
299 } 303 }
300 private: 304 private:
301 typedef BlurRectCompareGM INHERITED; 305 typedef BlurRectCompareGM INHERITED;
302 }; 306 };
303 307
304 308
305 ////////////////////////////////////////////////////////////////////////////// 309 //////////////////////////////////////////////////////////////////////////////
306 310
307 DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kNormal_B lurStyle);) 311 DEF_GM(return new BlurRectGM("blurrects", 0xFF);)
308 DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kSolid_Bl urStyle);)
309 DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kOuter_Bl urStyle);)
310 DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kInner_Bl urStyle);)
311 312
312 static const SkScalar kBig = 20; 313 static const SkScalar kBig = 20;
313 static const SkScalar kSmall = 2; 314 static const SkScalar kSmall = 2;
314 315
315 // regular size rects, blurs should be small enough not to completely overlap. 316 // regular size rects, blurs should be small enough not to completely overlap.
316 317
317 DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_normal_fast", 25, 100, kSma ll, SkBlurMask::kNormal_Style);) 318 DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_normal_fast", 25, 100, kSma ll, SkBlurMask::kNormal_Style);)
318 DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_normal_fast", 25, 100, kBig , SkBlurMask::kNormal_Style);) 319 DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_normal_fast", 25, 100, kBig , SkBlurMask::kNormal_Style);)
319 DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_normal_slow", 25, 100, kSma ll, SkBlurMask::kNormal_Style);) 320 DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_normal_slow", 25, 100, kSma ll, SkBlurMask::kNormal_Style);)
320 DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_normal_slow", 25, 100, kBig , SkBlurMask::kNormal_Style);) 321 DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_normal_slow", 25, 100, kBig , SkBlurMask::kNormal_Style);)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_11_simple", 25, 100, 11 );) 376 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_11_simple", 25, 100, 11 );)
376 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_12_simple", 25, 100, 12 );) 377 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_12_simple", 25, 100, 12 );)
377 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_13_simple", 25, 100, 13 );) 378 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_13_simple", 25, 100, 13 );)
378 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_14_simple", 25, 100, 14 );) 379 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_14_simple", 25, 100, 14 );)
379 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_15_simple", 25, 100, 15 );) 380 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_15_simple", 25, 100, 15 );)
380 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_16_simple", 25, 100, 16 );) 381 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_16_simple", 25, 100, 16 );)
381 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_17_simple", 25, 100, 17 );) 382 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_17_simple", 25, 100, 17 );)
382 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_18_simple", 25, 100, 18 );) 383 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_18_simple", 25, 100, 18 );)
383 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_19_simple", 25, 100, 19 );) 384 DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_19_simple", 25, 100, 19 );)
384 #endif 385 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698