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

Side by Side Diff: gm/tilemodes_scaled.cpp

Issue 1789633002: more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 /* 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 "gm.h" 8 #include "gm.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkRegion.h" 10 #include "SkRegion.h"
11 #include "SkShader.h" 11 #include "SkShader.h"
12 #include "SkUtils.h" 12 #include "SkUtils.h"
13 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
14 14
15 // effects 15 // effects
16 #include "SkGradientShader.h" 16 #include "SkGradientShader.h"
17 #include "SkBlurDrawLooper.h" 17 #include "SkBlurDrawLooper.h"
18 18
19 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) { 19 static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
20 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType)); 20 bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
21 bm->eraseColor(SK_ColorTRANSPARENT); 21 bm->eraseColor(SK_ColorTRANSPARENT);
22 22
23 SkCanvas canvas(*bm); 23 SkCanvas canvas(*bm);
24 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} }; 24 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} };
25 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; 25 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
26 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 26 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
27 SkPaint paint; 27 SkPaint paint;
28 28
29 paint.setDither(true); 29 paint.setDither(true);
30 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, 30 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos,
31 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref(); 31 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
32 canvas.drawPaint(paint); 32 canvas.drawPaint(paint);
33 } 33 }
34 34
35 static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_lev el, 35 static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_lev el,
36 SkShader::TileMode tmx, SkShader::TileMode tmy) { 36 SkShader::TileMode tmx, SkShader::TileMode tmy) {
37 SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy); 37 paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
38 paint->setShader(shader)->unref();
39 paint->setFilterQuality(filter_level); 38 paint->setFilterQuality(filter_level);
40 } 39 }
41 40
42 static const SkColorType gColorTypes[] = { 41 static const SkColorType gColorTypes[] = {
43 kN32_SkColorType, 42 kN32_SkColorType,
44 kRGB_565_SkColorType, 43 kRGB_565_SkColorType,
45 }; 44 };
46 45
47 class ScaledTilingGM : public skiagm::GM { 46 class ScaledTilingGM : public skiagm::GM {
48 public: 47 public:
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 152 }
154 153
155 private: 154 private:
156 bool fPowerOfTwoSize; 155 bool fPowerOfTwoSize;
157 typedef skiagm::GM INHERITED; 156 typedef skiagm::GM INHERITED;
158 }; 157 };
159 158
160 static const int gWidth = 32; 159 static const int gWidth = 32;
161 static const int gHeight = 32; 160 static const int gHeight = 32;
162 161
163 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { 162 static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
164 SkBitmap bm; 163 SkBitmap bm;
165 makebm(&bm, kN32_SkColorType, gWidth, gHeight); 164 makebm(&bm, kN32_SkColorType, gWidth, gHeight);
166 return SkShader::CreateBitmapShader(bm, tx, ty); 165 return SkShader::MakeBitmapShader(bm, tx, ty);
167 } 166 }
168 167
169 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { 168 static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
170 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} }; 169 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
171 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; 170 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
172 SkScalar rad = SkIntToScalar(gWidth)/2; 171 SkScalar rad = SkIntToScalar(gWidth)/2;
173 SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) }; 172 SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) };
174 173
175 int index = (int)ty; 174 int index = (int)ty;
176 switch (index % 3) { 175 switch (index % 3) {
177 case 0: 176 case 0:
178 return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY _COUNT(colors), tx); 177 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_C OUNT(colors), tx);
179 case 1: 178 case 1:
180 return SkGradientShader::CreateRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx); 179 return SkGradientShader::MakeRadial(center, rad, colors, nullptr, SK _ARRAY_COUNT(colors), tx);
181 case 2: 180 case 2:
182 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, n ullptr, SK_ARRAY_COUNT(colors)); 181 return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nul lptr, SK_ARRAY_COUNT(colors));
183 } 182 }
184 183
185 return nullptr; 184 return nullptr;
186 } 185 }
187 186
188 typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode); 187 typedef sk_sp<SkShader> (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
189 188
190 class ScaledTiling2GM : public skiagm::GM { 189 class ScaledTiling2GM : public skiagm::GM {
191 ShaderProc fProc; 190 ShaderProc fProc;
192 SkString fName; 191 SkString fName;
193 public: 192 public:
194 ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc) { 193 ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc) {
195 fName.printf("scaled_tilemode_%s", name); 194 fName.printf("scaled_tilemode_%s", name);
196 } 195 }
197 196
198 protected: 197 protected:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 235
237 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { 236 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
238 x = SkIntToScalar(16) + w; 237 x = SkIntToScalar(16) + w;
239 238
240 SkString str(gModeNames[ky]); 239 SkString str(gModeNames[ky]);
241 canvas->drawText(str.c_str(), str.size(), x, y + h/2, p); 240 canvas->drawText(str.c_str(), str.size(), x, y + h/2, p);
242 241
243 x += SkIntToScalar(50); 242 x += SkIntToScalar(50);
244 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 243 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
245 SkPaint paint; 244 SkPaint paint;
246 paint.setShader(fProc(gModes[kx], gModes[ky]))->unref(); 245 paint.setShader(fProc(gModes[kx], gModes[ky]));
247 246
248 canvas->save(); 247 canvas->save();
249 canvas->translate(x, y); 248 canvas->translate(x, y);
250 canvas->drawRect(r, paint); 249 canvas->drawRect(r, paint);
251 canvas->restore(); 250 canvas->restore();
252 251
253 x += r.width() * 4 / 3; 252 x += r.width() * 4 / 3;
254 } 253 }
255 y += r.height() * 4 / 3; 254 y += r.height() * 4 / 3;
256 } 255 }
257 } 256 }
258 257
259 private: 258 private:
260 typedef skiagm::GM INHERITED; 259 typedef skiagm::GM INHERITED;
261 }; 260 };
262 261
263 ////////////////////////////////////////////////////////////////////////////// 262 //////////////////////////////////////////////////////////////////////////////
264 263
265 DEF_GM( return new ScaledTilingGM(true); ) 264 DEF_GM( return new ScaledTilingGM(true); )
266 DEF_GM( return new ScaledTilingGM(false); ) 265 DEF_GM( return new ScaledTilingGM(false); )
267 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) 266 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); )
268 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) 267 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); )
OLDNEW
« gm/pictureshadertile.cpp ('K') | « gm/tilemodes.cpp ('k') | gm/tinybitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698