Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkMemoryStream Class Reference

#include <SkStream.h>

Inheritance diagram for SkMemoryStream:
SkStreamMemory SkStreamAsset SkStreamSeekable SkStreamRewindable SkStream

Public Member Functions

 SkMemoryStream ()
 
 SkMemoryStream (size_t length)
 
 SkMemoryStream (const void *data, size_t length, bool copyData=false)
 
 SkMemoryStream (sk_sp< SkData > data)
 
virtual void setMemory (const void *data, size_t length, bool copyData=false)
 
void setMemoryOwned (const void *data, size_t length)
 
sk_sp< SkDatagetData () const override
 
void setData (sk_sp< SkData > data)
 
const void * getAtPos ()
 
size_t read (void *buffer, size_t size) override
 
bool isAtEnd () const override
 
size_t peek (void *buffer, size_t size) const override
 
bool rewind () override
 
std::unique_ptr< SkMemoryStreamduplicate () const
 
size_t getPosition () const override
 
bool seek (size_t position) override
 
bool move (long offset) override
 
std::unique_ptr< SkMemoryStreamfork () const
 
size_t getLength () const override
 
const void * getMemoryBase () override
 
- Public Member Functions inherited from SkStreamMemory
const void * getMemoryBase () override=0
 
std::unique_ptr< SkStreamMemoryduplicate () const
 
std::unique_ptr< SkStreamMemoryfork () const
 
- Public Member Functions inherited from SkStreamAsset
bool hasLength () const override
 
size_t getLength () const override=0
 
std::unique_ptr< SkStreamAssetduplicate () const
 
std::unique_ptr< SkStreamAssetfork () const
 
- Public Member Functions inherited from SkStreamSeekable
std::unique_ptr< SkStreamSeekableduplicate () const
 
bool hasPosition () const override
 
size_t getPosition () const override=0
 
bool seek (size_t position) override=0
 
bool move (long offset) override=0
 
std::unique_ptr< SkStreamSeekablefork () const
 
- Public Member Functions inherited from SkStreamRewindable
bool rewind () override=0
 
std::unique_ptr< SkStreamRewindableduplicate () const
 
- Public Member Functions inherited from SkStream
virtual ~SkStream ()
 
 SkStream ()
 
virtual size_t read (void *buffer, size_t size)=0
 
size_t skip (size_t size)
 
virtual size_t peek (void *, size_t) const
 
virtual bool isAtEnd () const =0
 
bool readS8 (int8_t *)
 
bool readS16 (int16_t *)
 
bool readS32 (int32_t *)
 
bool readU8 (uint8_t *i)
 
bool readU16 (uint16_t *i)
 
bool readU32 (uint32_t *i)
 
bool readBool (bool *b)
 
bool readScalar (SkScalar *)
 
bool readPackedUInt (size_t *)
 
virtual bool rewind ()
 
std::unique_ptr< SkStreamduplicate () const
 
std::unique_ptr< SkStreamfork () const
 
virtual bool hasPosition () const
 
virtual size_t getPosition () const
 
virtual bool seek (size_t)
 
virtual bool move (long)
 
virtual bool hasLength () const
 
virtual size_t getLength () const
 
virtual const void * getMemoryBase ()
 
virtual sk_sp< SkDatagetData () const
 

Static Public Member Functions

static std::unique_ptr< SkMemoryStreamMakeCopy (const void *data, size_t length)
 
static std::unique_ptr< SkMemoryStreamMakeDirect (const void *data, size_t length)
 
static std::unique_ptr< SkMemoryStreamMake (sk_sp< SkData > data)
 
- Static Public Member Functions inherited from SkStream
static std::unique_ptr< SkStreamAssetMakeFromFile (const char path[])
 

Detailed Description

Definition at line 361 of file SkStream.h.

Constructor & Destructor Documentation

◆ SkMemoryStream() [1/4]

SkMemoryStream::SkMemoryStream ( )

Definition at line 284 of file SkStream.cpp.

284 {
285 fData = SkData::MakeEmpty();
286 fOffset = 0;
287}
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94

◆ SkMemoryStream() [2/4]

SkMemoryStream::SkMemoryStream ( size_t  length)

We allocate (and free) the memory. Write to it via getMemoryBase()

Definition at line 289 of file SkStream.cpp.

289 {
291 fOffset = 0;
292}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
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

◆ SkMemoryStream() [3/4]

SkMemoryStream::SkMemoryStream ( const void *  data,
size_t  length,
bool  copyData = false 
)

If copyData is true, the stream makes a private copy of the data.

Definition at line 294 of file SkStream.cpp.

294 {
295 fData = newFromParams(src, size, copyData);
296 fOffset = 0;
297}
static sk_sp< SkData > newFromParams(const void *src, size_t size, bool copyData)
Definition: SkStream.cpp:276

◆ SkMemoryStream() [4/4]

SkMemoryStream::SkMemoryStream ( sk_sp< SkData data)

Creates the stream to read from the specified data

Definition at line 299 of file SkStream.cpp.

299 : fData(std::move(data)) {
300 if (nullptr == fData) {
301 fData = SkData::MakeEmpty();
302 }
303 fOffset = 0;
304}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Member Function Documentation

◆ duplicate()

std::unique_ptr< SkMemoryStream > SkMemoryStream::duplicate ( ) const
inline

Definition at line 407 of file SkStream.h.

407 {
408 return std::unique_ptr<SkMemoryStream>(this->onDuplicate());
409 }

◆ fork()

std::unique_ptr< SkMemoryStream > SkMemoryStream::fork ( ) const
inline

Definition at line 415 of file SkStream.h.

415 {
416 return std::unique_ptr<SkMemoryStream>(this->onFork());
417 }

◆ getAtPos()

const void * SkMemoryStream::getAtPos ( )

Definition at line 403 of file SkStream.cpp.

403 {
404 return fData->bytes() + fOffset;
405}
const uint8_t * bytes() const
Definition: SkData.h:43

◆ getData()

sk_sp< SkData > SkMemoryStream::getData ( ) const
inlineoverridevirtual

Reimplemented from SkStream.

Definition at line 395 of file SkStream.h.

395{ return fData; }

◆ getLength()

size_t SkMemoryStream::getLength ( ) const
overridevirtual

Returns the total length of the stream. If this cannot be done, returns 0.

Implements SkStreamAsset.

Definition at line 395 of file SkStream.cpp.

395 {
396 return fData->size();
397}
size_t size() const
Definition: SkData.h:30

◆ getMemoryBase()

const void * SkMemoryStream::getMemoryBase ( )
overridevirtual

Returns the starting address for the data. If this cannot be done, returns NULL.

Implements SkStreamMemory.

Definition at line 399 of file SkStream.cpp.

399 {
400 return fData->data();
401}
const void * data() const
Definition: SkData.h:37

◆ getPosition()

size_t SkMemoryStream::getPosition ( ) const
overridevirtual

Returns the current position in the stream. If this cannot be done, returns 0.

Implements SkStreamSeekable.

Definition at line 374 of file SkStream.cpp.

374 {
375 return fOffset;
376}

◆ isAtEnd()

bool SkMemoryStream::isAtEnd ( ) const
overridevirtual

Returns true when all the bytes in the stream have been read. As SkStream represents synchronous I/O, isAtEnd returns false when the final stream length isn't known yet, even when all the bytes available so far have been read. This may return true early (when there are no more bytes to be read) or late (after the first unsuccessful read).

Implements SkStream.

Definition at line 361 of file SkStream.cpp.

361 {
362 return fOffset == fData->size();
363}

◆ Make()

std::unique_ptr< SkMemoryStream > SkMemoryStream::Make ( sk_sp< SkData data)
static

Returns a stream with a shared reference to the input data.

Definition at line 314 of file SkStream.cpp.

314 {
315 return std::make_unique<SkMemoryStream>(std::move(data));
316}

◆ MakeCopy()

std::unique_ptr< SkMemoryStream > SkMemoryStream::MakeCopy ( const void *  data,
size_t  length 
)
static

Returns a stream with a copy of the input data.

Definition at line 306 of file SkStream.cpp.

306 {
307 return std::make_unique<SkMemoryStream>(data, length, true);
308}
size_t length

◆ MakeDirect()

std::unique_ptr< SkMemoryStream > SkMemoryStream::MakeDirect ( const void *  data,
size_t  length 
)
static

Returns a stream with a bare pointer reference to the input data.

Definition at line 310 of file SkStream.cpp.

310 {
311 return std::make_unique<SkMemoryStream>(data, length, false);
312}

◆ move()

bool SkMemoryStream::move ( long  )
overridevirtual

Seeks to an relative offset in the stream. If this cannot be done, returns false. If an attempt is made to move to a position outside the stream, the position will be set to the closest point within the stream (beginning or end).

Implements SkStreamSeekable.

Definition at line 385 of file SkStream.cpp.

385 {
386 return this->seek(fOffset + offset);
387}
bool seek(size_t position) override
Definition: SkStream.cpp:378
SeparatedVector2 offset

◆ peek()

size_t SkMemoryStream::peek ( void *  ,
size_t   
) const
overridevirtual

Attempt to peek at size bytes. If this stream supports peeking, copy min(size, peekable bytes) into buffer, and return the number of bytes copied. If the stream does not support peeking, or cannot peek any bytes, return 0 and leave buffer unchanged. The stream is guaranteed to be in the same visible state after this call, regardless of success or failure.

Parameters
bufferMust not be NULL, and must be at least size bytes. Destination to copy bytes.
sizeNumber of bytes to copy.
Returns
The number of bytes peeked/copied.

Reimplemented from SkStream.

Definition at line 351 of file SkStream.cpp.

351 {
352 SkASSERT(buffer != nullptr);
353
354 const size_t currentOffset = fOffset;
355 SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this);
356 const size_t bytesRead = nonConstThis->read(buffer, size);
357 nonConstThis->fOffset = currentOffset;
358 return bytesRead;
359}
#define SkASSERT(cond)
Definition: SkAssert.h:116
size_t read(void *buffer, size_t size) override
Definition: SkStream.cpp:337
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

◆ read()

size_t SkMemoryStream::read ( void *  buffer,
size_t  size 
)
overridevirtual

Reads or skips size number of bytes. If buffer == NULL, skip size bytes, return how many were skipped. If buffer != NULL, copy size bytes into buffer, return how many were copied.

Parameters
bufferwhen NULL skip size bytes, otherwise copy size bytes into buffer
sizethe number of bytes to skip or copy
Returns
the number of bytes actually read.

Implements SkStream.

Definition at line 337 of file SkStream.cpp.

337 {
338 size_t dataSize = fData->size();
339
340 SkASSERT(fOffset <= dataSize);
341 if (size > dataSize - fOffset) {
342 size = dataSize - fOffset;
343 }
344 if (buffer) {
345 sk_careful_memcpy(buffer, fData->bytes() + fOffset, size);
346 }
347 fOffset += size;
348 return size;
349}
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition: SkMalloc.h:125

◆ rewind()

bool SkMemoryStream::rewind ( )
overridevirtual

Rewinds to the beginning of the stream. Returns true if the stream is known to be at the beginning after this call returns.

Implements SkStreamRewindable.

Definition at line 365 of file SkStream.cpp.

365 {
366 fOffset = 0;
367 return true;
368}

◆ seek()

bool SkMemoryStream::seek ( size_t  )
overridevirtual

Seeks to an absolute position in the stream. If this cannot be done, returns false. If an attempt is made to seek past the end of the stream, the position will be set to the end of the stream.

Implements SkStreamSeekable.

Definition at line 378 of file SkStream.cpp.

378 {
379 fOffset = position > fData->size()
380 ? fData->size()
381 : position;
382 return true;
383}

◆ setData()

void SkMemoryStream::setData ( sk_sp< SkData data)

Definition at line 328 of file SkStream.cpp.

328 {
329 if (nullptr == data) {
330 fData = SkData::MakeEmpty();
331 } else {
332 fData = data;
333 }
334 fOffset = 0;
335}

◆ setMemory()

void SkMemoryStream::setMemory ( const void *  data,
size_t  length,
bool  copyData = false 
)
virtual

Resets the stream to the specified data and length, just like the constructor. if copyData is true, the stream makes a private copy of the data

Definition at line 323 of file SkStream.cpp.

323 {
324 fData = newFromParams(src, size, copyData);
325 fOffset = 0;
326}

◆ setMemoryOwned()

void SkMemoryStream::setMemoryOwned ( const void *  data,
size_t  length 
)

Replace any memory buffer with the specified buffer. The caller must have allocated data with sk_malloc or sk_realloc, since it will be freed with sk_free.

Definition at line 318 of file SkStream.cpp.

318 {
320 fOffset = 0;
321}
static sk_sp< SkData > MakeFromMalloc(const void *data, size_t length)
Definition: SkData.cpp:107

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