Flutter Engine
The Flutter Engine
Bitmap_tryAllocPixels_4.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(Bitmap_tryAllocPixels_4, 256, 100, false, 0) {
5class LargePixelRef : public SkPixelRef {
6public:
7 LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes)
8 : SkPixelRef(info.width(), info.height(), storage, rowBytes) {
9 }
10 ~LargePixelRef() override {
11 delete[] (char* ) this->pixels();
12 }
13};
14class LargeAllocator : public SkBitmap::Allocator {
15public:
16 bool allocPixelRef(SkBitmap* bitmap) override {
17 const SkImageInfo& info = bitmap->info();
18 uint64_t rowBytes = info.minRowBytes64();
19 uint64_t size = info.height() * rowBytes;
20 char* addr = new char[size];
21 if (nullptr == addr) {
22 return false;
23 }
24 sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes));
25 if (!pr) {
26 return false;
27 }
28 bitmap->setPixelRef(std::move(pr), 0, 0);
29 return true;
30 }
31};
32
33void draw(SkCanvas* canvas) {
34 LargeAllocator largeAllocator;
36 int width = 100; // make this 20000
37 int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform
39 if (bitmap.tryAllocPixels(&largeAllocator)) {
40 bitmap.eraseColor(0xff55aa33);
41 canvas->drawImage(bitmap.asImage(), 0, 0);
42 }
43}
44} // END FIDDLE
REG_FIDDLE(Bitmap_tryAllocPixels_4, 256, 100, false, 0)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
size_t rowBytes() const
Definition: SkBitmap.h:238
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
void * pixels() const
Definition: SkPixelRef.h:36
SkPixelRef(int width, int height, void *addr, size_t rowBytes)
Definition: SkPixelRef.cpp:32
Definition: bitmap.py:1
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
int32_t height
int32_t width
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)