Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkBlockMemoryStream Class Reference
Inheritance diagram for SkBlockMemoryStream:
SkStreamAsset SkStreamSeekable SkStreamRewindable SkStream

Public Member Functions

 SkBlockMemoryStream (sk_sp< SkBlockMemoryRefCnt > headRef, size_t size)
 
size_t read (void *buffer, size_t rawCount) override
 
bool isAtEnd () const override
 
size_t peek (void *buff, size_t bytesToPeek) const override
 
bool rewind () override
 
SkBlockMemoryStreamonDuplicate () const override
 
size_t getPosition () const override
 
bool seek (size_t position) override
 
bool move (long offset) override
 
SkBlockMemoryStreamonFork () const override
 
size_t getLength () const override
 
const void * getMemoryBase () override
 
- Public Member Functions inherited from SkStreamAsset
bool hasLength () const override
 
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
 
std::unique_ptr< SkStreamSeekablefork () const
 
- Public Member Functions inherited from SkStreamRewindable
std::unique_ptr< SkStreamRewindableduplicate () const
 
- Public Member Functions inherited from SkStream
virtual ~SkStream ()
 
 SkStream ()
 
size_t skip (size_t size)
 
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 *)
 
std::unique_ptr< SkStreamduplicate () const
 
std::unique_ptr< SkStreamfork () const
 
virtual sk_sp< SkDatagetData () const
 

Additional Inherited Members

- Static Public Member Functions inherited from SkStream
static std::unique_ptr< SkStreamAssetMakeFromFile (const char path[])
 

Detailed Description

Definition at line 756 of file SkStream.cpp.

Constructor & Destructor Documentation

◆ SkBlockMemoryStream()

SkBlockMemoryStream::SkBlockMemoryStream ( sk_sp< SkBlockMemoryRefCnt headRef,
size_t  size 
)
inline

Definition at line 758 of file SkStream.cpp.

759 : fBlockMemory(std::move(headRef)), fCurrent(fBlockMemory->fHead)
760 , fSize(size) , fOffset(0), fCurrentOffset(0) { }
SkDynamicMemoryWStream::Block *const fHead
Definition SkStream.cpp:753

Member Function Documentation

◆ getLength()

size_t SkBlockMemoryStream::getLength ( ) const
inlineoverridevirtual

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

Implements SkStreamAsset.

Definition at line 857 of file SkStream.cpp.

857 {
858 return fSize;
859 }

◆ getMemoryBase()

const void * SkBlockMemoryStream::getMemoryBase ( )
inlineoverridevirtual

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

Reimplemented from SkStream.

Definition at line 861 of file SkStream.cpp.

861 {
862 if (fBlockMemory->fHead && !fBlockMemory->fHead->fNext) {
863 return fBlockMemory->fHead->start();
864 }
865 return nullptr;
866 }
const char * start() const
Definition SkStream.cpp:474

◆ getPosition()

size_t SkBlockMemoryStream::getPosition ( ) const
inlineoverridevirtual

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

Implements SkStreamSeekable.

Definition at line 824 of file SkStream.cpp.

824 {
825 return fOffset;
826 }

◆ isAtEnd()

bool SkBlockMemoryStream::isAtEnd ( ) const
inlineoverridevirtual

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 788 of file SkStream.cpp.

788 {
789 return fOffset == fSize;
790 }

◆ move()

bool SkBlockMemoryStream::move ( long  )
inlineoverridevirtual

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 845 of file SkStream.cpp.

845 {
846 return seek(fOffset + offset);
847 }
bool seek(size_t position) override
Definition SkStream.cpp:828
Point offset

◆ onDuplicate()

SkBlockMemoryStream * SkBlockMemoryStream::onDuplicate ( ) const
inlineoverridevirtual

Implements SkStreamAsset.

Definition at line 820 of file SkStream.cpp.

820 {
821 return new SkBlockMemoryStream(fBlockMemory, fSize);
822 }

◆ onFork()

SkBlockMemoryStream * SkBlockMemoryStream::onFork ( ) const
inlineoverridevirtual

Implements SkStreamAsset.

Definition at line 849 of file SkStream.cpp.

849 {
850 SkBlockMemoryStream* that = this->onDuplicate();
851 that->fCurrent = this->fCurrent;
852 that->fOffset = this->fOffset;
853 that->fCurrentOffset = this->fCurrentOffset;
854 return that;
855 }
SkBlockMemoryStream * onDuplicate() const override
Definition SkStream.cpp:820

◆ peek()

size_t SkBlockMemoryStream::peek ( void *  ,
size_t   
) const
inlineoverridevirtual

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 792 of file SkStream.cpp.

792 {
793 SkASSERT(buff != nullptr);
794
795 bytesToPeek = std::min(bytesToPeek, fSize - fOffset);
796
797 size_t bytesLeftToPeek = bytesToPeek;
798 char* buffer = static_cast<char*>(buff);
799 const SkDynamicMemoryWStream::Block* current = fCurrent;
800 size_t currentOffset = fCurrentOffset;
801 while (bytesLeftToPeek) {
802 SkASSERT(current);
803 size_t bytesFromCurrent = std::min(current->written() - currentOffset, bytesLeftToPeek);
804 memcpy(buffer, current->start() + currentOffset, bytesFromCurrent);
805 bytesLeftToPeek -= bytesFromCurrent;
806 buffer += bytesFromCurrent;
807 current = current->fNext;
808 currentOffset = 0;
809 }
810 return bytesToPeek;
811 }
#define SkASSERT(cond)
Definition SkAssert.h:116
static const uint8_t buffer[]

◆ read()

size_t SkBlockMemoryStream::read ( void *  buffer,
size_t  size 
)
inlineoverridevirtual

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 762 of file SkStream.cpp.

762 {
763 size_t count = rawCount;
764 if (fOffset + count > fSize) {
765 count = fSize - fOffset;
766 }
767 size_t bytesLeftToRead = count;
768 while (fCurrent != nullptr) {
769 size_t bytesLeftInCurrent = fCurrent->written() - fCurrentOffset;
770 size_t bytesFromCurrent = std::min(bytesLeftToRead, bytesLeftInCurrent);
771 if (buffer) {
772 memcpy(buffer, fCurrent->start() + fCurrentOffset, bytesFromCurrent);
773 buffer = SkTAddOffset<void>(buffer, bytesFromCurrent);
774 }
775 if (bytesLeftToRead <= bytesFromCurrent) {
776 fCurrentOffset += bytesFromCurrent;
777 fOffset += count;
778 return count;
779 }
780 bytesLeftToRead -= bytesFromCurrent;
781 fCurrent = fCurrent->fNext;
782 fCurrentOffset = 0;
783 }
784 SkASSERT(false);
785 return 0;
786 }
int count

◆ rewind()

bool SkBlockMemoryStream::rewind ( )
inlineoverridevirtual

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 813 of file SkStream.cpp.

813 {
814 fCurrent = fBlockMemory->fHead;
815 fOffset = 0;
816 fCurrentOffset = 0;
817 return true;
818 }

◆ seek()

bool SkBlockMemoryStream::seek ( size_t  )
inlineoverridevirtual

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 828 of file SkStream.cpp.

828 {
829 // If possible, skip forward.
830 if (position >= fOffset) {
831 size_t skipAmount = position - fOffset;
832 return this->skip(skipAmount) == skipAmount;
833 }
834 // If possible, move backward within the current block.
835 size_t moveBackAmount = fOffset - position;
836 if (moveBackAmount <= fCurrentOffset) {
837 fCurrentOffset -= moveBackAmount;
838 fOffset -= moveBackAmount;
839 return true;
840 }
841 // Otherwise rewind and move forward.
842 return this->rewind() && this->skip(position) == position;
843 }
bool rewind() override
Definition SkStream.cpp:813
size_t skip(size_t size)
Definition SkStream.h:51

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