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

Side by Side Diff: gm/gradients_no_texture.cpp

Issue 1442833004: augment gradients_many to exercise flipped gradients and clampping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 | 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 #include "gm.h" 7 #include "gm.h"
8 #include "SkGradientShader.h" 8 #include "SkGradientShader.h"
9 9
10 using namespace skiagm; 10 using namespace skiagm;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 SK_ColorBLACK, 196 SK_ColorBLACK,
197 }; 197 };
198 const int N = SK_ARRAY_COUNT(colors); 198 const int N = SK_ARRAY_COUNT(colors);
199 SkScalar pos[N]; 199 SkScalar pos[N];
200 for (int i = 0; i < N; ++i) { 200 for (int i = 0; i < N; ++i) {
201 pos[i] = SK_Scalar1 * i / (N - 1); 201 pos[i] = SK_Scalar1 * i / (N - 1);
202 } 202 }
203 rec->construct(colors, pos, N); 203 rec->construct(colors, pos, N);
204 } 204 }
205 205
206 static void make3(ColorPos* rec) {
207 const SkColor colors[] = {
208 SK_ColorRED, SK_ColorBLUE, SK_ColorBLUE, SK_ColorGREEN, SK_ColorGREEN, S K_ColorBLACK,
209 };
210 const SkScalar pos[] = {
211 0, 0, 0.5f, 0.5, 1, 1,
212 };
213 rec->construct(colors, pos, SK_ARRAY_COUNT(colors));
214 }
215
206 class GradientsManyColorsGM : public GM { 216 class GradientsManyColorsGM : public GM {
207 enum { 217 enum {
208 W = 800, 218 W = 800,
209 }; 219 };
210 SkAutoTUnref<SkShader> fShader; 220 SkAutoTUnref<SkShader> fShader;
211 221
212 typedef void (*Proc)(ColorPos*); 222 typedef void (*Proc)(ColorPos*);
213 public: 223 public:
214 GradientsManyColorsGM(bool dither) : fDither(dither) {} 224 GradientsManyColorsGM(bool dither) : fDither(dither) {}
215 225
216 protected: 226 protected:
217 227
218 SkString onShortName() override { 228 SkString onShortName() override {
219 return SkString(fDither ? "gradients_many" : "gradients_many_nodither"); 229 return SkString(fDither ? "gradients_many" : "gradients_many_nodither");
220 } 230 }
221 231
222 SkISize onISize() override { return SkISize::Make(850, 100); } 232 SkISize onISize() override { return SkISize::Make(880, 400); }
223 233
224 void onDraw(SkCanvas* canvas) override { 234 void onDraw(SkCanvas* canvas) override {
225 const Proc procs[] = { 235 const Proc procs[] = {
226 make0, make1, make2, 236 make0, make1, make2, make3,
227 }; 237 };
228 const SkPoint pts[] = { 238 const SkPoint pts[] = {
229 { 0, 0 }, 239 { 0, 0 },
230 { SkIntToScalar(W), 0 }, 240 { SkIntToScalar(W), 0 },
231 }; 241 };
232 const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30); 242 const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30);
233 243
234 SkPaint paint; 244 SkPaint paint;
235 paint.setDither(fDither); 245 paint.setDither(fDither);
236 246
237 canvas->translate(20, 20); 247 canvas->translate(40, 20);
238 248
239 for (int i = 0; i <= 8; ++i) { 249 for (int i = 0; i <= 8; ++i) {
240 SkScalar x = r.width() * i / 8; 250 SkScalar x = r.width() * i / 8;
241 canvas->drawLine(x, 0, x, 10000, paint); 251 canvas->drawLine(x, 0, x, 10000, paint);
242 } 252 }
243 253
254 // expand the drawing rect so we exercise clampping in the gradients
255 const SkRect drawR = r.makeOutset(20, 0);
244 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { 256 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
245 ColorPos rec; 257 ColorPos rec;
246 procs[i](&rec); 258 procs[i](&rec);
247 SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.f Pos, rec.fCount, 259 SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.f Pos, rec.fCount,
248 SkShader::kClamp_TileMo de); 260 SkShader::kClamp_TileMo de);
249 paint.setShader(s)->unref(); 261 paint.setShader(s)->unref();
250 canvas->drawRect(r, paint); 262 canvas->drawRect(drawR, paint);
251 canvas->translate(0, r.height() + 20); 263
264 canvas->save();
265 canvas->translate(r.centerX(), r.height() + 4);
266 canvas->scale(-1, 1);
267 canvas->translate(-r.centerX(), 0);
268 canvas->drawRect(drawR, paint);
269 canvas->restore();
270
271 canvas->translate(0, r.height() + 2*r.height() + 8);
252 } 272 }
253 } 273 }
254 274
255 private: 275 private:
256 bool fDither; 276 bool fDither;
257 277
258 typedef GM INHERITED; 278 typedef GM INHERITED;
259 }; 279 };
260 280
261 /////////////////////////////////////////////////////////////////////////////// 281 ///////////////////////////////////////////////////////////////////////////////
262 282
263 DEF_GM(return new GradientsNoTextureGM(true);) 283 DEF_GM(return new GradientsNoTextureGM(true);)
264 DEF_GM(return new GradientsNoTextureGM(false);) 284 DEF_GM(return new GradientsNoTextureGM(false);)
265 DEF_GM(return new GradientsManyColorsGM(true);) 285 DEF_GM(return new GradientsManyColorsGM(true);)
266 DEF_GM(return new GradientsManyColorsGM(false);) 286 DEF_GM(return new GradientsManyColorsGM(false);)
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