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

Side by Side Diff: gm/blurroundrect.cpp

Issue 812163002: modifying blur gms to test with shader too (Closed) Base URL: https://skia.googlesource.com/skia.git@vm-off-drawstate
Patch Set: fixing flags Created 6 years 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 | « gm/blurrect.cpp ('k') | 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 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 "gm.h" 8 #include "gm.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 canvas->drawRRect(fRRect, paint); 85 canvas->drawRRect(fRRect, paint);
86 } 86 }
87 87
88 private: 88 private:
89 SkString fName; 89 SkString fName;
90 SkRRect fRRect; 90 SkRRect fRRect;
91 91
92 typedef skiagm::GM INHERITED; 92 typedef skiagm::GM INHERITED;
93 }; 93 };
94 94
95 #include "SkGradientShader.h"
96 /*
97 * Spits out a dummy gradient to test blur with shader on paint
98 */
99 static SkShader* MakeRadial() {
100 SkPoint pts[2] = {
101 { 0, 0 },
102 { SkIntToScalar(100), SkIntToScalar(100) }
103 };
104 SkShader::TileMode tm = SkShader::kClamp_TileMode;
105 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, };
106 const SkScalar pos[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
107 SkMatrix scale;
108 scale.setScale(0.5f, 0.5f);
109 scale.postTranslate(5.f, 5.f);
110 SkPoint center0, center1;
111 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
112 SkScalarAve(pts[0].fY, pts[1].fY));
113 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
114 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
115 return SkGradientShader::CreateTwoPointRadial(center1, (pts[1].fX - pts[0].f X) / 7,
116 center0, (pts[1].fX - pts[0].f X) / 2,
117 colors, pos, SK_ARRAY_COUNT(co lors), tm,
118 0, &scale);
119 }
120
95 // Simpler blurred RR test cases where all the radii are the same. 121 // Simpler blurred RR test cases where all the radii are the same.
96 class SimpleBlurRoundRectGM : public skiagm::GM { 122 class SimpleBlurRoundRectGM : public skiagm::GM {
97 public: 123 public:
98 SimpleBlurRoundRectGM() 124 SimpleBlurRoundRectGM()
99 : fName("simpleblurroundrect") { 125 : fName("simpleblurroundrect") {
100 } 126 }
101 127
102 protected: 128 protected:
129 virtual uint32_t onGetFlags() const SK_OVERRIDE {
130 return kSkipTiled_Flag;
131 }
132
103 virtual SkString onShortName() SK_OVERRIDE { 133 virtual SkString onShortName() SK_OVERRIDE {
104 return fName; 134 return fName;
105 } 135 }
106 136
107 virtual SkISize onISize() SK_OVERRIDE { 137 virtual SkISize onISize() SK_OVERRIDE {
108 return SkISize::Make(950, 950); 138 return SkISize::Make(1000, 500);
109 } 139 }
110 140
111 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 141 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
112 canvas->scale(1.5f, 1.5f); 142 canvas->scale(1.5f, 1.5f);
113 canvas->translate(50,50); 143 canvas->translate(50,50);
114 144
115 const float blurRadii[] = { 1,5,10,20 }; 145 const float blurRadii[] = { 1,5,10,20 };
116 const int cornerRadii[] = { 1,5,10,20 }; 146 const int cornerRadii[] = { 1,5,10,20 };
117 const SkRect r = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); 147 const SkRect r = SkRect::MakeWH(SkIntToScalar(25), SkIntToScalar(25));
118 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) { 148 for (size_t i = 0; i < SK_ARRAY_COUNT(blurRadii); ++i) {
119 SkAutoCanvasRestore autoRestore(canvas, true); 149 SkAutoCanvasRestore autoRestore(canvas, true);
120 canvas->translate(0, (r.height() + SkIntToScalar(50)) * i); 150 canvas->translate(0, (r.height() + SkIntToScalar(50)) * i);
121 for (size_t j = 0; j < SK_ARRAY_COUNT(cornerRadii); ++j) { 151 for (size_t j = 0; j < SK_ARRAY_COUNT(cornerRadii); ++j) {
122 SkMaskFilter* filter = SkBlurMaskFilter::Create( 152 for (int k = 0; k <= 1; k++) {
123 kNormal_SkBlurStyle, 153 SkMaskFilter* filter = SkBlurMaskFilter::Create(
124 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i]) ), 154 kNormal_SkBlurStyle,
125 SkBlurMaskFilter::kHighQuality_BlurFlag); 155 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii [i])),
126 SkPaint paint; 156 SkBlurMaskFilter::kHighQuality_BlurFlag);
127 paint.setColor(SK_ColorBLACK); 157 SkPaint paint;
128 paint.setMaskFilter(filter)->unref(); 158 paint.setColor(SK_ColorBLACK);
159 paint.setMaskFilter(filter)->unref();
129 160
130 SkRRect rrect; 161 bool useRadial = SkToBool(k);
131 rrect.setRectXY(r, SkIntToScalar(cornerRadii[j]), SkIntToScalar( cornerRadii[j])); 162 if (useRadial) {
132 canvas->drawRRect(rrect, paint); 163 paint.setShader(MakeRadial())->unref();
133 canvas->translate(r.width() + SkIntToScalar(50), 0); 164 }
165
166 SkRRect rrect;
167 rrect.setRectXY(r, SkIntToScalar(cornerRadii[j]),
168 SkIntToScalar(cornerRadii[j]));
169 canvas->drawRRect(rrect, paint);
170 canvas->translate(r.width() + SkIntToScalar(50), 0);
171 }
134 } 172 }
135 } 173 }
136 } 174 }
137 private: 175 private:
138 const SkString fName; 176 const SkString fName;
139 177
140 typedef skiagm::GM INHERITED; 178 typedef skiagm::GM INHERITED;
141 }; 179 };
142 180
143 // Create one with dimensions/rounded corners based on the skp 181 // Create one with dimensions/rounded corners based on the skp
144 // 182 //
145 // TODO(scroggo): Disabled in an attempt to rememdy 183 // TODO(scroggo): Disabled in an attempt to rememdy
146 // https://code.google.com/p/skia/issues/detail?id=1801 ('Win7 Test bots all fai ling GenerateGMs: 184 // https://code.google.com/p/skia/issues/detail?id=1801 ('Win7 Test bots all fai ling GenerateGMs:
147 // ran wrong number of tests') 185 // ran wrong number of tests')
148 //DEF_GM(return new BlurRoundRectGM(600, 5514, 6);) 186 //DEF_GM(return new BlurRoundRectGM(600, 5514, 6);)
149 187
150 // Rounded rect with two opposite corners with large radii, the other two 188 // Rounded rect with two opposite corners with large radii, the other two
151 // small. 189 // small.
152 DEF_GM(return new BlurRoundRectGM(100, 100);) 190 DEF_GM(return new BlurRoundRectGM(100, 100);)
153 191
154 DEF_GM(return new SimpleBlurRoundRectGM();) 192 DEF_GM(return new SimpleBlurRoundRectGM();)
OLDNEW
« no previous file with comments | « gm/blurrect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698