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
43
void draw(SkCanvas* canvas) {
// Default SkPaint properties
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kFill_Style);
p.setStrokeWidth(10);
// Draw red squares
p.setColor(SK_ColorRED);
const SkRect red = SkRect::MakeXYWH(0, 0, 128, 128);
canvas->drawRect(red, p);
const SkRect red2 = SkRect::MakeXYWH(128, 128, 128, 128);
canvas->drawRect(red2, p);
// Draw blue squares
p.setColor(SK_ColorBLUE);
const SkRect blue = SkRect::MakeXYWH(128, 0, 128, 128);
canvas->drawRect(blue, p);
const SkRect blue2 = SkRect::MakeXYWH(0, 128, 128, 128);
canvas->drawRect(blue2, p);
// Create middle overlay rectangle for background blur
const SkRect middle = SkRect::MakeXYWH(64, 64, 128, 128);
// Use middle rectangle as clip mask
canvas->clipRect(middle, true);
// Two blur filters, one that we're currently using and the newer one in current version of Skia.
// Both blur filters select a tile mode for clamping the blur filter at the rectangle's edges.
// However, the result on the CPU does NOT appear to clamp at all, while the result on GPU does!
sk_sp<SkImageFilter> oldBlurFilter = SkBlurImageFilter::Make(25, 25, nullptr, nullptr, SkBlurImageFilter::kClamp_TileMode);
sk_sp<SkImageFilter> newBlurFilter = SkImageFilters::Blur(25, 25, SkTileMode::kClamp, nullptr);
p.setImageFilter(std::move(oldBlurFilter));
// Make a separate layer using the blur filter, clipped to the middle rectangle's bounds
SkCanvas::SaveLayerRec slr(&middle, &p, SkCanvas::kInitWithPrevious_SaveLayerFlag);
canvas->saveLayer(slr);
// Fill the clip middle rectangle with a transparent white
canvas->drawColor(0x40FFFFFF);
canvas->restore();
}