OLD | NEW |
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 sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) { | 14 static 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::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), | 21 return SkGradientShader::CreateLinear(pts, colors, nullptr, |
22 SkShader::kMirror_TileMode); | 22 SK_ARRAY_COUNT(colors), |
| 23 SkShader::kMirror_TileMode); |
23 } | 24 } |
24 | 25 |
25 static sk_sp<SkShader> make_shader2() { | 26 static SkShader* make_shader2() { |
26 return SkShader::MakeColorShader(SK_ColorBLUE); | 27 return SkShader::CreateColorShader(SK_ColorBLUE); |
27 } | 28 } |
28 | 29 |
29 static SkColorFilter* make_color_filter() { | 30 static SkColorFilter* make_color_filter() { |
30 return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode)
; | 31 return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode)
; |
31 } | 32 } |
32 | 33 |
33 class VerticesGM : public skiagm::GM { | 34 class VerticesGM : public skiagm::GM { |
34 SkPoint fPts[9]; | 35 SkPoint fPts[9]; |
35 SkPoint fTexs[9]; | 36 SkPoint fTexs[9]; |
36 SkColor fColors[9]; | 37 SkColor fColors[9]; |
37 sk_sp<SkShader> fShader1; | 38 SkAutoTUnref<SkShader> fShader1; |
38 sk_sp<SkShader> fShader2; | 39 SkAutoTUnref<SkShader> fShader2; |
39 SkAutoTUnref<SkColorFilter> fColorFilter; | 40 SkAutoTUnref<SkColorFilter> fColorFilter; |
40 | 41 |
41 public: | 42 public: |
42 VerticesGM() {} | 43 VerticesGM() {} |
43 | 44 |
44 protected: | 45 protected: |
45 | 46 |
46 void onOnceBeforeDraw() override { | 47 void onOnceBeforeDraw() override { |
47 const SkScalar X = 30; | 48 const SkScalar X = 30; |
48 const SkScalar Y = 30; | 49 const SkScalar Y = 30; |
49 | 50 |
50 fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0); | 51 fPts[0].set(0, 0); fPts[1].set(X/2, 3); fPts[2].set(X, 0); |
51 fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2); | 52 fPts[3].set(3, Y/2); fPts[4].set(X/2, Y/2); fPts[5].set(X-3, Y/2); |
52 fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y); | 53 fPts[6].set(0, Y); fPts[7].set(X/2, Y-3); fPts[8].set(X, Y); |
53 | 54 |
54 const SkScalar w = 40; | 55 const SkScalar w = 40; |
55 const SkScalar h = 40; | 56 const SkScalar h = 40; |
56 | 57 |
57 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0); | 58 fTexs[0].set(0, 0); fTexs[1].set(w/2, 0); fTexs[2].set(w, 0); |
58 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2); | 59 fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2); |
59 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h); | 60 fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h); |
60 | 61 |
61 fShader1 = make_shader1(w, h); | 62 fShader1.reset(make_shader1(w, h)); |
62 fShader2 = make_shader2(); | 63 fShader2.reset(make_shader2()); |
63 fColorFilter.reset(make_color_filter()); | 64 fColorFilter.reset(make_color_filter()); |
64 | 65 |
65 SkRandom rand; | 66 SkRandom rand; |
66 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) { | 67 for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) { |
67 fColors[i] = rand.nextU() | 0xFF000000; | 68 fColors[i] = rand.nextU() | 0xFF000000; |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
71 SkString onShortName() override { | 72 SkString onShortName() override { |
72 SkString name("vertices"); | 73 SkString name("vertices"); |
73 return name; | 74 return name; |
74 } | 75 } |
75 | 76 |
76 SkISize onISize() override { | 77 SkISize onISize() override { |
77 return SkISize::Make(600, 600); | 78 return SkISize::Make(600, 600); |
78 } | 79 } |
79 | 80 |
80 void onDraw(SkCanvas* canvas) override { | 81 void onDraw(SkCanvas* canvas) override { |
81 // start with the center of a 3x3 grid | 82 // start with the center of a 3x3 grid |
82 static const uint16_t fan[] = { | 83 static const uint16_t fan[] = { |
83 4, | 84 4, |
84 0, 1, 2, 5, 8, 7, 6, 3, 0 | 85 0, 1, 2, 5, 8, 7, 6, 3, 0 |
85 }; | 86 }; |
86 | 87 |
87 const struct { | 88 const struct { |
88 const SkColor* fColors; | 89 const SkColor* fColors; |
89 const SkPoint* fTexs; | 90 const SkPoint* fTexs; |
90 const sk_sp<SkShader>& fShader; | 91 SkShader* fShader; |
91 SkColorFilter* fColorFilter; | 92 SkColorFilter* fColorFilter; |
92 uint8_t fAlpha; | 93 uint8_t fAlpha; |
93 } rec[] = { | 94 } rec[] = { |
94 { fColors, nullptr, fShader1, nullptr , 0xFF }, | 95 { fColors, nullptr, fShader1, nullptr , 0xFF }, |
95 { nullptr, fTexs , fShader1, nullptr , 0xFF }, | 96 { nullptr, fTexs , fShader1, nullptr , 0xFF }, |
96 { fColors, fTexs , fShader1, nullptr , 0xFF }, | 97 { fColors, fTexs , fShader1, nullptr , 0xFF }, |
97 { fColors, nullptr, fShader2, nullptr , 0xFF }, | 98 { fColors, nullptr, fShader2, nullptr , 0xFF }, |
98 { nullptr, fTexs , fShader2, nullptr , 0xFF }, | 99 { nullptr, fTexs , fShader2, nullptr , 0xFF }, |
99 { fColors, fTexs , fShader2, nullptr , 0xFF }, | 100 { fColors, fTexs , fShader2, nullptr , 0xFF }, |
100 { fColors, nullptr, fShader1, fColorFilter, 0xFF }, | 101 { fColors, nullptr, fShader1, fColorFilter, 0xFF }, |
101 { nullptr, fTexs , fShader1, fColorFilter, 0xFF }, | 102 { nullptr, fTexs , fShader1, fColorFilter, 0xFF }, |
102 { fColors, fTexs , fShader1, fColorFilter, 0xFF }, | 103 { fColors, fTexs , fShader1, fColorFilter, 0xFF }, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 175 } |
175 } | 176 } |
176 | 177 |
177 private: | 178 private: |
178 typedef skiagm::GM INHERITED; | 179 typedef skiagm::GM INHERITED; |
179 }; | 180 }; |
180 | 181 |
181 ////////////////////////////////////////////////////////////////////////////////
///// | 182 ////////////////////////////////////////////////////////////////////////////////
///// |
182 | 183 |
183 DEF_GM(return new VerticesGM();) | 184 DEF_GM(return new VerticesGM();) |
OLD | NEW |