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
50
void draw(SkCanvas* canvas) {
SkPaint pRed;
pRed.setColor(SK_ColorRED);
SkPaint pSolidBlue;
pSolidBlue.setColor(SK_ColorBLUE);
SkPaint pThirtyBlue;
pThirtyBlue.setColor(SK_ColorBLUE);
pThirtyBlue.setAlphaf(0.3);
SkPaint alpha;
alpha.setAlphaf(0.3);
// Draw 4 solid red rectangles on the 0th layer.
canvas->drawRect(SkRect::MakeLTRB(10, 10, 60, 60), pRed);
canvas->drawRect(SkRect::MakeLTRB(150, 10, 200, 60), pRed);
canvas->drawRect(SkRect::MakeLTRB(10, 70, 60, 120), pRed);
canvas->drawRect(SkRect::MakeLTRB(150, 70, 200, 120), pRed);
// Draw 2 blue rectangles that overlap. One is solid, the other
// is 30% transparent. We should see purple from the right one,
// the left one overlaps the red because it is opaque.
canvas->drawRect(SkRect::MakeLTRB(30, 10, 80, 60), pSolidBlue);
canvas->drawRect(SkRect::MakeLTRB(170, 10, 220, 60), pThirtyBlue);
// Save a new layer. When the 1st layer gets merged onto the
// 0th layer (i.e. when restore() is called), it will use the provided
// paint to do so. The provided paint is set to have 30% opacity, but
// it could also have things set like blend modes or image filters.
canvas->saveLayer(nullptr, &alpha);
// Draw the same blue overlapping rectangles as before. Notice in the
// final output, we have two different shades of purple instead of the
// solid blue overwriting the red. This proves the opacity was applied.
canvas->drawRect(SkRect::MakeLTRB(30, 70, 80, 120), pSolidBlue);
canvas->drawRect(SkRect::MakeLTRB(170, 70, 220, 120), pThirtyBlue);
// We draw two more sets of overlapping red and blue rectangles. Notice
// the solid blue overwrites the red. This proves that the opacity from
// the alpha paint isn't available when the drawing happens - it only
// matters when restore() is called.
canvas->drawRect(SkRect::MakeLTRB(10, 130, 60, 180), pRed);
canvas->drawRect(SkRect::MakeLTRB(30, 130, 80, 180), pSolidBlue);
canvas->drawRect(SkRect::MakeLTRB(150, 130, 200, 180), pRed);
canvas->drawRect(SkRect::MakeLTRB(170, 130, 220, 180), pThirtyBlue);
canvas->restore();
}