Flutter Engine
The Flutter Engine
SkMallocPixelRef.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12#include "include/core/SkData.h"
16
17#include <utility>
18
19static bool is_valid(const SkImageInfo& info) {
20 if (info.width() < 0 || info.height() < 0 ||
21 (unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType ||
22 (unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType)
23 {
24 return false;
25 }
26 return true;
27}
28
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}
58
60 size_t rowBytes,
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}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kLastEnum_SkAlphaType
last valid value
Definition: SkAlphaType.h:31
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kLastEnum_SkColorType
last valid value
Definition: SkColorType.h:56
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
void setImmutable()
Definition: SkPixelRef.cpp:112
SkPixelRef(int width, int height, void *addr, size_t rowBytes)
Definition: SkPixelRef.cpp:32
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
struct MyStruct s
SK_API sk_sp< SkPixelRef > MakeWithData(const SkImageInfo &, size_t rowBytes, sk_sp< SkData > data)
SK_API sk_sp< SkPixelRef > MakeAllocate(const SkImageInfo &, size_t rowBytes)
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
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63