Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
25
void draw(SkCanvas* canvas) {
// Turn `image` into an SkShader:
sk_sp<SkShader> imageShader = image->makeShader(SkSamplingOptions(SkFilterMode::kLinear));
const char* sksl =
"uniform shader image;"
"half4 main(float2 coord) {"
" return image.eval(coord).bgra;" // Sample 'image', then swap red and blue
"}";
// Parse the SkSL, and create an SkRuntimeEffect object:
auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
// SkRuntimeEffect::makeShader expects an SkSpan<ChildPtr>, one per `uniform shader`:
SkRuntimeEffect::ChildPtr children[] = { imageShader };
// Create an SkShader from our SkSL, with `imageShader` bound to `image`:
sk_sp<SkShader> myShader = effect->makeShader(/*uniforms=*/ nullptr,
/*children=*/ { children, 1 });
// Fill the surface with `myShader`:
SkPaint p;
p.setShader(myShader);
canvas->drawPaint(p);
}