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

Go to the source code of this file.

Functions

 REG_FIDDLE (SkSL_EvaluatingTwoShaders, 128, 128, false, 5)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( SkSL_EvaluatingTwoShaders  ,
128  ,
128  ,
false  ,
 
)

Definition at line 4 of file SkSL_EvaluatingTwoShaders.cpp.

4 {
5// Create a linear gradient from white (left) to black (right)
6sk_sp<SkShader> makeGradientShader() {
7 const SkPoint pts[] = { { 0, 0 }, { 128, 0 } };
10}
11
12void draw(SkCanvas* canvas) {
13 // Turn `image` into an SkShader:
15
16 const char* sksl =
17 "uniform shader input_1;"
18 "uniform shader input_2;"
19 "half4 main(float2 coord) {"
20 " return input_1.eval(coord) * input_2.eval(coord);"
21 "}";
22 SkRuntimeEffect::ChildPtr children[] = { /*input_1=*/ imageShader,
23 /*input_2=*/ makeGradientShader() };
24
25 // Create SkShader from SkSL, then fill surface: // SK_FOLD_START
26
27 // Create an SkShader from our SkSL, with `children` bound to the inputs:
28 auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
29 sk_sp<SkShader> myShader = effect->makeShader(/*uniforms=*/ nullptr,
30 /*children=*/ { children, 2 });
31
32 // Fill the surface with `myShader`:
33 SkPaint p;
34 p.setShader(myShader);
35 canvas->drawPaint(p);
36 // SK_FOLD_END
37}} // END FIDDLE
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
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
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkSamplingOptions(SkFilterMode::kLinear))