Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
AutoCleanPng Class Reference
Inheritance diagram for AutoCleanPng:
SkNoncopyable

Public Member Functions

 AutoCleanPng (png_structp png_ptr, SkStream *stream, SkPngChunkReader *reader, SkCodec **codecPtr)
 
 ~AutoCleanPng ()
 
void setInfoPtr (png_infop info_ptr)
 
bool decodeBounds ()
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Detailed Description

Definition at line 88 of file SkPngCodec.cpp.

Constructor & Destructor Documentation

◆ AutoCleanPng()

AutoCleanPng::AutoCleanPng ( png_structp  png_ptr,
SkStream stream,
SkPngChunkReader reader,
SkCodec **  codecPtr 
)
inline

Definition at line 96 of file SkPngCodec.cpp.

98 : fPng_ptr(png_ptr)
99 , fInfo_ptr(nullptr)
100 , fStream(stream)
101 , fChunkReader(reader)
102 , fOutCodec(codecPtr)
103 {}

◆ ~AutoCleanPng()

AutoCleanPng::~AutoCleanPng ( )
inline

Definition at line 105 of file SkPngCodec.cpp.

105 {
106 // fInfo_ptr will never be non-nullptr unless fPng_ptr is.
107 if (fPng_ptr) {
108 png_infopp info_pp = fInfo_ptr ? &fInfo_ptr : nullptr;
109 png_destroy_read_struct(&fPng_ptr, info_pp, nullptr);
110 }
111 }

Member Function Documentation

◆ decodeBounds()

bool AutoCleanPng::decodeBounds ( )

Reads enough of the input stream to decode the bounds.

Returns
false if the stream is not a valid PNG (or too short). true if it read enough of the stream to determine the bounds. In the latter case, the stream may have been read beyond the point to determine the bounds, and the png_ptr will have saved any extra data. Further, if the codecPtr supplied to the constructor was not NULL, it will now point to a new SkCodec, which owns (or refs, in the case of the SkPngChunkReader) the inputs. If codecPtr was NULL, the png_ptr and info_ptr are unowned, and it is up to the caller to destroy them.

Definition at line 165 of file SkPngCodec.cpp.

165 {
166 SkASSERT(fStream);
167 if (setjmp(PNG_JMPBUF(fPng_ptr))) {
168 return false;
169 }
170
171 png_set_progressive_read_fn(fPng_ptr, nullptr, nullptr, nullptr, nullptr);
172
173 // Arbitrary buffer size, though note that it matches (below)
174 // SkPngCodec::processData(). FIXME: Can we better suit this to the size of
175 // the PNG header?
176 constexpr size_t kBufferSize = 4096;
177 char buffer[kBufferSize];
178
179 {
180 // Parse the signature.
181 if (fStream->read(buffer, 8) < 8) {
182 return false;
183 }
184
185 png_process_data(fPng_ptr, fInfo_ptr, (png_bytep) buffer, 8);
186 }
187
188 while (true) {
189 // Parse chunk length and type.
190 if (fStream->read(buffer, 8) < 8) {
191 // We have read to the end of the input without decoding bounds.
192 break;
193 }
194
195 png_byte* chunk = reinterpret_cast<png_byte*>(buffer);
196 const size_t length = png_get_uint_32(chunk);
197
198 if (is_chunk(chunk, "IDAT")) {
199 this->infoCallback(length);
200 return true;
201 }
202
203 png_process_data(fPng_ptr, fInfo_ptr, chunk, 8);
204 // Process the full chunk + CRC.
205 if (!process_data(fPng_ptr, fInfo_ptr, fStream, buffer, kBufferSize, length + 4)) {
206 return false;
207 }
208 }
209
210 return false;
211}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool process_data(png_structp png_ptr, png_infop info_ptr, SkStream *stream, void *buffer, size_t bufferSize, size_t length)
Definition: SkPngCodec.cpp:151
#define PNG_JMPBUF(x)
Definition: SkPngCodec.cpp:54
static bool is_chunk(const png_byte *chunk, const char *tag)
Definition: SkPngCodec.cpp:147
static const size_t kBufferSize
Definition: SkString.cpp:27
virtual size_t read(void *buffer, size_t size)=0
size_t length
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ setInfoPtr()

void AutoCleanPng::setInfoPtr ( png_infop  info_ptr)
inline

Definition at line 113 of file SkPngCodec.cpp.

113 {
114 SkASSERT(nullptr == fInfo_ptr);
115 fInfo_ptr = info_ptr;
116 }

The documentation for this class was generated from the following file: