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

Go to the source code of this file.

Functions

 REG_FIDDLE (SkSL_EvaluatingImageShader, 128, 128, false, 5)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( SkSL_EvaluatingImageShader  ,
128  ,
128  ,
false  ,
 
)

Definition at line 4 of file SkSL_EvaluatingImageShader.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 // Turn `image` into an SkShader:
8
9 const char* sksl =
10 "uniform shader image;"
11 "half4 main(float2 coord) {"
12 " return image.eval(coord).bgra;" // Sample 'image', then swap red and blue
13 "}";
14
15 // Parse the SkSL, and create an SkRuntimeEffect object:
16 auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
17
18 // SkRuntimeEffect::makeShader expects an SkSpan<ChildPtr>, one per `uniform shader`:
19 SkRuntimeEffect::ChildPtr children[] = { imageShader };
20
21 // Create an SkShader from our SkSL, with `imageShader` bound to `image`:
22 sk_sp<SkShader> myShader = effect->makeShader(/*uniforms=*/ nullptr,
23 /*children=*/ { children, 1 });
24
25 // Fill the surface with `myShader`:
26 SkPaint p;
27 p.setShader(myShader);
28 canvas->drawPaint(p);
29}} // 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))