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

Side by Side Diff: gm/vertices.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on 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
« no previous file with comments | « gm/transparency.cpp ('k') | gm/verylargebitmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 13
14 static SkShader* make_shader1(SkScalar w, SkScalar h) { 14 static sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) {
15 const SkColor colors[] = { 15 const SkColor colors[] = {
16 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, 16 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
17 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, 17 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
18 }; 18 };
19 const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } }; 19 const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } };
20 20
21 return SkGradientShader::CreateLinear(pts, colors, nullptr, 21 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col ors),
22 SK_ARRAY_COUNT(colors), 22 SkShader::kMirror_TileMode);
23 SkShader::kMirror_TileMode);
24 } 23 }
25 24
26 static SkShader* make_shader2() { 25 static sk_sp<SkShader> make_shader2() {
27 return SkShader::CreateColorShader(SK_ColorBLUE); 26 return SkShader::MakeColorShader(SK_ColorBLUE);
28 } 27 }
29 28
30 static SkColorFilter* make_color_filter() { 29 static SkColorFilter* make_color_filter() {
31 return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode) ; 30 return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode) ;
32 } 31 }
33 32
34 class VerticesGM : public skiagm::GM { 33 class VerticesGM : public skiagm::GM {
35 SkPoint fPts[9]; 34 SkPoint fPts[9];
36 SkPoint fTexs[9]; 35 SkPoint fTexs[9];
37 SkColor fColors[9]; 36 SkColor fColors[9];
38 SkAutoTUnref<SkShader> fShader1; 37 sk_sp<SkShader> fShader1;
39 SkAutoTUnref<SkShader> fShader2; 38 sk_sp<SkShader> fShader2;
40 SkAutoTUnref<SkColorFilter> fColorFilter; 39 SkAutoTUnref<SkColorFilter> fColorFilter;
41 40
42 public: 41 public:
43 VerticesGM() {} 42 VerticesGM() {}
44 43
45 protected: 44 protected:
46 45
47 void onOnceBeforeDraw() override { 46 void onOnceBeforeDraw() override {
48 const SkScalar X = 30; 47 const SkScalar X = 30;
49 const SkScalar Y = 30; 48 const SkScalar Y = 30;
50 49
51 fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0); 50 fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0);
52 fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2); 51 fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2);
53 fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y); 52 fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y);
54 53
55 const SkScalar w = 40; 54 const SkScalar w = 40;
56 const SkScalar h = 40; 55 const SkScalar h = 40;
57 56
58 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0); 57 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0);
59 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2); 58 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2);
60 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h); 59 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h);
61 60
62 fShader1.reset(make_shader1(w, h)); 61 fShader1 = make_shader1(w, h);
63 fShader2.reset(make_shader2()); 62 fShader2 = make_shader2();
64 fColorFilter.reset(make_color_filter()); 63 fColorFilter.reset(make_color_filter());
65 64
66 SkRandom rand; 65 SkRandom rand;
67 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) { 66 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
68 fColors[i] = rand.nextU() | 0xFF000000; 67 fColors[i] = rand.nextU() | 0xFF000000;
69 } 68 }
70 } 69 }
71 70
72 SkString onShortName() override { 71 SkString onShortName() override {
73 SkString name("vertices"); 72 SkString name("vertices");
74 return name; 73 return name;
75 } 74 }
76 75
77 SkISize onISize() override { 76 SkISize onISize() override {
78 return SkISize::Make(600, 600); 77 return SkISize::Make(600, 600);
79 } 78 }
80 79
81 void onDraw(SkCanvas* canvas) override { 80 void onDraw(SkCanvas* canvas) override {
82 // start with the center of a 3x3 grid 81 // start with the center of a 3x3 grid
83 static const uint16_t fan[] = { 82 static const uint16_t fan[] = {
84 4, 83 4,
85 0, 1, 2, 5, 8, 7, 6, 3, 0 84 0, 1, 2, 5, 8, 7, 6, 3, 0
86 }; 85 };
87 86
88 const struct { 87 const struct {
89 const SkColor* fColors; 88 const SkColor* fColors;
90 const SkPoint* fTexs; 89 const SkPoint* fTexs;
91 SkShader* fShader; 90 const sk_sp<SkShader>& fShader;
92 SkColorFilter* fColorFilter; 91 SkColorFilter* fColorFilter;
93 uint8_t fAlpha; 92 uint8_t fAlpha;
94 } rec[] = { 93 } rec[] = {
95 { fColors, nullptr, fShader1, nullptr , 0xFF }, 94 { fColors, nullptr, fShader1, nullptr , 0xFF },
96 { nullptr, fTexs , fShader1, nullptr , 0xFF }, 95 { nullptr, fTexs , fShader1, nullptr , 0xFF },
97 { fColors, fTexs , fShader1, nullptr , 0xFF }, 96 { fColors, fTexs , fShader1, nullptr , 0xFF },
98 { fColors, nullptr, fShader2, nullptr , 0xFF }, 97 { fColors, nullptr, fShader2, nullptr , 0xFF },
99 { nullptr, fTexs , fShader2, nullptr , 0xFF }, 98 { nullptr, fTexs , fShader2, nullptr , 0xFF },
100 { fColors, fTexs , fShader2, nullptr , 0xFF }, 99 { fColors, fTexs , fShader2, nullptr , 0xFF },
101 { fColors, nullptr, fShader1, fColorFilter, 0xFF }, 100 { fColors, nullptr, fShader1, fColorFilter, 0xFF },
102 { nullptr, fTexs , fShader1, fColorFilter, 0xFF }, 101 { nullptr, fTexs , fShader1, fColorFilter, 0xFF },
103 { fColors, fTexs , fShader1, fColorFilter, 0xFF }, 102 { fColors, fTexs , fShader1, fColorFilter, 0xFF },
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 174 }
176 } 175 }
177 176
178 private: 177 private:
179 typedef skiagm::GM INHERITED; 178 typedef skiagm::GM INHERITED;
180 }; 179 };
181 180
182 //////////////////////////////////////////////////////////////////////////////// ///// 181 //////////////////////////////////////////////////////////////////////////////// /////
183 182
184 DEF_GM(return new VerticesGM();) 183 DEF_GM(return new VerticesGM();)
OLDNEW
« no previous file with comments | « gm/transparency.cpp ('k') | gm/verylargebitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698