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
39
// Create a linear gradient from white (left) to black (right)
sk_sp<SkShader> makeGradientShader() {
const char* sksl =
"half4 main(float2 coord) {"
" float t = coord.x / 128;"
" half4 white = half4(1);"
" half4 black = half4(0,0,0,1);"
" return mix(white, black, t);"
"}";
auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
return effect->makeShader(/*uniforms=*/ nullptr, /*children=*/ {});
}
void draw(SkCanvas* canvas) {
// Turn `image` into an SkShader:
sk_sp<SkShader> imageShader = image->makeShader(SkSamplingOptions(SkFilterMode::kLinear));
const char* sksl =
"uniform shader input_1;"
"uniform shader input_2;"
"half4 main(float2 coord) {"
" return input_1.eval(coord) * input_2.eval(coord);"
"}";
SkRuntimeEffect::ChildPtr children[] = { /*input_1=*/ imageShader,
/*input_2=*/ makeGradientShader() };
// Create SkShader from SkSL, then fill surface:
}