171 {
172 const CircularRRectEffect& crre =
args.fFp.cast<CircularRRectEffect>();
174 const char *rectName;
175 const char *radiusPlusHalfName;
176
177
178
179
181 "innerRect", &rectName);
182
185 &radiusPlusHalfName);
186
187
189 if (!
args.fShaderCaps->fFloatIs32Bits) {
190 clampedCircleDistance.
printf(
"saturate(%s.x * (1.0 - length(dxy * %s.y)))",
191 radiusPlusHalfName, radiusPlusHalfName);
192 } else {
193 clampedCircleDistance.
printf(
"saturate(%s.x - length(dxy))", radiusPlusHalfName);
194 }
195
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 switch (crre.fCircularCornerFlags) {
213 case CircularRRectEffect::kAll_CornerFlags:
214 fragBuilder->
codeAppendf(
"float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName);
215 fragBuilder->
codeAppendf(
"float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName);
216 fragBuilder->
codeAppend(
"float2 dxy = max(max(dxy0, dxy1), 0.0);");
217 fragBuilder->
codeAppendf(
"half alpha = half(%s);", clampedCircleDistance.
c_str());
218 break;
219 case CircularRRectEffect::kTopLeft_CornerFlag:
220 fragBuilder->
codeAppendf(
"float2 dxy = max(%s.LT - sk_FragCoord.xy, 0.0);",
221 rectName);
222 fragBuilder->
codeAppendf(
"half rightAlpha = half(saturate(%s.R - sk_FragCoord.x));",
223 rectName);
224 fragBuilder->
codeAppendf(
"half bottomAlpha = half(saturate(%s.B - sk_FragCoord.y));",
225 rectName);
226 fragBuilder->
codeAppendf(
"half alpha = bottomAlpha * rightAlpha * half(%s);",
227 clampedCircleDistance.
c_str());
228 break;
229 case CircularRRectEffect::kTopRight_CornerFlag:
230 fragBuilder->
codeAppendf(
"float2 dxy = max(float2(sk_FragCoord.x - %s.R, "
231 "%s.T - sk_FragCoord.y), 0.0);",
232 rectName, rectName);
233 fragBuilder->
codeAppendf(
"half leftAlpha = half(saturate(sk_FragCoord.x - %s.L));",
234 rectName);
235 fragBuilder->
codeAppendf(
"half bottomAlpha = half(saturate(%s.B - sk_FragCoord.y));",
236 rectName);
237 fragBuilder->
codeAppendf(
"half alpha = bottomAlpha * leftAlpha * half(%s);",
238 clampedCircleDistance.
c_str());
239 break;
240 case CircularRRectEffect::kBottomRight_CornerFlag:
241 fragBuilder->
codeAppendf(
"float2 dxy = max(sk_FragCoord.xy - %s.RB, 0.0);",
242 rectName);
243 fragBuilder->
codeAppendf(
"half leftAlpha = half(saturate(sk_FragCoord.x - %s.L));",
244 rectName);
245 fragBuilder->
codeAppendf(
"half topAlpha = half(saturate(sk_FragCoord.y - %s.T));",
246 rectName);
247 fragBuilder->
codeAppendf(
"half alpha = topAlpha * leftAlpha * half(%s);",
248 clampedCircleDistance.
c_str());
249 break;
250 case CircularRRectEffect::kBottomLeft_CornerFlag:
251 fragBuilder->
codeAppendf(
"float2 dxy = max(float2(%s.L - sk_FragCoord.x, "
252 "sk_FragCoord.y - %s.B), 0.0);",
253 rectName, rectName);
254 fragBuilder->
codeAppendf(
"half rightAlpha = half(saturate(%s.R - sk_FragCoord.x));",
255 rectName);
256 fragBuilder->
codeAppendf(
"half topAlpha = half(saturate(sk_FragCoord.y - %s.T));",
257 rectName);
258 fragBuilder->
codeAppendf(
"half alpha = topAlpha * rightAlpha * half(%s);",
259 clampedCircleDistance.
c_str());
260 break;
261 case CircularRRectEffect::kLeft_CornerFlags:
262 fragBuilder->
codeAppendf(
"float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName);
263 fragBuilder->
codeAppendf(
"float dy1 = sk_FragCoord.y - %s.B;", rectName);
264 fragBuilder->
codeAppend(
"float2 dxy = max(float2(dxy0.x, max(dxy0.y, dy1)), 0.0);");
265 fragBuilder->
codeAppendf(
"half rightAlpha = half(saturate(%s.R - sk_FragCoord.x));",
266 rectName);
267 fragBuilder->
codeAppendf(
"half alpha = rightAlpha * half(%s);",
268 clampedCircleDistance.
c_str());
269 break;
270 case CircularRRectEffect::kTop_CornerFlags:
271 fragBuilder->
codeAppendf(
"float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName);
272 fragBuilder->
codeAppendf(
"float dx1 = sk_FragCoord.x - %s.R;", rectName);
273 fragBuilder->
codeAppend(
"float2 dxy = max(float2(max(dxy0.x, dx1), dxy0.y), 0.0);");
274 fragBuilder->
codeAppendf(
"half bottomAlpha = half(saturate(%s.B - sk_FragCoord.y));",
275 rectName);
276 fragBuilder->
codeAppendf(
"half alpha = bottomAlpha * half(%s);",
277 clampedCircleDistance.
c_str());
278 break;
279 case CircularRRectEffect::kRight_CornerFlags:
280 fragBuilder->
codeAppendf(
"float dy0 = %s.T - sk_FragCoord.y;", rectName);
281 fragBuilder->
codeAppendf(
"float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName);
282 fragBuilder->
codeAppend(
"float2 dxy = max(float2(dxy1.x, max(dy0, dxy1.y)), 0.0);");
283 fragBuilder->
codeAppendf(
"half leftAlpha = half(saturate(sk_FragCoord.x - %s.L));",
284 rectName);
285 fragBuilder->
codeAppendf(
"half alpha = leftAlpha * half(%s);",
286 clampedCircleDistance.
c_str());
287 break;
288 case CircularRRectEffect::kBottom_CornerFlags:
289 fragBuilder->
codeAppendf(
"float dx0 = %s.L - sk_FragCoord.x;", rectName);
290 fragBuilder->
codeAppendf(
"float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName);
291 fragBuilder->
codeAppend(
"float2 dxy = max(float2(max(dx0, dxy1.x), dxy1.y), 0.0);");
292 fragBuilder->
codeAppendf(
"half topAlpha = half(saturate(sk_FragCoord.y - %s.T));",
293 rectName);
294 fragBuilder->
codeAppendf(
"half alpha = topAlpha * half(%s);",
295 clampedCircleDistance.
c_str());
296 break;
297 }
298
300 fragBuilder->
codeAppend(
"alpha = 1.0 - alpha;");
301 }
302
304
306}
SkString invokeChild(int childIndex, EmitArgs &parentArgs, std::string_view skslCoords={})
void codeAppend(const char *str)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void printf(const char format[],...) SK_PRINTF_LIKE(2
const char * c_str() const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args