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
34
void draw(SkCanvas* canvas) {
// Make a very wide-gamut offscreen surface:
auto rec2020 = SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear,
SkNamedGamut::kRec2020);
auto info = SkImageInfo::Make(128, 64, kRGBA_F16_SkColorType,
kPremul_SkAlphaType, rec2020);
auto surface = SkSurfaces::Raster(info);
// Effect draws horizontal gradients. Top half uses the simple uniform,
// bottom half uses a uniform tagged as a color:
const char* sksl = R"(
uniform vec4 not_a_color;
layout(color) uniform vec4 color;
vec4 main(vec2 xy) {
vec4 c = xy.y < 32 ? not_a_color : color;
return (c * (xy.x / 128)).rgb1;
})";
auto [effect, err] = SkRuntimeEffect::MakeForShader(SkString(sksl));
// Set both uniforms to be "red":
SkRuntimeShaderBuilder builder(effect);
builder.uniform("not_a_color") = SkV4{ 1, 0, 0, 1 }; // Red?
builder.uniform("color") = SkV4{ 1, 0, 0, 1 }; // sRGB Red
// Fill the offscreen surface:
SkPaint paint;
paint.setShader(builder.makeShader());
surface->getCanvas()->drawPaint(paint);
// Draw our offscreen image back to the original canvas:
canvas->drawImage(surface->makeImageSnapshot(), 0, 0);
}