54 fSecs = nanos / (1000 * 1000 * 1000);
73 half4 main(float2 p) {
74 return half4(p*(1.0/255), gColor.b, 1);
86 p.setShader(
builder.makeShader(&localM));
102 auto canvas = surf->getCanvas();
107 paint.setAntiAlias(
true);
113 canvas->saveLayer(
nullptr, &layerPaint);
116 for (
int i = 0;
i < 25; ++
i) {
120 canvas->translate(
x,
y);
121 canvas->drawCircle(0, 0, rad,
paint);
133 uniform shader before_map;
134 uniform shader after_map;
135 uniform shader threshold_map;
137 uniform float cutoff;
140 float smooth_cutoff(float x) {
141 x = x * slope + (0.5 - slope * cutoff);
142 return clamp(x, 0, 1);
145 half4 main(float2 xy) {
146 half4 before = before_map.eval(xy);
147 half4 after = after_map.eval(xy);
149 float m = smooth_cutoff(threshold_map.eval(xy).a);
150 return mix(before, after, m);
169 builder.uniform(
"slope") = 10.0f;
180 paint.setShader(shader);
196 uniform float rad_scale;
197 uniform float2 in_center;
198 layout(color) uniform float4 in_colors0;
199 layout(color) uniform float4 in_colors1;
201 half4 main(float2 p) {
202 float2 pp = p - in_center;
203 float radius = length(pp);
204 radius = sqrt(radius);
205 float angle = atan(pp.y / pp.x);
206 float t = (angle + 3.1415926/2) / (3.1415926);
207 t += radius * rad_scale;
209 return in_colors0 * (1-t) + in_colors1 * t;
216 builder.uniform(
"rad_scale") = std::sin(fSecs * 0.5f + 2.0f) / 5;
235 uniform shader child;
236 half4 main(float2 xy) {
237 half4 c = child.eval(xy) * 5;
238 c -= child.eval(xy + float2( 1, 0));
239 c -= child.eval(xy + float2(-1, 0));
240 c -= child.eval(xy + float2( 0, 1));
241 c -= child.eval(xy + float2( 0, -1));
273 uniform shader child;
274 uniform shader color_cube;
276 uniform float rg_scale;
277 uniform float rg_bias;
278 uniform float b_scale;
279 uniform float inv_size;
281 half4 main(float2 xy) {
282 float4 c = unpremul(child.eval(xy));
284 // Map to cube coords:
285 float3 cubeCoords = float3(c.rg * rg_scale + rg_bias, c.b * b_scale);
287 // Compute slice coordinate
288 float2 coords1 = float2((floor(cubeCoords.b) + cubeCoords.r) * inv_size, cubeCoords.g);
289 float2 coords2 = float2(( ceil(cubeCoords.b) + cubeCoords.r) * inv_size, cubeCoords.g);
291 // Two bilinear fetches, plus a manual lerp for the third axis:
292 half4 color = mix(color_cube.eval(coords1), color_cube.eval(coords2),
293 fract(cubeCoords.b));
296 color.rgb *= color.a;
318 canvas->
drawImage(fMandrillSepia, 0, 256);
321 constexpr float kSize = 16.0f;
357 uniform shader color_cube;
359 uniform float rg_scale;
360 uniform float rg_bias;
361 uniform float b_scale;
362 uniform float inv_size;
364 half4 main(half4 inColor) {
365 float4 c = unpremul(inColor);
367 // Map to cube coords:
368 float3 cubeCoords = float3(c.rg * rg_scale + rg_bias, c.b * b_scale);
370 // Compute slice coordinate
371 float2 coords1 = float2((floor(cubeCoords.b) + cubeCoords.r) * inv_size, cubeCoords.g);
372 float2 coords2 = float2(( ceil(cubeCoords.b) + cubeCoords.r) * inv_size, cubeCoords.g);
374 // Two bilinear fetches, plus a manual lerp for the third axis:
375 half4 color = mix(color_cube.eval(coords1), color_cube.eval(coords2),
376 fract(cubeCoords.b));
379 color.rgb *= color.a;
401 canvas->
drawImage(fMandrillSepia, 0, 256);
404 constexpr float kSize = 16.0f;
444 uniform float power_minus1;
445 uniform float2 stretch_factor;
446 uniform float2x2 derivatives;
447 half4 main(float2 xy) {
448 xy = max(abs(xy) + stretch_factor, 0);
449 float2 exp_minus1 = pow(xy, power_minus1.xx); // If power == 3.5: xy * xy * sqrt(xy)
450 float f = dot(exp_minus1, xy) - 1; // f = x^n + y^n - 1
451 float2 grad = exp_minus1 * derivatives;
452 float fwidth = abs(grad.x) + abs(grad.y) + 1e-12; // 1e-12 to avoid a divide by zero.
453 return half4(saturate(.5 - f/fwidth)); // Approx coverage by riding the gradient to f=0.
455 )"), fPower(power) {}
465 paint.setAntiAlias(
true);
471 builder.uniform(
"power_minus1") = fPower - 1;
478 float cornerWidth = radX *
scale;
479 float cornerHeight = radY *
scale;
480 cornerWidth =
std::min(cornerWidth, superRRect.
width() * .5f);
483 builder.uniform(
"stretch_factor") =
SkV2{1 - superRRect.
width()*.5f / cornerWidth,
484 1 - superRRect.
height()*.5f / cornerHeight};
502 float a=
M.getScaleX(),
b=
M.getSkewX(), c=
M.getSkewY(),
d=
M.getScaleY();
503 float determinant =
a*
d -
b*c;
504 float dx = fPower / (cornerWidth * determinant);
505 float dy = fPower / (cornerHeight * determinant);
520 float inverseDet = 1 / fabsf(determinant);
521 float bloatX = (fabsf(
d) + fabsf(c)) * inverseDet;
522 float bloatY = (fabsf(
b) + fabsf(
a)) * inverseDet;
535 rand.
nextU() | 0xff808080);
541 rand.
nextU() | 0xff808080);
547 rand.
nextU() | 0xff808080);
553 rand.
nextU() | 0xff808080);
559 rand.
nextU() | 0xff808080);
565 rand.
nextU() | 0xff808080);
571 rand.
nextU() | 0xff808080);
577 rand.
nextU() | 0xff808080);
596 layout(color) uniform vec4 in_colors0;
597 layout(color) uniform vec4 in_colors1;
602 return mix(in_colors0, in_colors1, t);
604 vec3 linColor0 = toLinearSrgb(in_colors0.rgb);
605 vec3 linColor1 = toLinearSrgb(in_colors1.rgb);
606 vec3 linColor = mix(linColor0, linColor1, t);
607 return fromLinearSrgb(linColor).rgb1;
648 static constexpr char scale[] =
649 "uniform shader child;"
650 "half4 main(float2 xy) {"
651 " return child.eval(xy*0.1);"
656 p.setAntiAlias(
true);
661 surf->getCanvas()->drawLine(0, 0, 100, 100,
p);
665 builder.child(
"child") = shader;
668 canvas->drawPaint(
p);
673 static const char* kSrc = R
"(
675 p = (p / 256) * 2 - 1;
676 float p2 = dot(p, p);
677 vec3 v = (p2 > 1) ? vec3(0, 0, 1) : vec3(p, sqrt(1 - p2));
678 return (v * 0.5 + 0.5).xyz1;
692 return surface->makeImageSnapshot();
711 for (
int x = 0;
x < pm.
width();
x++) {
728 static const char* kSrc = R
"(
729 uniform shader normals;
731 vec3 n = normalize(normals.eval(p).xyz * 2 - 1);
732 vec3 l = normalize(vec3(1, -1, 1));
733 return saturate(dot(n, l)).xxx1;
742 static const char* kSrc = R
"(
743 uniform shader normals;
745 vec3 n = normalize(normals.eval(p).xyz * 2 - 1);
746 vec3 l = normalize(vec3(1, -1, 1));
747 return fromLinearSrgb(saturate(dot(n, l)).xxx).xxx1;
766 canvas->translate(
x,
y);
767 canvas->clipRect({0, 0, 256, 256});
768 canvas->drawPaint(
p);
787 auto surface = canvas->makeSurface(surfInfo);
797 canvas->translate(
x,
y);
798 canvas->clipRect({0, 0, 256, 256});
799 canvas->drawPaint(
p);
837 auto surface = canvas->makeSurface(surfInfo);
847 canvas->translate(
x,
y);
848 canvas->clipRect({0, 0, 256, 256});
849 canvas->drawPaint(
p);
859 canvas->drawImage(
surface->makeImageSnapshot(), 0, 0);
866 half4 main(float2 p) { return s.eval(p); }
884 paint.setShader(imgShader);
885 canvas->drawRect(r,
paint);
890 paint.setShader(rte->makeShader(
nullptr, &imgShader, 1));
891 canvas->drawRect(r,
paint);
897 paint.setShader(imgShader->makeWithLocalMatrix(lm));
898 canvas->drawRect(r,
paint);
904 paint.setShader(rte->makeShader(
nullptr, &imgShader, 1)
905 ->makeWithLocalMatrix(lm));
906 canvas->drawRect(r,
paint);
919 half4 main(float2 p) { return s.eval(p) + half4(0.5, 0, 0.5, 1); }
926 paint.setShader(rtShader->makeShader(
nullptr, children));
928 canvas->drawRect({0, 0, 48, 48},
paint);
929 canvas->translate(50, 0);
935 uniform colorFilter cf;
936 half4 main(float2 p) { return cf.eval(half4(0.5, 0, 0.5, 1)); }
943 paint.setShader(rtShader->makeShader(
nullptr, children));
945 canvas->drawRect({0, 0, 48, 48},
paint);
946 canvas->translate(50, 0);
953 half4 main(float2 p) { return b.eval(half4(0.5, 0, 0, 0.5), half4(0, 0, 1, 1)); }
960 paint.setShader(rtShader->makeShader(
nullptr, children));
962 canvas->drawRect({0, 0, 48, 48},
paint);
963 canvas->translate(50, 0);
966 canvas->translate(-150, 50);
973 half4 main(half4 c) { return s.eval(float2(0)) + half4(0.5, 0, 0.5, 1); }
980 paint.setColorFilter(rtFilter->makeColorFilter(
nullptr, children));
982 canvas->drawRect({0, 0, 48, 48},
paint);
983 canvas->translate(50, 0);
989 uniform colorFilter cf;
990 half4 main(half4 c) { return cf.eval(half4(0.5, 0, 0.5, 1)); }
997 paint.setColorFilter(rtFilter->makeColorFilter(
nullptr, children));
999 canvas->drawRect({0, 0, 48, 48},
paint);
1000 canvas->translate(50, 0);
1007 half4 main(half4 c) { return b.eval(half4(0.5, 0, 0, 0.5), half4(0, 0, 1, 1)); }
1014 paint.setColorFilter(rtFilter->makeColorFilter(
nullptr, children));
1016 canvas->drawRect({0, 0, 48, 48},
paint);
1017 canvas->translate(50, 0);
1030 uniform half4 color;
1031 half4 main(float2 p) { return color; }
1048 paint.setShader(shader);
1050 for (
int i = 0;
i < 3; ++
i) {
1051 canvas->drawRect({0, 0, 50, 50},
paint);
1052 canvas->translate(50, 0);
1066 if (!canvas->getSurface()) {
1070 *errorMsg =
"Not supported in recording/DDL mode";
1084 paint.setColor({0.5f, 0, 0.5f, 1.0f});
1087 canvas->drawRect({0, 0, 48, 48},
paint);
1088 canvas->translate(50, 0);
1095 paint.setShader(paint_shader);
1105 "half4 main(float2 p) { return s.eval(p); }"))
1106 .effect->makeShader(
nullptr, children));
1110 paint.setShader(
nullptr);
1113 "half4 main(half4 color) { return s.eval(float2(0)); }"))
1114 .effect->makeColorFilter(
nullptr, children));
1121 paint.setShader(
nullptr);
1122 paint.setColorFilter(
nullptr);
1126 "half4 main(half4 src, half4 dst) { return s.eval(float2(0)); }"))
1127 .effect->makeBlender(
nullptr, children));
static SkM44 normals(SkM44 m)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
SkColorSpace * sk_srgb_singleton()
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kUnknown_SkColorType
uninitialized
constexpr SkColor SK_ColorRED
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
sk_sp< T > sk_ref_sp(T *obj)
#define SK_ScalarRoot2Over2
static constexpr bool SkToBool(const T &x)
void drawSuperRRect(SkCanvas *canvas, const SkRect &superRRect, float radX, float radY, SkColor color)
ClipSuperRRect(const char *name, float power)
void onDraw(SkCanvas *canvas) override
void onOnceBeforeDraw() override
sk_sp< SkImage > fIdentityCube
void onDraw(SkCanvas *canvas) override
void onDraw(SkCanvas *canvas) override
void onOnceBeforeDraw() override
sk_sp< SkImage > fIdentityCube
void onDraw(SkCanvas *canvas) override
SkISize getISize() override
RuntimeShaderGM(const char *name, SkISize size, const char *sksl, uint32_t flags=0)
void onOnceBeforeDraw() override
bool runAsBench() const override
sk_sp< SkRuntimeEffect > fEffect
bool onAnimate(double nanos) override
SkString getName() const override
void onDraw(SkCanvas *canvas) override
void allocPixels(const SkImageInfo &info, size_t rowBytes)
sk_sp< SkImage > asImage() const
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
uint32_t * getAddr32(int x, int y) const
void eraseColor(SkColor4f) const
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
void clear(SkColor color)
void rotate(SkScalar degrees)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
SkMatrix getTotalMatrix() const
void clipShader(sk_sp< SkShader >, SkClipOp=SkClipOp::kIntersect)
SkImageInfo imageInfo() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
static sk_sp< SkShader > MakeRadial(const SkPoint ¢er, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
const SkImageInfo & imageInfo() const
bool peekPixels(SkPixmap *pixmap) const
sk_sp< SkShader > makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
static SkMatrix Scale(SkScalar sx, SkScalar sy)
static SkMatrix RotateDeg(SkScalar deg)
void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
@ kStroke_Style
set to stroke geometry
const uint32_t * addr32() const
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
static sk_sp< SkShader > MakeDeferredShader(const SkRuntimeEffect *effect, UniformsCallback uniformsCallback, SkSpan< const SkRuntimeEffect::ChildPtr > children, const SkMatrix *localMatrix=nullptr)
sk_sp< SkShader > makeShader(sk_sp< const SkData > uniforms, sk_sp< SkShader > children[], size_t childCount, const SkMatrix *localMatrix=nullptr) const
static Result MakeForColorFilter(SkString sksl, const Options &)
static Result MakeForBlender(SkString sksl, const Options &)
static Result MakeForShader(SkString sksl, const Options &)
void onDraw(SkCanvas *canvas) override
void onDraw(SkCanvas *canvas) override
void onOnceBeforeDraw() override
sk_sp< SkShader > fBefore
sk_sp< SkShader > fThreshold
void onDraw(SkCanvas *canvas) override
void onOnceBeforeDraw() override
sk_sp< SkImage > fMandrill
DrawResult draw(SkCanvas *canvas)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
FlutterSemanticsFlag flags
const uint8_t uint32_t uint32_t GError ** error
static float min(float r, float g, float b)
constexpr SkColor4f kGreen
sk_sp< const SkImage > image
sk_sp< SkBlender > blender SkRect rect
PODArray< SkColor > colors
SkSamplingOptions sampling
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DEF_SWITCHES_START aot vmservice shared library name
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
SkSamplingOptions(SkFilterMode::kLinear))
SIN Vec< N, float > normalize(const Vec< N, float > &v)
static SkBitmap draw_shader(SkCanvas *canvas, sk_sp< SkShader > shader, bool allowRasterFallback=true)
static sk_sp< SkShader > make_shader(sk_sp< SkImage > img, SkISize size)
DEF_SIMPLE_GM_CAN_FAIL(deferred_shader_rt, canvas, errorMsg, 150, 50)
static sk_sp< SkShader > lit_shader(sk_sp< SkShader > normals)
static sk_sp< SkShader > normal_map_shader()
sk_sp< SkShader > paint_color_shader()
static sk_sp< SkShader > normal_map_raw_unpremul_image_shader()
static sk_sp< SkShader > normal_map_image_shader()
static sk_sp< SkShader > lit_shader_linear(sk_sp< SkShader > normals)
static sk_sp< SkShader > make_threshold(SkISize size)
static sk_sp< SkImage > normal_map_unpremul_image()
static sk_sp< SkShader > normal_map_unpremul_image_shader()
static sk_sp< SkShader > normal_map_raw_image_shader()
static sk_sp< SkImage > normal_map_image()
DEF_SIMPLE_GM(child_sampling_rt, canvas, 256, 256)
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkRect makeOutset(float dx, float dy) const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
constexpr float centerX() const
constexpr float height() const
constexpr float centerY() const
constexpr float width() const
static constexpr SkRect MakeWH(float w, float h)
sk_sp< SkRuntimeEffect > effect
static void checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)