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

Side by Side Diff: gm/gradients_2pt_conical.cpp

Issue 1790353002: Revert of more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/gradients.cpp ('k') | gm/gradients_no_texture.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 2014 Google Inc. 2 * Copyright 2014 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 "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 10
(...skipping 19 matching lines...) Expand all
30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE 30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
31 }; 31 };
32 32
33 static const GradData gGradData[] = { 33 static const GradData gGradData[] = {
34 { 2, gColors, gPos0 }, 34 { 2, gColors, gPos0 },
35 { 2, gColors, gPos1 }, 35 { 2, gColors, gPos1 },
36 { 5, gColors, gPos2 }, 36 { 5, gColors, gPos2 },
37 { 4, gColorClamp, gPosClamp } 37 { 4, gColorClamp, gPosClamp }
38 }; 38 };
39 39
40 static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data, 40 static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
41 SkShader::TileMode tm, const SkMatrix & localMatrix) { 41 SkShader::TileMode tm, const SkMatrix& loca lMatrix) {
42 SkPoint center0, center1; 42 SkPoint center0, center1;
43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; 43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
44 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 44 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
47 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 47 return SkGradientShader::CreateTwoPointConical(center0, radius0,
48 data.fPos, data.fCount, tm, 0, &localMatrix); 48 center1, radius1,
49 } 49 data.fColors, data.fPos,
50 50 data.fCount, tm, 0, &localMat rix);
51 static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradD ata& data, 51 }
52
53 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d ata,
52 SkShader::TileMode tm, const SkMatrix& localMatrix) { 54 SkShader::TileMode tm, const SkMatrix& localMatrix) {
53 SkPoint center0, center1; 55 SkPoint center0, center1;
54 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; 56 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
55 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 57 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
56 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 58 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
57 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
58 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radi us0, data.fColors, 60 return SkGradientShader::CreateTwoPointConical(center1, radius1,
59 data.fPos, data.fCount, tm, 0, &localMatrix); 61 center0, radius0,
60 } 62 data.fColors, data.fPos,
61 63 data.fCount, tm, 0, &localMat rix);
62 static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data, 64 }
63 SkShader::TileMode tm, const SkMatrix& localMatrix) { 65
64 SkPoint center0, center1; 66 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
65 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 67 SkShader::TileMode tm, const SkMatrix& localMatrix) {
66 SkScalarAve(pts[0].fY, pts[1].fY)); 68 SkPoint center0, center1;
67 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 69 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
68 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 70 SkScalarAve(pts[0].fY, pts[1].fY));
69 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX ) / 7, 71 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
70 center0, (pts[1].fX - pts[0].fX ) / 2, 72 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
71 data.fColors, data.fPos, data.f Count, tm, 73 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 7,
72 0, &localMatrix); 74 center0, (pts[1].fX - pts[0]. fX) / 2,
73 } 75 data.fColors, data.fPos, data .fCount, tm,
74 76 0, &localMatrix);
75 static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradDa ta& data, 77 }
76 SkShader::TileMode tm, const SkMat rix& localMatrix) { 78
77 SkPoint center0, center1; 79 static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da ta,
78 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 80 SkShader::TileMode tm, const SkMatrix& localMatrix) {
79 SkScalarAve(pts[0].fY, pts[1].fY)); 81 SkPoint center0, center1;
80 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 82 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
81 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 83 SkScalarAve(pts[0].fY, pts[1].fY));
82 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX ) / 2, 84 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
83 center1, (pts[1].fX - pts[0].fX ) / 7, 85 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
84 data.fColors, data.fPos, data.f Count, tm, 86 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0]. fX) / 2,
85 0, &localMatrix); 87 center1, (pts[1].fX - pts[0]. fX) / 7,
86 } 88 data.fColors, data.fPos, data .fCount, tm,
87 89 0, &localMatrix);
88 static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const Grad Data& data, 90 }
89 SkShader::TileMode tm, const SkMatrix& localMatrix) { 91
90 SkPoint center0, center1; 92 static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
91 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 93 SkShader::TileMode tm, const SkMatrix& localMatrix) {
92 SkScalarAve(pts[0].fY, pts[1].fY)); 94 SkPoint center0, center1;
93 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 95 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
94 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 96 SkScalarAve(pts[0].fY, pts[1].fY));
95 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX ) / 7, 97 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
96 center0, (pts[1].fX - pts[0].fX ) / 2, 98 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
97 data.fColors, data.fPos, data.f Count, tm, 99 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0]. fX) / 7,
98 0, &localMatrix); 100 center0, (pts[1].fX - pts[0]. fX) / 2,
99 } 101 data.fColors, data.fPos, data .fCount, tm,
100 102 0, &localMatrix);
101 static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data, 103 }
102 SkShader::TileMode tm, const SkMatrix & localMatrix) { 104
103 SkPoint center0, center1; 105 static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
104 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 106 SkShader::TileMode tm, const SkMatrix& localMatrix) {
105 SkScalarAve(pts[0].fY, pts[1].fY)); 107 SkPoint center0, center1;
106 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 108 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
107 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 109 SkScalarAve(pts[0].fY, pts[1].fY));
108 return SkGradientShader::MakeTwoPointConical(center1, 0.f, 110 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
109 center0, (pts[1].fX - pts[0].fX ) / 2, 111 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
110 data.fColors, data.fPos, data.f Count, tm, 112 return SkGradientShader::CreateTwoPointConical(center1, 0.f,
111 0, &localMatrix); 113 center0, (pts[1].fX - pts[0]. fX) / 2,
112 } 114 data.fColors, data.fPos, data .fCount, tm,
113 115 0, &localMatrix);
114 static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradD ata& data, 116 }
115 SkShader::TileMode tm, const SkMa trix& localMatrix) { 117
116 SkPoint center0, center1; 118 static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d ata,
117 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 119 SkShader::TileMode tm, const SkMatrix& localMatrix) {
118 SkScalarAve(pts[0].fY, pts[1].fY)); 120 SkPoint center0, center1;
119 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 121 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
120 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 122 SkScalarAve(pts[0].fY, pts[1].fY));
121 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX ) / 2, 123 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
122 center0, 0.f, 124 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
123 data.fColors, data.fPos, data.f Count, tm, 125 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 2,
124 0, &localMatrix); 126 center0, 0.f,
125 } 127 data.fColors, data.fPos, data .fCount, tm,
126 128 0, &localMatrix);
127 static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const Gra dData& data, 129 }
128 SkShader::TileMode tm, const SkMatrix& localMatrix) { 130
129 SkPoint center0, center1; 131 static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
130 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 132 SkShader::TileMode tm, const SkMatrix& localMatrix) {
131 SkScalarAve(pts[0].fY, pts[1].fY)); 133 SkPoint center0, center1;
132 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 134 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
133 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 135 SkScalarAve(pts[0].fY, pts[1].fY));
134 return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1]. fX - pts[0].fX) / 2, 136 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
135 data.fColors, data.fPos, data.f Count, tm, 137 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
136 0, &localMatrix); 138 return SkGradientShader::CreateTwoPointConical(center0, 0.f,
137 } 139 center0, (pts[1].fX - pts[0]. fX) / 2,
138 140 data.fColors, data.fPos, data .fCount, tm,
139 static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const Gr adData& data, 141 0, &localMatrix);
140 SkShader::TileMode tm, 142 }
141 const SkMatrix& localMatrix) { 143
142 SkPoint center0, center1; 144 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData & data,
143 SkScalar radius0 = 0.f; 145 SkShader::TileMode tm, const SkMatrix& localMatrix) {
144 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 146 SkPoint center0, center1;
145 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 147 SkScalar radius0 = 0.f;
146 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 148 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
147 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, 149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
148 data.fColors, data.fPos, 150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
149 data.fCount, tm, 0, &localMatri x); 151 return SkGradientShader::CreateTwoPointConical(center0, radius0,
150 } 152 center1, radius1,
151 153 data.fColors, data.fPos,
152 static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], cons t GradData& data, 154 data.fCount, tm, 0, &localMat rix);
153 SkShader::TileMode tm, 155 }
154 const SkMatrix& localMatri x) { 156
155 SkPoint center0, center1; 157 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad Data& data,
156 SkScalar radius0 = 0.f; 158 SkShader::TileMode tm, const SkMatrix& localMatrix) {
157 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 159 SkPoint center0, center1;
158 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 160 SkScalar radius0 = 0.f;
159 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 161 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
160 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radi us0, data.fColors, 162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
161 data.fPos, data.fCount, tm, 0, &localMatrix); 163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
162 } 164 return SkGradientShader::CreateTwoPointConical(center1, radius1,
163 165 center0, radius0,
164 static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& d ata, 166 data.fColors, data.fPos,
165 SkShader::TileMode tm, const SkMatrix& localMatrix) { 167 data.fCount, tm, 0, &localMat rix);
168 }
169
170 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
171 SkShader::TileMode tm, const SkMatrix& localMatrix) {
166 SkPoint center0, center1; 172 SkPoint center0, center1;
167 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; 173 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
168 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 174 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
169 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
170 SkScalarAve(pts[0].fY, pts[1].fY)); 176 SkScalarAve(pts[0].fY, pts[1].fY));
171 center0.set(center1.fX + radius1, center1.fY); 177 center0.set(center1.fX + radius1, center1.fY);
172 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 178 return SkGradientShader::CreateTwoPointConical(center0, radius0,
173 data.fPos, data.fCount, tm, 0, &localMatrix); 179 center1, radius1,
174 } 180 data.fColors, data.fPos,
175 181 data.fCount, tm, 0, &localMat rix);
176 static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& d ata, 182 }
177 SkShader::TileMode tm, const SkMatrix& localMatrix) { 183
184 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
185 SkShader::TileMode tm, const SkMatrix& localMatrix) {
178 SkPoint center0, center1; 186 SkPoint center0, center1;
179 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; 187 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
180 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 188 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
181 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
182 SkScalarAve(pts[0].fY, pts[1].fY)); 190 SkScalarAve(pts[0].fY, pts[1].fY));
183 center0.set(center1.fX, center1.fY + radius1); 191 center0.set(center1.fX, center1.fY + radius1);
184 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 192 return SkGradientShader::CreateTwoPointConical(center0, radius0,
185 data.fPos, data.fCount, tm, 0, &localMatrix); 193 center1, radius1,
186 } 194 data.fColors, data.fPos,
187 195 data.fCount, tm, 0, &localMat rix);
188 static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const Grad Data& data, 196 }
189 SkShader::TileMode tm, 197
190 const SkMatrix& localMatrix) { 198 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
199 SkShader::TileMode tm, const SkMatrix& localMatrix) {
191 SkPoint center0, center1; 200 SkPoint center0, center1;
192 SkScalar radius0 = 0.f; 201 SkScalar radius0 = 0.f;
193 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 202 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
194 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 203 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
195 SkScalarAve(pts[0].fY, pts[1].fY)); 204 SkScalarAve(pts[0].fY, pts[1].fY));
196 center0.set(center1.fX + radius1, center1.fY); 205 center0.set(center1.fX + radius1, center1.fY);
197 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 206 return SkGradientShader::CreateTwoPointConical(center0, radius0,
198 data.fPos, data.fCount, tm, 0, &localMatrix); 207 center1, radius1,
199 } 208 data.fColors, data.fPos,
200 209 data.fCount, tm, 0, &localMat rix);
201 static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const Grad Data& data, 210 }
202 SkShader::TileMode tm, const SkM atrix& localMatrix) { 211
212 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
213 SkShader::TileMode tm, const SkMatrix& localMatrix) {
203 SkPoint center0, center1; 214 SkPoint center0, center1;
204 SkScalar radius0 = 0.f; 215 SkScalar radius0 = 0.f;
205 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 216 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
206 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 217 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
207 SkScalarAve(pts[0].fY, pts[1].fY)); 218 SkScalarAve(pts[0].fY, pts[1].fY));
208 center0.set(center1.fX, center1.fY + radius1); 219 center0.set(center1.fX, center1.fY + radius1);
209 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 220 return SkGradientShader::CreateTwoPointConical(center0, radius0,
210 data.fPos, data.fCount, tm, 0, &localMatrix); 221 center1, radius1,
211 } 222 data.fColors, data.fPos,
212 223 data.fCount, tm, 0, &localMat rix);
213 static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, 224 }
214 SkShader::TileMode tm, const SkMatrix& localMatrix) { 225
226 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
227 SkShader::TileMode tm, const SkMatrix& localMatrix) {
215 SkPoint center0, center1; 228 SkPoint center0, center1;
216 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; 229 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
217 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 230 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
218 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 231 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
219 SkScalarAve(pts[0].fY, pts[1].fY)); 232 SkScalarAve(pts[0].fY, pts[1].fY));
220 center0.set(center1.fX - radius1 + radius0, center1.fY); 233 center0.set(center1.fX - radius1 + radius0, center1.fY);
221 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 234 return SkGradientShader::CreateTwoPointConical(center0, radius0,
222 data.fPos, data.fCount, tm, 0, &localMatrix); 235 center1, radius1,
223 } 236 data.fColors, data.fPos,
224 237 data.fCount, tm, 0, &localMat rix);
225 static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, 238 }
226 SkShader::TileMode tm, const SkMatrix& localMatrix) { 239
240 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
241 SkShader::TileMode tm, const SkMatrix& localMatrix) {
227 SkPoint center0, center1; 242 SkPoint center0, center1;
228 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; 243 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
229 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 244 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
230 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 245 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
231 SkScalarAve(pts[0].fY, pts[1].fY)); 246 SkScalarAve(pts[0].fY, pts[1].fY));
232 center0.set(center1.fX, center1.fY + radius1 - radius0); 247 center0.set(center1.fX, center1.fY + radius1 - radius0);
233 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radi us1, data.fColors, 248 return SkGradientShader::CreateTwoPointConical(center0, radius0,
234 data.fPos, data.fCount, tm, 0, &localMatrix); 249 center1, radius1,
235 } 250 data.fColors, data.fPos,
236 251 data.fCount, tm, 0, &localMat rix);
237 static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const Gr adData& data, 252 }
238 SkShader::TileMode tm, const SkMatrix& localMatrix) { 253
239 SkPoint center0, center1; 254 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData & data,
240 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 255 SkShader::TileMode tm, const SkMatrix& localMatrix) {
241 SkScalarAve(pts[0].fY, pts[1].fY)); 256 SkPoint center0, center1;
242 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 257 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
243 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 258 SkScalarAve(pts[0].fY, pts[1].fY));
244 return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f , 259 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
245 center0, (pts[1].fX - pts[0]. fX) / 2, 260 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
246 data.fColors, data.fPos, data .fCount, tm, 261 return SkGradientShader::CreateTwoPointConical(center0, 0.000000000000000000 1f,
247 0, &localMatrix); 262 center0, (pts[1].fX - pts[0]. fX) / 2,
248 } 263 data.fColors, data.fPos, data .fCount, tm,
249 264 0, &localMatrix);
250 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, 265 }
251 SkShader::TileMode tm, const SkMatrix& loca lMatrix); 266
267 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
268 SkShader::TileMode tm, const SkMatrix& localMatri x);
252 269
253 static const GradMaker gGradMakersOutside[] = { 270 static const GradMaker gGradMakersOutside[] = {
254 Make2ConicalOutside, Make2ConicalOutsideFlip, 271 Make2ConicalOutside, Make2ConicalOutsideFlip,
255 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside 272 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside
256 }; 273 };
257 274
258 static const GradMaker gGradMakersInside[] = { 275 static const GradMaker gGradMakersInside[] = {
259 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, 276 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
260 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, 277 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
261 }; 278 };
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { 340 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
324 canvas->save(); 341 canvas->save();
325 for (int j = 0; j < count; j++) { 342 for (int j = 0; j < count; j++) {
326 SkMatrix scale = SkMatrix::I(); 343 SkMatrix scale = SkMatrix::I();
327 344
328 if (i == 3) { // if the clamp case 345 if (i == 3) { // if the clamp case
329 scale.setScale(0.5f, 0.5f); 346 scale.setScale(0.5f, 0.5f);
330 scale.postTranslate(25.f, 25.f); 347 scale.postTranslate(25.f, 25.f);
331 } 348 }
332 349
333 paint.setShader(gradMaker[j](pts, gGradData[i], tm, scale)); 350 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale);
351 paint.setShader(shader);
334 canvas->drawRect(r, paint); 352 canvas->drawRect(r, paint);
353 shader->unref();
335 canvas->translate(0, SkIntToScalar(120)); 354 canvas->translate(0, SkIntToScalar(120));
336 } 355 }
337 canvas->restore(); 356 canvas->restore();
338 canvas->translate(SkIntToScalar(120), 0); 357 canvas->translate(SkIntToScalar(120), 0);
339 } 358 }
340 } 359 }
341 360
342 private: 361 private:
343 typedef GM INHERITED; 362 typedef GM INHERITED;
344 363
345 GradCaseType fGradCaseType; 364 GradCaseType fGradCaseType;
346 SkString fName; 365 SkString fName;
347 bool fDither; 366 bool fDither;
348 }; 367 };
349 /////////////////////////////////////////////////////////////////////////////// 368 ///////////////////////////////////////////////////////////////////////////////
350 369
351 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); ) 370 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); )
352 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); ) 371 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); )
353 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); ) 372 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); )
354 373
355 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); ) 374 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); )
356 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); ) 375 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); )
357 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); ) 376 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); )
358 377
359 } 378 }
OLDNEW
« no previous file with comments | « gm/gradients.cpp ('k') | gm/gradients_no_texture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698