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