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

Side by Side Diff: gm/gradients_no_texture.cpp

Issue 1400813006: Remove SK_SUPPORT_LEGACY_GRADIENT_DITHERING from Skia proper (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha der::TileMode tm); 73 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha der::TileMode tm);
74 74
75 static const GradMaker gGradMakers[] = { 75 static const GradMaker gGradMakers[] = {
76 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical, 76 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical,
77 }; 77 };
78 78
79 /////////////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////////////
80 80
81 class GradientsNoTextureGM : public GM { 81 class GradientsNoTextureGM : public GM {
82 public: 82 public:
83 GradientsNoTextureGM() { 83 GradientsNoTextureGM(bool dither) : fDither(dither) {
84 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); 84 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
85 } 85 }
86 86
87 protected: 87 protected:
88 88
89 SkString onShortName() override { return SkString("gradients_no_texture"); } 89 SkString onShortName() override {
90 return SkString(fDither ? "gradients_no_texture" : "gradients_no_texture _nodither");
91 }
92
90 SkISize onISize() override { return SkISize::Make(640, 615); } 93 SkISize onISize() override { return SkISize::Make(640, 615); }
91 94
92 void onDraw(SkCanvas* canvas) override { 95 void onDraw(SkCanvas* canvas) override {
93 static const SkPoint kPts[2] = { { 0, 0 }, 96 static const SkPoint kPts[2] = { { 0, 0 },
94 { SkIntToScalar(50), SkIntToScalar(50) } }; 97 { SkIntToScalar(50), SkIntToScalar(50) } };
95 static const SkShader::TileMode kTM = SkShader::kClamp_TileMode; 98 static const SkShader::TileMode kTM = SkShader::kClamp_TileMode;
96 SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) }; 99 SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) };
97 SkPaint paint; 100 SkPaint paint;
98 paint.setAntiAlias(true); 101 paint.setAntiAlias(true);
102 paint.setDither(fDither);
99 103
100 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 104 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
101 static const uint8_t kAlphas[] = { 0xff, 0x40 }; 105 static const uint8_t kAlphas[] = { 0xff, 0x40 };
102 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) { 106 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) {
103 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) { 107 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) {
104 canvas->save(); 108 canvas->save();
105 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) { 109 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) {
106 SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM); 110 SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM);
107 paint.setShader(shader)->unref(); 111 paint.setShader(shader)->unref();
108 paint.setAlpha(kAlphas[a]); 112 paint.setAlpha(kAlphas[a]);
109 canvas->drawRect(kRect, paint); 113 canvas->drawRect(kRect, paint);
110 canvas->translate(0, SkIntToScalar(kRect.height() + 20)); 114 canvas->translate(0, SkIntToScalar(kRect.height() + 20));
111 } 115 }
112 canvas->restore(); 116 canvas->restore();
113 canvas->translate(SkIntToScalar(kRect.width() + 20), 0); 117 canvas->translate(SkIntToScalar(kRect.width() + 20), 0);
114 } 118 }
115 } 119 }
116 } 120 }
117 121
118 private: 122 private:
123 bool fDither;
124
119 typedef GM INHERITED; 125 typedef GM INHERITED;
120 }; 126 };
121 127
122 /////////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////////
123 129
124 struct ColorPos { 130 struct ColorPos {
125 SkColor* fColors; 131 SkColor* fColors;
126 SkScalar* fPos; 132 SkScalar* fPos;
127 int fCount; 133 int fCount;
128 134
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 204 }
199 205
200 class GradientsManyColorsGM : public GM { 206 class GradientsManyColorsGM : public GM {
201 enum { 207 enum {
202 W = 800, 208 W = 800,
203 }; 209 };
204 SkAutoTUnref<SkShader> fShader; 210 SkAutoTUnref<SkShader> fShader;
205 211
206 typedef void (*Proc)(ColorPos*); 212 typedef void (*Proc)(ColorPos*);
207 public: 213 public:
208 GradientsManyColorsGM() {} 214 GradientsManyColorsGM(bool dither) : fDither(dither) {}
209 215
210 protected: 216 protected:
211 217
212 SkString onShortName() override { return SkString("gradients_many"); } 218 SkString onShortName() override {
219 return SkString(fDither ? "gradients_many" : "gradients_many_nodither");
220 }
221
213 SkISize onISize() override { return SkISize::Make(850, 100); } 222 SkISize onISize() override { return SkISize::Make(850, 100); }
214 223
215 void onDraw(SkCanvas* canvas) override { 224 void onDraw(SkCanvas* canvas) override {
216 const Proc procs[] = { 225 const Proc procs[] = {
217 make0, make1, make2, 226 make0, make1, make2,
218 }; 227 };
219 const SkPoint pts[] = { 228 const SkPoint pts[] = {
220 { 0, 0 }, 229 { 0, 0 },
221 { SkIntToScalar(W), 0 }, 230 { SkIntToScalar(W), 0 },
222 }; 231 };
223 const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30); 232 const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30);
224 233
225 SkPaint paint; 234 SkPaint paint;
235 paint.setDither(fDither);
226 236
227 canvas->translate(20, 20); 237 canvas->translate(20, 20);
228 238
229 for (int i = 0; i <= 8; ++i) { 239 for (int i = 0; i <= 8; ++i) {
230 SkScalar x = r.width() * i / 8; 240 SkScalar x = r.width() * i / 8;
231 canvas->drawLine(x, 0, x, 10000, paint); 241 canvas->drawLine(x, 0, x, 10000, paint);
232 } 242 }
233 243
234 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { 244 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
235 ColorPos rec; 245 ColorPos rec;
236 procs[i](&rec); 246 procs[i](&rec);
237 SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.f Pos, rec.fCount, 247 SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.f Pos, rec.fCount,
238 SkShader::kClamp_TileMo de); 248 SkShader::kClamp_TileMo de);
239 paint.setShader(s)->unref(); 249 paint.setShader(s)->unref();
240 canvas->drawRect(r, paint); 250 canvas->drawRect(r, paint);
241 canvas->translate(0, r.height() + 20); 251 canvas->translate(0, r.height() + 20);
242 } 252 }
243 } 253 }
244 254
245 private: 255 private:
256 bool fDither;
257
246 typedef GM INHERITED; 258 typedef GM INHERITED;
247 }; 259 };
248 260
249 /////////////////////////////////////////////////////////////////////////////// 261 ///////////////////////////////////////////////////////////////////////////////
250 262
251 DEF_GM(return new GradientsNoTextureGM); 263 DEF_GM(return new GradientsNoTextureGM(true);)
252 DEF_GM(return new GradientsManyColorsGM); 264 DEF_GM(return new GradientsNoTextureGM(false);)
265 DEF_GM(return new GradientsManyColorsGM(true);)
266 DEF_GM(return new GradientsManyColorsGM(false);)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698