OLD | NEW |
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::MakeLinear(pts, colors, pos, | 30 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, |
31 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); | 31 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref(); |
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 paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy)); | 37 SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy); |
| 38 paint->setShader(shader)->unref(); |
38 paint->setFilterQuality(filter_level); | 39 paint->setFilterQuality(filter_level); |
39 } | 40 } |
40 | 41 |
41 static const SkColorType gColorTypes[] = { | 42 static const SkColorType gColorTypes[] = { |
42 kN32_SkColorType, | 43 kN32_SkColorType, |
43 kRGB_565_SkColorType, | 44 kRGB_565_SkColorType, |
44 }; | 45 }; |
45 | 46 |
46 class ScaledTilingGM : public skiagm::GM { | 47 class ScaledTilingGM : public skiagm::GM { |
47 public: | 48 public: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 153 } |
153 | 154 |
154 private: | 155 private: |
155 bool fPowerOfTwoSize; | 156 bool fPowerOfTwoSize; |
156 typedef skiagm::GM INHERITED; | 157 typedef skiagm::GM INHERITED; |
157 }; | 158 }; |
158 | 159 |
159 static const int gWidth = 32; | 160 static const int gWidth = 32; |
160 static const int gHeight = 32; | 161 static const int gHeight = 32; |
161 | 162 |
162 static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { | 163 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { |
163 SkBitmap bm; | 164 SkBitmap bm; |
164 makebm(&bm, kN32_SkColorType, gWidth, gHeight); | 165 makebm(&bm, kN32_SkColorType, gWidth, gHeight); |
165 return SkShader::MakeBitmapShader(bm, tx, ty); | 166 return SkShader::CreateBitmapShader(bm, tx, ty); |
166 } | 167 } |
167 | 168 |
168 static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { | 169 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { |
169 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; | 170 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)}
}; |
170 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; | 171 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; |
171 SkScalar rad = SkIntToScalar(gWidth)/2; | 172 SkScalar rad = SkIntToScalar(gWidth)/2; |
172 SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) }; | 173 SkColor colors[] = { 0xFFFF0000, sk_tool_utils::color_to_565(0xFF0044FF) }; |
173 | 174 |
174 int index = (int)ty; | 175 int index = (int)ty; |
175 switch (index % 3) { | 176 switch (index % 3) { |
176 case 0: | 177 case 0: |
177 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_C
OUNT(colors), tx); | 178 return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY
_COUNT(colors), tx); |
178 case 1: | 179 case 1: |
179 return SkGradientShader::MakeRadial(center, rad, colors, nullptr, SK
_ARRAY_COUNT(colors), tx); | 180 return SkGradientShader::CreateRadial(center, rad, colors, nullptr,
SK_ARRAY_COUNT(colors), tx); |
180 case 2: | 181 case 2: |
181 return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nul
lptr, SK_ARRAY_COUNT(colors)); | 182 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, n
ullptr, SK_ARRAY_COUNT(colors)); |
182 } | 183 } |
183 | 184 |
184 return nullptr; | 185 return nullptr; |
185 } | 186 } |
186 | 187 |
187 typedef sk_sp<SkShader> (*ShaderProc)(SkShader::TileMode, SkShader::TileMode); | 188 typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode); |
188 | 189 |
189 class ScaledTiling2GM : public skiagm::GM { | 190 class ScaledTiling2GM : public skiagm::GM { |
190 ShaderProc fProc; | 191 ShaderProc fProc; |
191 SkString fName; | 192 SkString fName; |
192 public: | 193 public: |
193 ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc) { | 194 ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc) { |
194 fName.printf("scaled_tilemode_%s", name); | 195 fName.printf("scaled_tilemode_%s", name); |
195 } | 196 } |
196 | 197 |
197 protected: | 198 protected: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 236 |
236 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 237 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
237 x = SkIntToScalar(16) + w; | 238 x = SkIntToScalar(16) + w; |
238 | 239 |
239 SkString str(gModeNames[ky]); | 240 SkString str(gModeNames[ky]); |
240 canvas->drawText(str.c_str(), str.size(), x, y + h/2, p); | 241 canvas->drawText(str.c_str(), str.size(), x, y + h/2, p); |
241 | 242 |
242 x += SkIntToScalar(50); | 243 x += SkIntToScalar(50); |
243 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 244 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
244 SkPaint paint; | 245 SkPaint paint; |
245 paint.setShader(fProc(gModes[kx], gModes[ky])); | 246 paint.setShader(fProc(gModes[kx], gModes[ky]))->unref(); |
246 | 247 |
247 canvas->save(); | 248 canvas->save(); |
248 canvas->translate(x, y); | 249 canvas->translate(x, y); |
249 canvas->drawRect(r, paint); | 250 canvas->drawRect(r, paint); |
250 canvas->restore(); | 251 canvas->restore(); |
251 | 252 |
252 x += r.width() * 4 / 3; | 253 x += r.width() * 4 / 3; |
253 } | 254 } |
254 y += r.height() * 4 / 3; | 255 y += r.height() * 4 / 3; |
255 } | 256 } |
256 } | 257 } |
257 | 258 |
258 private: | 259 private: |
259 typedef skiagm::GM INHERITED; | 260 typedef skiagm::GM INHERITED; |
260 }; | 261 }; |
261 | 262 |
262 ////////////////////////////////////////////////////////////////////////////// | 263 ////////////////////////////////////////////////////////////////////////////// |
263 | 264 |
264 DEF_GM( return new ScaledTilingGM(true); ) | 265 DEF_GM( return new ScaledTilingGM(true); ) |
265 DEF_GM( return new ScaledTilingGM(false); ) | 266 DEF_GM( return new ScaledTilingGM(false); ) |
266 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) | 267 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); ) |
267 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) | 268 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); ) |
OLD | NEW |