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
class LargePixelRef : public SkPixelRef {
public:
LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes)
: SkPixelRef(info.width(), info.height(), storage, rowBytes) {
}
~LargePixelRef() override {
delete[] (char* ) this->pixels();
}
};
class LargeAllocator : public SkBitmap::Allocator {
public:
bool allocPixelRef(SkBitmap* bitmap) override {
const SkImageInfo& info = bitmap->info();
uint64_t rowBytes = info.minRowBytes64();
uint64_t size = info.height() * rowBytes;
char* addr = new char[size];
if (nullptr == addr) {
return false;
}
sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes));
if (!pr) {
return false;
}
bitmap->setPixelRef(std::move(pr), 0, 0);
return true;
}
};
void draw(SkCanvas* canvas) {
LargeAllocator largeAllocator;
SkBitmap bitmap;
int width = 100; // make this 20000
int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform
bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType));
if (bitmap.tryAllocPixels(&largeAllocator)) {
bitmap.eraseColor(0xff55aa33);
canvas->drawImage(bitmap.asImage(), 0, 0);
}
}