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

Side by Side Diff: samplecode/SampleVertices.cpp

Issue 1772463002: use Make instead of Create to return a shared shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: partial update of skia call-sites 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkGraphics.h" 12 #include "SkGraphics.h"
13 #include "SkImageDecoder.h" 13 #include "SkImageDecoder.h"
14 #include "SkPath.h" 14 #include "SkPath.h"
15 #include "SkRandom.h" 15 #include "SkRandom.h"
16 #include "SkRegion.h" 16 #include "SkRegion.h"
17 #include "SkShader.h" 17 #include "SkShader.h"
18 #include "SkUtils.h" 18 #include "SkUtils.h"
19 #include "SkXfermode.h" 19 #include "SkXfermode.h"
20 #include "SkColorPriv.h" 20 #include "SkColorPriv.h"
21 #include "SkColorFilter.h" 21 #include "SkColorFilter.h"
22 #include "SkTime.h" 22 #include "SkTime.h"
23 #include "SkTypeface.h" 23 #include "SkTypeface.h"
24 24
25 #include "SkOSFile.h" 25 #include "SkOSFile.h"
26 #include "SkStream.h" 26 #include "SkStream.h"
27 27
28 static SkShader* make_shader0(SkIPoint* size) { 28 static sk_sp<SkShader> make_shader0(SkIPoint* size) {
29 SkBitmap bm; 29 SkBitmap bm;
30 size->set(2, 2); 30 size->set(2, 2);
31 SkPMColor color0 = SkPreMultiplyARGB(0x80, 0x80, 0xff, 0x80); 31 SkPMColor color0 = SkPreMultiplyARGB(0x80, 0x80, 0xff, 0x80);
32 SkPMColor color1 = SkPreMultiplyARGB(0x40, 0xff, 0x00, 0xff); 32 SkPMColor color1 = SkPreMultiplyARGB(0x40, 0xff, 0x00, 0xff);
33 bm.allocN32Pixels(size->fX, size->fY); 33 bm.allocN32Pixels(size->fX, size->fY);
34 bm.eraseColor(color0); 34 bm.eraseColor(color0);
35 bm.lockPixels(); 35 bm.lockPixels();
36 uint32_t* pixels = (uint32_t*) bm.getPixels(); 36 uint32_t* pixels = (uint32_t*) bm.getPixels();
37 pixels[0] = pixels[2] = color0; 37 pixels[0] = pixels[2] = color0;
38 pixels[1] = pixels[3] = color1; 38 pixels[1] = pixels[3] = color1;
39 bm.unlockPixels(); 39 bm.unlockPixels();
40 40
41 return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, 41 return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader:: kRepeat_TileMode);
42 SkShader::kRepeat_TileMode);
43 } 42 }
44 43
45 static SkShader* make_shader1(const SkIPoint& size) { 44 static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
46 SkPoint pts[] = { { 0, 0 }, 45 SkPoint pts[] = { { 0, 0 },
47 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; 46 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
48 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED } ; 47 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED } ;
49 return SkGradientShader::CreateLinear(pts, colors, nullptr, 48 return SkGradientShader::MakeLinear(pts, colors, nullptr,
50 SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode); 49 SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode);
51 } 50 }
52 51
53 class VerticesView : public SampleView { 52 class VerticesView : public SampleView {
54 SkShader* fShader0; 53 sk_sp<SkShader> fShader0;
55 SkShader* fShader1; 54 sk_sp<SkShader> fShader1;
56 55
57 public: 56 public:
58 VerticesView() { 57 VerticesView() {
59 SkIPoint size; 58 SkIPoint size;
60 59
61 fShader0 = make_shader0(&size); 60 fShader0 = make_shader0(&size);
62 fShader1 = make_shader1(size); 61 fShader1 = make_shader1(size);
63 62
64 make_strip(&fRecs[0], size.fX, size.fY); 63 make_strip(&fRecs[0], size.fX, size.fY);
65 make_fan(&fRecs[1], size.fX, size.fY); 64 make_fan(&fRecs[1], size.fX, size.fY);
66 make_tris(&fRecs[2]); 65 make_tris(&fRecs[2]);
67 66
68 fScale = SK_Scalar1; 67 fScale = SK_Scalar1;
69 68
70 this->setBGColor(SK_ColorGRAY); 69 this->setBGColor(SK_ColorGRAY);
71 } 70 }
72 71
73 virtual ~VerticesView() {
74 SkSafeUnref(fShader0);
75 SkSafeUnref(fShader1);
76 }
77
78 protected: 72 protected:
79 // overrides from SkEventSink 73 // overrides from SkEventSink
80 bool onQuery(SkEvent* evt) override { 74 bool onQuery(SkEvent* evt) override {
81 if (SampleCode::TitleQ(*evt)) { 75 if (SampleCode::TitleQ(*evt)) {
82 SampleCode::TitleR(evt, "Vertices"); 76 SampleCode::TitleR(evt, "Vertices");
83 return true; 77 return true;
84 } 78 }
85 return this->INHERITED::onQuery(evt); 79 return this->INHERITED::onQuery(evt);
86 } 80 }
87 81
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 217
224 Rec fRecs[3]; 218 Rec fRecs[3];
225 219
226 typedef SampleView INHERITED; 220 typedef SampleView INHERITED;
227 }; 221 };
228 222
229 ////////////////////////////////////////////////////////////////////////////// 223 //////////////////////////////////////////////////////////////////////////////
230 224
231 static SkView* MyFactory() { return new VerticesView; } 225 static SkView* MyFactory() { return new VerticesView; }
232 static SkViewRegister reg(MyFactory); 226 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698