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
48
void fill(SkBitmap & b, SkColor c, int n) {
for (int y = 0; y < n; y++) {
for (int x = 0; x < n; x++) {
*(b.getAddr32(x, y)) = c;
}
}
}
void doCell(SkCanvas* canvas, float x, float y, SkAlphaType at, SkColor c, int n) {
SkImageInfo info = SkImageInfo::MakeS32(n, n, at);
SkBitmap bmp;
bmp.allocPixels(info);
fill(bmp, c, n);
sk_sp<SkImage> img = bmp.asImage();
SkPaint paint;
const SkTileMode tile = SkTileMode::kRepeat;
paint.setShader(img->makeShader(tile, tile, SkSamplingOptions()));
canvas->drawRect(SkRect::MakeXYWH(x, y, 50, 50), paint);
}
void draw(SkCanvas* canvas) {
canvas->clear(SK_ColorBLACK);
doCell(canvas, 0, 0, kPremul_SkAlphaType, 0x80404040, 2);
doCell(canvas, 0, 50, kUnpremul_SkAlphaType, 0x80808080, 2);
doCell(canvas, 50, 0, kPremul_SkAlphaType, 0x80808080, 2);
doCell(canvas, 50, 50, kUnpremul_SkAlphaType, 0x80FFFFFF, 2);
doCell(canvas, 110, 0, kPremul_SkAlphaType, 0x80404040, 1);
doCell(canvas, 110, 50, kUnpremul_SkAlphaType, 0x80808080, 1);
doCell(canvas, 160, 0, kPremul_SkAlphaType, 0x80808080, 1);
doCell(canvas, 160, 50, kUnpremul_SkAlphaType, 0x80FFFFFF, 1);
SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 12);
SkPaint paint;
paint.setColor(SK_ColorWHITE);
canvas->drawString("Premul", 220, 20, font, paint);
canvas->drawString("Unpremul", 220, 70, font, paint);
canvas->drawString("Gray", 5, 120, font, paint);
canvas->drawString("White", 55, 120, font, paint);
canvas->drawString("Gray", 115, 120, font, paint);
canvas->drawString("White", 165, 120, font, paint);
canvas->drawString("2x2", 40, 150, font, paint);
canvas->drawString("1x1", 150, 150, font, paint);
}