Flutter Engine
The Flutter Engine
Functions
SkMallocPixelRef Namespace Reference

Functions

SK_API sk_sp< SkPixelRefMakeAllocate (const SkImageInfo &, size_t rowBytes)
 
SK_API sk_sp< SkPixelRefMakeWithData (const SkImageInfo &, size_t rowBytes, sk_sp< SkData > data)
 

Detailed Description

We explicitly use the same allocator for our pixels that SkMask does, so that we can freely assign memory allocated by one class to the other.

Function Documentation

◆ MakeAllocate()

sk_sp< SkPixelRef > SkMallocPixelRef::MakeAllocate ( const SkImageInfo info,
size_t  rowBytes 
)

Return a new SkMallocPixelRef, automatically allocating storage for the pixels. If rowBytes are 0, an optimal value will be chosen automatically. If rowBytes is > 0, then it will be respected, or NULL will be returned if rowBytes is invalid for the specified info.

All pixel bytes are zeroed.

Returns NULL on failure.

Definition at line 29 of file SkMallocPixelRef.cpp.

29 {
30 if (rowBytes == 0) {
31 rowBytes = info.minRowBytes();
32 // rowBytes can still be zero, if it overflowed (width * bytesPerPixel > size_t)
33 // or if colortype is unknown
34 }
35 if (!is_valid(info) || !info.validRowBytes(rowBytes)) {
36 return nullptr;
37 }
38 size_t size = info.computeByteSize(rowBytes);
40 return nullptr;
41 }
42#if defined(SK_BUILD_FOR_FUZZER)
43 if (size > 10000000) {
44 return nullptr;
45 }
46#endif
48 if (nullptr == addr) {
49 return nullptr;
50 }
51
52 struct PixelRef final : public SkPixelRef {
53 PixelRef(int w, int h, void* s, size_t r) : SkPixelRef(w, h, s, r) {}
54 ~PixelRef() override { sk_free(this->pixels()); }
55 };
56 return sk_sp<SkPixelRef>(new PixelRef(info.width(), info.height(), addr, rowBytes));
57}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static bool is_valid(const SkImageInfo &info)
static void * sk_calloc_canfail(size_t size)
Definition: SkMalloc.h:75
SK_API void sk_free(void *)
void * pixels() const
Definition: SkPixelRef.h:36
struct MyStruct s
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
SkScalar w
SkScalar h
static bool ByteSizeOverflowed(size_t byteSize)
Definition: SkImageInfo.h:588

◆ MakeWithData()

sk_sp< SkPixelRef > SkMallocPixelRef::MakeWithData ( const SkImageInfo info,
size_t  rowBytes,
sk_sp< SkData data 
)

Return a new SkMallocPixelRef that will use the provided SkData and rowBytes as pixel storage. The SkData will be ref()ed and on destruction of the PixelRef, the SkData will be unref()ed.

Returns NULL on failure.

Definition at line 59 of file SkMallocPixelRef.cpp.

61 {
62 SkASSERT(data != nullptr);
63 if (!is_valid(info)) {
64 return nullptr;
65 }
66 // TODO: what should we return if computeByteSize returns 0?
67 // - the info was empty?
68 // - we overflowed computing the size?
69 if ((rowBytes < info.minRowBytes()) || (data->size() < info.computeByteSize(rowBytes))) {
70 return nullptr;
71 }
72 struct PixelRef final : public SkPixelRef {
73 sk_sp<SkData> fData;
74 PixelRef(int w, int h, void* s, size_t r, sk_sp<SkData> d)
75 : SkPixelRef(w, h, s, r), fData(std::move(d)) {}
76 };
77 void* pixels = const_cast<void*>(data->data());
78 sk_sp<SkPixelRef> pr(new PixelRef(info.width(), info.height(), pixels, rowBytes,
79 std::move(data)));
80 pr->setImmutable(); // since we were created with (immutable) data
81 return pr;
82}
#define SkASSERT(cond)
Definition: SkAssert.h:116
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
Definition: ref_ptr.h:256
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63