Flutter Engine
The Flutter Engine
Functions
SkSL_EvaluatingNestedShaders.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (SkSL_EvaluatingNestedShaders, 128, 128, false, 5)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( SkSL_EvaluatingNestedShaders  ,
128  ,
128  ,
false  ,
 
)

Definition at line 4 of file SkSL_EvaluatingNestedShaders.cpp.

4 {
5// Create a linear gradient from white (left) to black (right)
6sk_sp<SkShader> makeGradientShader() {
7 const char* sksl =
8 "half4 main(float2 coord) {"
9 " float t = coord.x / 128;"
10 " half4 white = half4(1);"
11 " half4 black = half4(0,0,0,1);"
12 " return mix(white, black, t);"
13 "}";
14 auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
15 return effect->makeShader(/*uniforms=*/ nullptr, /*children=*/ {});
16}
17
18void draw(SkCanvas* canvas) {
19 // Turn `image` into an SkShader:
21
22 const char* sksl =
23 "uniform shader input_1;"
24 "uniform shader input_2;"
25 "half4 main(float2 coord) {"
26 " return input_1.eval(coord) * input_2.eval(coord);"
27 "}";
28 SkRuntimeEffect::ChildPtr children[] = { /*input_1=*/ imageShader,
29 /*input_2=*/ makeGradientShader() };
30
31 // Create SkShader from SkSL, then fill surface: // SK_FOLD_START
32
33 // Create an SkShader from our SkSL, with `children` bound to the inputs:
34 auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
35 sk_sp<SkShader> myShader = effect->makeShader(/*uniforms=*/ nullptr,
36 /*children=*/ children);
37
38 // Fill the surface with `myShader`:
39 SkPaint p;
40 p.setShader(myShader);
41 canvas->drawPaint(p);
42 // SK_FOLD_END
43}} // END FIDDLE
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
static Result MakeForShader(SkString sksl, const Options &)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions(SkFilterMode::kLinear))