63 bool allowRasterFallback =
true) {
65 paint.setShader(std::move(shader));
70 if (allowRasterFallback && !
surface) {
102 "uniform float xScale; uniform float xBias;"
103 "uniform float yScale; uniform float yBias;"
104 "half4 main(float2 p) {"
105 " const float2 v1 = float2(1);"
106 " const float2 v2 = float2(2);"
107 " p = float2(p.x, 1 - p.x) * xScale + xBias;"
109 " int2 pi = int2(floor(p));"
111 " float y = float(%s) * yScale + yBias;"
114 requireES3 ?
"300" :
"100", fn);
124 const char* label =
nullptr,
125 bool requireES3 =
false) {
137 builder.uniform(
"xScale") = xMax - xMin;
138 builder.uniform(
"xBias") = xMin;
139 builder.uniform(
"yScale") = 1.0f / (yMax - yMin);
140 builder.uniform(
"yBias") = -yMin / (yMax - yMin);
146 SkPaint plotPaint({ 0.0f, 0.5f, 0.0f, 1.0f });
151 pts[
x].set(
x + 0.5f,
y);
153 plotPaint.setAntiAlias(
true);
167 const char* label =
nullptr) {
168 plot(canvas, fn, xMin, xMax, yMin, yMax, label,
true);
181 plot(canvas,
"radians(x)", 0.0f, 360.0f, 0.0f, kTwoPI);
182 plot(canvas,
"degrees(x)", 0.0f, kTwoPI, 0.0f, 360.0f);
185 plot(canvas,
"sin(x)", 0.0f, kTwoPI, -1.0f, 1.0f);
186 plot(canvas,
"cos(x)", 0.0f, kTwoPI, -1.0f, 1.0f);
187 plot(canvas,
"tan(x)", 0.0f, kPI, -10.0f, 10.0f);
190 plot(canvas,
"asin(x)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo);
191 plot(canvas,
"acos(x)", -1.0f, 1.0f, 0.0f, kPI);
192 plot(canvas,
"atan(x)", -10.0f, 10.0f, -kPIOverTwo, kPIOverTwo);
195 plot(canvas,
"atan(0.1, x)", -1.0f, 1.0f, 0.0f, kPI);
196 plot(canvas,
"atan(-0.1, x)", -1.0f, 1.0f, -kPI, 0.0f);
199 plot(canvas,
"atan(x, 0.1)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo);
200 plot(canvas,
"atan(x, -0.1)", -1.0f, 1.0f, -kPI, kPI);
206 ctx, canvas, errorMsg,
210 *errorMsg =
"SkSL 300 is not supported.";
217 plot_es3(canvas,
"sinh(x)", -2.0f, 2.0f, -4.0f, 4.0f);
218 plot_es3(canvas,
"cosh(x)", -2.0f, 2.0f, 0.0f, 4.0f);
219 plot_es3(canvas,
"tanh(x)", -2.0f, 2.0f, -1.0f, 1.0f);
222 if (ctx->priv().caps()->shaderCaps()->fInverseHyperbolicSupport) {
223 plot_es3(canvas,
"asinh(x)", -2.0f, 2.0f, -2.0f, 2.0f);
224 plot_es3(canvas,
"acosh(x)", 0.0f, 5.0f, 0.0f, 3.0f);
225 plot_es3(canvas,
"atanh(x)", -1.0f, 1.0f, -4.0f, 4.0f);
240 plot(canvas,
"pow(x, 3)", 0.0f, 8.0f, 0.0f, 500.0f);
241 plot(canvas,
"pow(x, -3)", 0.0f, 4.0f, 0.0f, 10.0f);
244 plot(canvas,
"pow(0.9, x)", -10.0f, 10.0f, 0.0f, 3.0f);
245 plot(canvas,
"pow(1.1, x)", -10.0f, 10.0f, 0.0f, 3.0f);
248 plot(canvas,
"exp(x)", -1.0f, 7.0f, 0.0f, 1000.0f);
249 plot(canvas,
"log(x)", 0.0f, 2.5f, -4.0f, 1.0f);
252 plot(canvas,
"exp2(x)", -1.0f, 7.0f, 0.0f, 130.0f);
253 plot(canvas,
"log2(x)", 0.0f, 4.0f, -4.0f, 2.0f);
256 plot(canvas,
"sqrt(x)", 0.0f, 25.0f, 0.0f, 5.0f);
257 plot(canvas,
"inversesqrt(x)", 0.0f, 25.0f, 0.2f, 4.0f);
269 plot(canvas,
"abs(x)", -10.0f, 10.0f, 0.0f, 10.0f);
270 plot(canvas,
"sign(x)", -1.0f, 1.0f, -1.5f, 1.5f);
273 plot(canvas,
"floor(x)", -3.0f, 3.0f, -4.0f, 4.0f);
274 plot(canvas,
"ceil(x)", -3.0f, 3.0f, -4.0f, 4.0f);
275 plot(canvas,
"fract(x)", -3.0f, 3.0f, 0.0f, 1.0f);
276 plot(canvas,
"mod(x, 2)", -4.0f, 4.0f, -2.0f, 2.0f,
"mod(scalar)");
277 plot(canvas,
"mod(p, -2).x", -4.0f, 4.0f, -2.0f, 2.0f,
"mod(mixed)" );
278 plot(canvas,
"mod(p, v2).x", -4.0f, 4.0f, -2.0f, 2.0f,
"mod(vector)");
281 plot(canvas,
"min(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f,
"min(scalar)");
282 plot(canvas,
"min(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f,
"min(mixed)" );
283 plot(canvas,
"min(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f,
"min(vector)");
284 plot(canvas,
"max(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f,
"max(scalar)");
285 plot(canvas,
"max(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f,
"max(mixed)" );
286 plot(canvas,
"max(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f,
"max(vector)");
289 plot(canvas,
"clamp(x, 1, 2)", 0.0f, 3.0f, 0.0f, 3.0f,
"clamp(scalar)");
290 plot(canvas,
"clamp(p, 1, 2).x", 0.0f, 3.0f, 0.0f, 3.0f,
"clamp(mixed)" );
291 plot(canvas,
"clamp(p, v1, v2).x", 0.0f, 3.0f, 0.0f, 3.0f,
"clamp(vector)");
292 plot(canvas,
"saturate(x)", -1.0f, 2.0f, -0.5f, 1.5f);
295 plot(canvas,
"mix(1, 2, x)", -1.0f, 2.0f, 0.0f, 3.0f,
"mix(scalar)");
296 plot(canvas,
"mix(v1, v2, x).x", -1.0f, 2.0f, 0.0f, 3.0f,
"mix(mixed)" );
297 plot(canvas,
"mix(v1, v2, p).x", -1.0f, 2.0f, 0.0f, 3.0f,
"mix(vector)");
300 plot(canvas,
"step(1, x)", 0.0f, 2.0f, -0.5f, 1.5f,
"step(scalar)");
301 plot(canvas,
"step(1, p).x", 0.0f, 2.0f, -0.5f, 1.5f,
"step(mixed)" );
302 plot(canvas,
"step(v1, p).x", 0.0f, 2.0f, -0.5f, 1.5f,
"step(vector)");
303 plot(canvas,
"smoothstep(1, 2, x)", 0.5f, 2.5f, -0.5f, 1.5f,
"smooth(scalar)");
304 plot(canvas,
"smoothstep(1, 2, p).x", 0.5f, 2.5f, -0.5f, 1.5f,
"smooth(mixed)" );
305 plot(canvas,
"smoothstep(v1, v2, p).x", 0.5f, 2.5f, -0.5f, 1.5f,
"smooth(vector)");
308 plot(canvas,
"floor(p).x", -3.0f, 3.0f, -4.0f, 4.0f);
309 plot(canvas,
"ceil(p).x", -3.0f, 3.0f, -4.0f, 4.0f);
310 plot(canvas,
"floor(p).y", -3.0f, 3.0f, -4.0f, 4.0f);
311 plot(canvas,
"ceil(p).y", -3.0f, 3.0f, -4.0f, 4.0f);
317 ctx, canvas, errorMsg,
321 *errorMsg =
"SkSL 300 is not supported.";
328 plot_es3(canvas,
"floatBitsToInt(x)", -2, 2, -2'000'000'000, 2'000'000'000,
329 "floatBitsToInt(s)");
330 plot_es3(canvas,
"floatBitsToInt(p).x", -2, 2, -2'000'000'000, 2'000'000'000,
331 "floatBitsToInt(v)");
332 plot_es3(canvas,
"floatBitsToUint(x)", -2, 2, 0, 4'000'000'000,
333 "floatBitsToUint(s)");
334 plot_es3(canvas,
"floatBitsToUint(p).x", -2, 2, 0, 4'000'000'000,
335 "floatBitsToUint(v)");
338 plot_es3(canvas,
"intBitsToFloat(xi)", -2'000'000'000, 2'000'000'000, -2, 2,
339 "intBitsToFloat(s)");
340 plot_es3(canvas,
"intBitsToFloat(pi).x", -2'000'000'000, 2'000'000'000, -2, 2,
341 "intBitsToFloat(v)");
342 plot_es3(canvas,
"uintBitsToFloat(uint(xi))", 0, 4'000'000'000, -2, 2,
343 "uintBitsToFloat(s)");
344 plot_es3(canvas,
"uintBitsToFloat(uint2(pi)).x", 0, 4'000'000'000, -2, 2,
345 "uintBitsToFloat(v)");
348 plot_es3(canvas,
"trunc(x)", -2, 2, -3, 3);
349 plot_es3(canvas,
"trunc(p).x", -2, 2, -3, 3);
350 plot_es3(canvas,
"round(x)", -2, 2, -3, 3);
351 plot_es3(canvas,
"round(p).x", -2, 2, -3, 3);
352 plot_es3(canvas,
"roundEven(x)", -2, 2, -3, 3);
353 plot_es3(canvas,
"roundEven(p).x", -2, 2, -3, 3);
356 plot_es3(canvas,
"min(xi, 1)", -2, 5, -3, 5,
"min(int-scalar)");
357 plot_es3(canvas,
"min(pi, 1).x", -2, 5, -3, 5,
"min(int-mixed)" );
358 plot_es3(canvas,
"min(pi, int2(1)).x", -2, 5, -3, 5,
"min(int-vector)");
359 plot_es3(canvas,
"max(xi, 1)", -2, 5, -3, 5,
"max(int-scalar)");
360 plot_es3(canvas,
"max(pi, 1).x", -2, 5, -3, 5,
"max(int-mixed)" );
361 plot_es3(canvas,
"max(pi, int2(1)).x", -2, 5, -3, 5,
"max(int-vector)");
364 plot_es3(canvas,
"clamp(xi, 1, 3)", -1, 5, -1, 5,
"clamp(int-scalar)");
365 plot_es3(canvas,
"clamp(pi, 1, 3).x", -1, 5, -1, 5,
"clamp(int-mixed)" );
366 plot_es3(canvas,
"clamp(pi, int2(1), int2(3)).x", -1, 5, -1, 5,
"clamp(int-vector)");
367 plot_es3(canvas,
"mix(p.x, p.y, (x>0) )", -1, 2, 0, 3,
"mix(scalar, bool)");
368 plot_es3(canvas,
"mix(p.yx, p, (x>0).xx).x", -1, 2, 0, 3,
"mix(vector, bool)");
383 plot(canvas,
"length(x)", -1.0f, 1.0f, -0.5f, 1.5f);
384 plot(canvas,
"length(p)", 0.0f, 1.0f, 0.5f, 1.5f);
385 plot(canvas,
"distance(x, 0)", -1.0f, 1.0f, -0.5f, 1.5f);
386 plot(canvas,
"distance(p, v1)", 0.0f, 1.0f, 0.5f, 1.5f);
389 plot(canvas,
"dot(x, 2)", -1.0f, 1.0f, -2.5f, 2.5f);
390 plot(canvas,
"dot(p, p.y1)", -1.0f, 1.0f, -2.5f, 0.5f);
393 plot(canvas,
"cross(p.xy1, p.y1x).x", 0.0f, 1.0f, -1.0f, 1.0f);
394 plot(canvas,
"cross(p.xy1, p.y1x).y", 0.0f, 1.0f, -1.0f, 1.0f);
395 plot(canvas,
"cross(p.xy1, p.y1x).z", 0.0f, 1.0f, -1.0f, 1.0f);
398 plot(canvas,
"normalize(x)", -2.0f, 2.0f, -1.5f, 1.5f);
399 plot(canvas,
"normalize(p).x", 0.0f, 2.0f, 0.0f, 1.0f);
400 plot(canvas,
"normalize(p).y", 0.0f, 2.0f, 0.0f, 1.0f);
401 plot(canvas,
"faceforward(v1, p.x0, v1.x0).x", -1.0f, 1.0f, -1.5f, 1.5f,
"faceforward");
404 plot(canvas,
"reflect(p.x1, v1.0x).x", -1.0f, 1.0f, -1.0f, 1.0f,
"reflect(horiz)");
405 plot(canvas,
"reflect(p.x1, normalize(v1)).y", -1.0f, 1.0f, -1.0f, 1.0f,
"reflect(diag)" );
406 plot(canvas,
"refract(v1.x0, v1.0x, x).x", 0.0f, 1.0f, -1.0f, 1.0f,
"refract().x");
407 plot(canvas,
"refract(v1.x0, v1.0x, x).y", 0.0f, 1.0f, -1.0f, 1.0f,
"refract().y");
411#define SKSL_MATRIX_SELECTORS \
412 "inline float2 sel2(float x) {" \
414 " x < 0.5 ? 1 : 0," \
415 " x >= 0.5 ? 1 : 0);" \
417 "inline float3 sel3(float x) {" \
419 " x < 0.33 ? 1 : 0," \
420 " x >= 0.33 && x < 0.66 ? 1 : 0," \
421 " x >= 0.66 ? 1 : 0);" \
423 "inline float4 sel4(float x) {" \
425 " x < 0.25 ? 1 : 0," \
426 " x >= 0.25 && x < 0.5 ? 1 : 0," \
427 " x >= 0.5 && x < 0.75 ? 1 : 0," \
428 " x >= 0.75 ? 1 : 0);" \
434 "uniform float%dx%d m1;"
435 "uniform float%dx%d m2;"
437 "half4 main(float2 p) {"
438 " float%d colSel = sel%d(p.x);"
439 " float%d rowSel = sel%d(p.y);"
440 " float%d col = matrixCompMult(m1, m2) * colSel;"
441 " float v = dot(col, rowSel);"
443 "}", dim, dim, dim, dim, dim, dim, dim, dim, dim);
448 std::array<float, N*N> mtx1,
449 std::array<float, N*N> mtx2,
474 "uniform float scale; uniform float bias;"
475 "uniform float%dx%d m;"
477 "half4 main(float2 p) {"
478 " float%d colSel = sel%d(p.x);"
479 " float%d rowSel = sel%d(p.y);"
480 " float%d col = inverse(m) * colSel;"
481 " float v = dot(col, rowSel) * scale + bias;"
483 "}", dim, dim, dim, dim, dim, dim, dim);
499 builder.uniform(
"scale") = 0.5f;
500 builder.uniform(
"bias") = 0.5f;
518 plot_matrix_comp_mult<2>(canvas,
519 {1.00f, 0.0f, 2.0f, 0.5f},
520 {0.75f, 2.0f, 0.2f, 1.2f},
523 plot_matrix_comp_mult<3>(canvas,
524 {1.00f, 0.0f, 2.0f, 0.5f, -1.0f, -2.0f, -0.5f, 4.00f, 0.25f},
525 {0.75f, 2.0f, 0.2f, 1.2f, -0.8f, -0.1f, -1.8f, 0.25f, 2.00f},
528 plot_matrix_comp_mult<4>(canvas,
529 {1.00f, 0.0f, 2.0f, 0.5f, -1.0f, -2.0f, -0.5f, 4.00f, 0.25f, 0.05f,
530 10.00f, -0.66f, -1.0f, -0.5f, 0.5f, 0.66f},
531 {0.75f, 2.0f, 0.2f, 1.2f, -0.8f, -0.1f, -1.8f, 0.25f, 2.00f, 2.00f,
532 0.03f, -1.00f, -1.0f, -0.5f, 1.7f, 0.66f},
537 plot_matrix_inverse<2>(canvas,
542 plot_matrix_inverse<3>(canvas,
543 {-1.13f, -2.96f, -0.14f,
544 1.45f, -1.88f, -1.02f,
545 -2.54f, -2.58f, -1.17f},
548 plot_matrix_inverse<4>(canvas,
549 {-1.51f, -3.95f, -0.19f, 1.93f,
550 -2.51f, -1.35f, -3.39f, -3.45f,
551 -1.56f, 1.61f, -0.22f, -1.08f,
552 -2.81f, -2.14f, -0.09f, 3.00f},
565 "half4 main(float2 p) {"
566 " p.x = p.x < 0.33 ? -3.0 : (p.x < 0.66 ? -2.0 : -1.0);"
567 " p.y = p.y < 0.33 ? -3.0 : (p.y < 0.66 ? -2.0 : -1.0);"
569 " return half4(cmp.x ? 1.0 : 0.0, cmp.y ? 1.0 : 0.0, 0, 1);"
574template <
typename T =
float>
587 T uniformData[2] = { -2, -2 };
590 draw_shader(canvas, effect->makeShader(uniforms, {}));
604 plot_bvec<float>(canvas,
"lessThan(p, v1)",
"lessThan");
605 plot_bvec<int> (canvas,
"lessThan(int2(p), v1)",
"lessThan(int)");
606 plot_bvec<float>(canvas,
"lessThanEqual(p, v1)",
"lessThanEqual");
607 plot_bvec<int> (canvas,
"lessThanEqual(int2(p), v1)",
"lessThanEqual(int)");
610 plot_bvec<float>(canvas,
"greaterThan(p, v1)",
"greaterThan");
611 plot_bvec<int> (canvas,
"greaterThan(int2(p), v1)",
"greaterThan(int)");
612 plot_bvec<float>(canvas,
"greaterThanEqual(p, v1)",
"greaterThanEqual");
613 plot_bvec<int> (canvas,
"greaterThanEqual(int2(p), v1)",
"greaterThanEqual(int)");
616 plot_bvec<float>(canvas,
"equal(p, v1)",
"equal");
617 plot_bvec<int> (canvas,
"equal(int2(p), v1)",
"equal(int)");
618 plot_bvec<float>(canvas,
"notEqual(p, v1)",
"notEqual");
619 plot_bvec<int> (canvas,
"notEqual(int2(p), v1)",
"notEqual(int)");
622 plot_bvec(canvas,
"equal( lessThanEqual(p, v1), greaterThanEqual(p, v1))",
"equal(bvec)");
623 plot_bvec(canvas,
"notEqual(lessThanEqual(p, v1), greaterThanEqual(p, v1))",
"notequal(bvec)");
626 plot_bvec(canvas,
"not(notEqual(p, v1))",
"not(notEqual)");
627 plot_bvec(canvas,
"not(equal(p, v1))",
"not(equal)");
630 plot_bvec(canvas,
"bool2(any(equal(p, v1)))",
"any(equal)");
631 plot_bvec(canvas,
"bool2(all(equal(p, v1)))",
"all(equal)");
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SkColorGetR(color)
constexpr SkColor SK_ColorWHITE
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
constexpr float SK_FloatPI
@ kUTF8
uses bytes to represent UTF-8 or ASCII
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
@ kPolygon_PointMode
draw the array of points as a open polygon
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
static Result MakeForShader(SkString sksl, const Options &)
const uint8_t uint32_t uint32_t GError ** error
constexpr SkColor4f kBlack
Optional< SkRect > bounds
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
font
Font Metadata and Metrics.
static void plot_matrix_comp_mult(SkCanvas *canvas, std::array< float, N *N > mtx1, std::array< float, N *N > mtx2, const char *label)
static SkString make_unary_sksl_1d(const char *fn, bool requireES3)
static void plot_matrix_inverse(SkCanvas *canvas, std::array< float, N *N > mtx, const char *label)
static SkString make_matrix_comp_mult_sksl(int dim)
static constexpr int kPadding
static void next_row(SkCanvas *canvas)
#define SKSL_MATRIX_SELECTORS
DEF_SIMPLE_GM(runtime_intrinsics_trig, canvas, columns_to_width(3), rows_to_height(5))
static SkBitmap draw_shader(SkCanvas *canvas, sk_sp< SkShader > shader, bool allowRasterFallback=true)
static void plot_es3(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr)
static constexpr int kLabelHeight
static void plot_bvec(SkCanvas *canvas, const char *fn, const char *label)
static void draw_label(SkCanvas *canvas, const char *label)
static SkString make_bvec_sksl(const char *type, const char *fn)
static constexpr int columns_to_width(int columns)
static constexpr int rows_to_height(int rows)
static constexpr int kBoxSize
static void next_column(SkCanvas *canvas)
DEF_SIMPLE_GPU_GM_CAN_FAIL(runtime_intrinsics_trig_es3, ctx, canvas, errorMsg, columns_to_width(3), rows_to_height(2))
static void plot(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr, bool requireES3=false)
static SkString make_matrix_inverse_sksl(int dim)
static SkImageInfo MakeN32Premul(int width, int height)