OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkView.h" | 10 #include "SkView.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "SkColorPriv.h" | 21 #include "SkColorPriv.h" |
22 #include "SkColorFilter.h" | 22 #include "SkColorFilter.h" |
23 #include "SkTime.h" | 23 #include "SkTime.h" |
24 #include "SkTypeface.h" | 24 #include "SkTypeface.h" |
25 | 25 |
26 #include "SkOSFile.h" | 26 #include "SkOSFile.h" |
27 #include "SkStream.h" | 27 #include "SkStream.h" |
28 | 28 |
29 #include "SkGeometry.h" // private include :( | 29 #include "SkGeometry.h" // private include :( |
30 | 30 |
31 static SkShader* make_shader0(SkIPoint* size) { | 31 static sk_sp<SkShader> make_shader0(SkIPoint* size) { |
32 SkBitmap bm; | 32 SkBitmap bm; |
33 | 33 |
34 // SkImageDecoder::DecodeFile("/skimages/progressivejpg.jpg", &bm); | 34 // SkImageDecoder::DecodeFile("/skimages/progressivejpg.jpg", &bm); |
35 SkImageDecoder::DecodeFile("/skimages/logo.png", &bm); | 35 SkImageDecoder::DecodeFile("/skimages/logo.png", &bm); |
36 size->set(bm.width(), bm.height()); | 36 size->set(bm.width(), bm.height()); |
37 return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, | 37 return SkShader::MakeBitmapShader(bm, SkShader::kClamp_TileMode, |
38 SkShader::kClamp_TileMode); | 38 SkShader::kClamp_TileMode); |
39 } | 39 } |
40 | 40 |
41 static SkShader* make_shader1(const SkIPoint& size) { | 41 static sk_sp<SkShader> make_shader1(const SkIPoint& size) { |
42 SkPoint pts[] = { { 0, 0, }, | 42 SkPoint pts[] = { { 0, 0, }, |
43 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; | 43 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; |
44 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED }
; | 44 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED }
; |
45 return SkGradientShader::CreateLinear(pts, colors, nullptr, | 45 return SkGradientShader::MakeLinear(pts, colors, nullptr, |
46 SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode); | 46 SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode); |
47 } | 47 } |
48 | 48 |
49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
50 | 50 |
51 class Patch { | 51 class Patch { |
52 public: | 52 public: |
53 Patch() { sk_bzero(fPts, sizeof(fPts)); } | 53 Patch() { sk_bzero(fPts, sizeof(fPts)); } |
54 ~Patch() {} | 54 ~Patch() {} |
55 | 55 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 patch->draw(canvas, paint, nu, nv, false, true); | 204 patch->draw(canvas, paint, nu, nv, false, true); |
205 canvas->translate(SkIntToScalar(180), 0); | 205 canvas->translate(SkIntToScalar(180), 0); |
206 patch->draw(canvas, paint, nu, nv, true, true); | 206 patch->draw(canvas, paint, nu, nv, true, true); |
207 } | 207 } |
208 | 208 |
209 const SkScalar DX = 20; | 209 const SkScalar DX = 20; |
210 const SkScalar DY = 0; | 210 const SkScalar DY = 0; |
211 | 211 |
212 class PatchView : public SampleView { | 212 class PatchView : public SampleView { |
213 SkScalar fAngle; | 213 SkScalar fAngle; |
214 SkShader* fShader0; | 214 sk_sp<SkShader> fShader0; |
215 SkShader* fShader1; | 215 sk_sp<SkShader> fShader1; |
216 SkIPoint fSize0, fSize1; | 216 SkIPoint fSize0, fSize1; |
217 SkPoint fPts[12]; | 217 SkPoint fPts[12]; |
218 | 218 |
219 public: | 219 public: |
220 PatchView() : fAngle(0) { | 220 PatchView() : fAngle(0) { |
221 fShader0 = make_shader0(&fSize0); | 221 fShader0 = make_shader0(&fSize0); |
222 fSize1 = fSize0; | 222 fSize1 = fSize0; |
223 if (fSize0.fX == 0 || fSize0.fY == 0) { | 223 if (fSize0.fX == 0 || fSize0.fY == 0) { |
224 fSize1.set(2, 2); | 224 fSize1.set(2, 2); |
225 } | 225 } |
(...skipping 10 matching lines...) Expand all Loading... |
236 fPts[6].set(S*3, T*4); | 236 fPts[6].set(S*3, T*4); |
237 fPts[7].set(S*2, T*4); | 237 fPts[7].set(S*2, T*4); |
238 fPts[8].set(S*1, T*4); | 238 fPts[8].set(S*1, T*4); |
239 fPts[9].set(S*0, T*4); | 239 fPts[9].set(S*0, T*4); |
240 fPts[10].set(S*0, T*3); | 240 fPts[10].set(S*0, T*3); |
241 fPts[11].set(S*0, T*2); | 241 fPts[11].set(S*0, T*2); |
242 | 242 |
243 this->setBGColor(SK_ColorGRAY); | 243 this->setBGColor(SK_ColorGRAY); |
244 } | 244 } |
245 | 245 |
246 virtual ~PatchView() { | |
247 SkSafeUnref(fShader0); | |
248 SkSafeUnref(fShader1); | |
249 } | |
250 | |
251 protected: | 246 protected: |
252 // overrides from SkEventSink | 247 // overrides from SkEventSink |
253 bool onQuery(SkEvent* evt) override { | 248 bool onQuery(SkEvent* evt) override { |
254 if (SampleCode::TitleQ(*evt)) { | 249 if (SampleCode::TitleQ(*evt)) { |
255 SampleCode::TitleR(evt, "Patch"); | 250 SampleCode::TitleR(evt, "Patch"); |
256 return true; | 251 return true; |
257 } | 252 } |
258 return this->INHERITED::onQuery(evt); | 253 return this->INHERITED::onQuery(evt); |
259 } | 254 } |
260 | 255 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 } | 335 } |
341 | 336 |
342 private: | 337 private: |
343 typedef SampleView INHERITED; | 338 typedef SampleView INHERITED; |
344 }; | 339 }; |
345 | 340 |
346 ////////////////////////////////////////////////////////////////////////////// | 341 ////////////////////////////////////////////////////////////////////////////// |
347 | 342 |
348 static SkView* MyFactory() { return new PatchView; } | 343 static SkView* MyFactory() { return new PatchView; } |
349 static SkViewRegister reg(MyFactory); | 344 static SkViewRegister reg(MyFactory); |
OLD | NEW |