Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Friends | List of all members
SkDynamicMemoryWStream Class Reference

#include <SkStream.h>

Inheritance diagram for SkDynamicMemoryWStream:
SkWStream SkRawLimitedDynamicMemoryWStream

Classes

struct  Block
 

Public Member Functions

 SkDynamicMemoryWStream ()=default
 
 SkDynamicMemoryWStream (SkDynamicMemoryWStream &&)
 
SkDynamicMemoryWStreamoperator= (SkDynamicMemoryWStream &&)
 
 ~SkDynamicMemoryWStream () override
 
bool write (const void *buffer, size_t size) override
 
size_t bytesWritten () const override
 
bool read (void *buffer, size_t offset, size_t size)
 
void copyTo (void *dst) const
 
bool writeToStream (SkWStream *dst) const
 
void copyToAndReset (void *dst)
 
bool writeToAndReset (SkWStream *dst)
 
bool writeToAndReset (SkDynamicMemoryWStream *dst)
 
void prependToAndReset (SkDynamicMemoryWStream *dst)
 
sk_sp< SkDatadetachAsData ()
 
std::unique_ptr< SkStreamAssetdetachAsStream ()
 
void reset ()
 
void padToAlign4 ()
 
- Public Member Functions inherited from SkWStream
virtual ~SkWStream ()
 
 SkWStream ()
 
virtual bool write (const void *buffer, size_t size)=0
 
virtual void flush ()
 
virtual size_t bytesWritten () const =0
 
bool write8 (U8CPU value)
 
bool write16 (U16CPU value)
 
bool write32 (uint32_t v)
 
bool writeText (const char text[])
 
bool newline ()
 
bool writeDecAsText (int32_t)
 
bool writeBigDecAsText (int64_t, int minDigits=0)
 
bool writeHexAsText (uint32_t, int minDigits=0)
 
bool writeScalarAsText (SkScalar)
 
bool writeBool (bool v)
 
bool writeScalar (SkScalar)
 
bool writePackedUInt (size_t)
 
bool writeStream (SkStream *input, size_t length)
 

Friends

class SkBlockMemoryStream
 
class SkBlockMemoryRefCnt
 

Additional Inherited Members

- Static Public Member Functions inherited from SkWStream
static int SizeOfPackedUInt (size_t value)
 

Detailed Description

Definition at line 455 of file SkStream.h.

Constructor & Destructor Documentation

◆ SkDynamicMemoryWStream() [1/2]

SkDynamicMemoryWStream::SkDynamicMemoryWStream ( )
default

◆ SkDynamicMemoryWStream() [2/2]

SkDynamicMemoryWStream::SkDynamicMemoryWStream ( SkDynamicMemoryWStream &&  other)

Definition at line 493 of file SkStream.cpp.

494 : fHead(other.fHead)
495 , fTail(other.fTail)
496 , fBytesWrittenBeforeTail(other.fBytesWrittenBeforeTail)
497{
498 other.fHead = nullptr;
499 other.fTail = nullptr;
500 other.fBytesWrittenBeforeTail = 0;
501}

◆ ~SkDynamicMemoryWStream()

SkDynamicMemoryWStream::~SkDynamicMemoryWStream ( )
override

Definition at line 511 of file SkStream.cpp.

511 {
512 this->reset();
513}

Member Function Documentation

◆ bytesWritten()

size_t SkDynamicMemoryWStream::bytesWritten ( ) const
overridevirtual

Implements SkWStream.

Definition at line 526 of file SkStream.cpp.

526 {
527 this->validate();
528
529 if (fTail) {
530 return fBytesWrittenBeforeTail + fTail->written();
531 }
532 return 0;
533}

◆ copyTo()

void SkDynamicMemoryWStream::copyTo ( void *  dst) const

More efficient version of read(dst, 0, bytesWritten()).

Definition at line 631 of file SkStream.cpp.

631 {
632 SkASSERT(dst);
633 Block* block = fHead;
634 while (block != nullptr) {
635 size_t size = block->written();
636 memcpy(dst, block->start(), size);
637 dst = (void*)((char*)dst + size);
638 block = block->fNext;
639 }
640}
#define SkASSERT(cond)
Definition: SkAssert.h: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
dst
Definition: cp.py:12

◆ copyToAndReset()

void SkDynamicMemoryWStream::copyToAndReset ( void *  dst)

Equivalent to copyTo() followed by reset(), but may save memory use.

Definition at line 668 of file SkStream.cpp.

668 {
669 if (!ptr) {
670 this->reset();
671 return;
672 }
673 // By looping through the source and freeing as we copy, we
674 // can reduce real memory use with large streams.
675 char* dst = reinterpret_cast<char*>(ptr);
676 Block* block = fHead;
677 while (block != nullptr) {
678 size_t len = block->written();
679 memcpy(dst, block->start(), len);
680 dst += len;
681 Block* next = block->fNext;
682 sk_free(block);
683 block = next;
684 }
685 fHead = fTail = nullptr;
686 fBytesWrittenBeforeTail = 0;
687}
static float next(float f)
SK_API void sk_free(void *)

◆ detachAsData()

sk_sp< SkData > SkDynamicMemoryWStream::detachAsData ( )

Return the contents as SkData, and then reset the stream.

Definition at line 707 of file SkStream.cpp.

707 {
708 const size_t size = this->bytesWritten();
709 if (0 == size) {
710 return SkData::MakeEmpty();
711 }
713 this->copyToAndReset(data->writable_data());
714 return data;
715}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
void * writable_data()
Definition: SkData.h:52
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94
size_t bytesWritten() const override
Definition: SkStream.cpp:526
void copyToAndReset(void *dst)
Definition: SkStream.cpp:668
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ detachAsStream()

std::unique_ptr< SkStreamAsset > SkDynamicMemoryWStream::detachAsStream ( )

Reset, returning a reader stream with the current content.

Definition at line 876 of file SkStream.cpp.

876 {
877 if (nullptr == fHead) {
878 // no need to reset.
879 return SkMemoryStream::Make(nullptr);
880 }
881 if (fHead == fTail) { // one block, may be worth shrinking.
882 ptrdiff_t used = fTail->fCurr - (char*)fTail;
883 fHead = fTail = (SkDynamicMemoryWStream::Block*)sk_realloc_throw(fTail, SkToSizeT(used));
884 fTail->fStop = fTail->fCurr = (char*)fTail + used; // Update pointers.
885 SkASSERT(nullptr == fTail->fNext);
886 SkASSERT(0 == fBytesWrittenBeforeTail);
887 }
888 std::unique_ptr<SkStreamAsset> stream
889 = std::make_unique<SkBlockMemoryStream>(sk_make_sp<SkBlockMemoryRefCnt>(fHead),
890 this->bytesWritten());
891 fHead = nullptr; // signal reset() to not free anything
892 this->reset();
893 return stream;
894}
SK_API void * sk_realloc_throw(void *buffer, size_t size)
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
Definition: SkStream.cpp:314

◆ operator=()

SkDynamicMemoryWStream & SkDynamicMemoryWStream::operator= ( SkDynamicMemoryWStream &&  other)

Definition at line 503 of file SkStream.cpp.

503 {
504 if (this != &other) {
506 new (this) SkDynamicMemoryWStream(std::move(other));
507 }
508 return *this;
509}
~SkDynamicMemoryWStream() override
Definition: SkStream.cpp:511
SkDynamicMemoryWStream()=default

◆ padToAlign4()

void SkDynamicMemoryWStream::padToAlign4 ( )

Definition at line 652 of file SkStream.cpp.

652 {
653 // The contract is to write zeros until the entire stream has written a multiple of 4 bytes.
654 // Our Blocks are guaranteed always be (a) full (except the tail) and (b) a multiple of 4
655 // so it is sufficient to just examine the tail (if present).
656
657 if (fTail) {
658 // cast to remove unary-minus warning
659 int padBytes = -(int)fTail->written() & 0x03;
660 if (padBytes) {
661 int zero = 0;
662 fTail->append(&zero, padBytes);
663 }
664 }
665}
const void * append(const void *data, size_t size)
Definition: SkStream.cpp:485

◆ prependToAndReset()

void SkDynamicMemoryWStream::prependToAndReset ( SkDynamicMemoryWStream dst)

Prepend this stream to dst, resetting this.

Definition at line 591 of file SkStream.cpp.

591 {
592 SkASSERT(dst);
593 SkASSERT(dst != this);
594 if (0 == this->bytesWritten()) {
595 return;
596 }
597 if (0 == dst->bytesWritten()) {
598 *dst = std::move(*this);
599 return;
600 }
601 fTail->fNext = dst->fHead;
602 dst->fHead = fHead;
603 dst->fBytesWrittenBeforeTail += fBytesWrittenBeforeTail + fTail->written();
604 fHead = fTail = nullptr;
605 fBytesWrittenBeforeTail = 0;
606}

◆ read()

bool SkDynamicMemoryWStream::read ( void *  buffer,
size_t  offset,
size_t  size 
)

Definition at line 609 of file SkStream.cpp.

609 {
610 if (offset + count > this->bytesWritten()) {
611 return false; // test does not partially modify
612 }
613 Block* block = fHead;
614 while (block != nullptr) {
615 size_t size = block->written();
616 if (offset < size) {
617 size_t part = offset + count > size ? size - offset : count;
618 memcpy(buffer, block->start() + offset, part);
619 if (count <= part) {
620 return true;
621 }
622 count -= part;
623 buffer = (void*) ((char* ) buffer + part);
624 }
625 offset = offset > size ? offset - size : 0;
626 block = block->fNext;
627 }
628 return false;
629}
int count
Definition: FontMgrTest.cpp:50
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
SeparatedVector2 offset

◆ reset()

void SkDynamicMemoryWStream::reset ( )

Reset the stream to its original, empty, state.

Definition at line 515 of file SkStream.cpp.

515 {
516 Block* block = fHead;
517 while (block != nullptr) {
518 Block* next = block->fNext;
519 sk_free(block);
520 block = next;
521 }
522 fHead = fTail = nullptr;
523 fBytesWrittenBeforeTail = 0;
524}

◆ write()

bool SkDynamicMemoryWStream::write ( const void *  buffer,
size_t  size 
)
overridevirtual

Called to write bytes to a SkWStream. Returns true on success

Parameters
bufferthe address of at least size bytes to be written to the stream
sizeThe number of bytes in buffer to write to the stream
Returns
true on success

Implements SkWStream.

Reimplemented in SkRawLimitedDynamicMemoryWStream.

Definition at line 535 of file SkStream.cpp.

535 {
536 if (count > 0) {
538 size_t size;
539
540 if (fTail && fTail->avail() > 0) {
541 size = std::min(fTail->avail(), count);
542 buffer = fTail->append(buffer, size);
543 SkASSERT(count >= size);
544 count -= size;
545 if (count == 0) {
546 return true;
547 }
548 }
549
550 size = std::max<size_t>(count, SkDynamicMemoryWStream_MinBlockSize - sizeof(Block));
551 size = SkAlign4(size); // ensure we're always a multiple of 4 (see padToAlign4())
552
553 Block* block = (Block*)sk_malloc_canfail(sizeof(Block) + size);
554 if (!block) {
555 this->validate();
556 return false;
557 }
558 block->init(size);
559 block->append(buffer, count);
560
561 if (fTail) {
562 fBytesWrittenBeforeTail += fTail->written();
563 fTail->fNext = block;
564 } else {
565 fHead = fTail = block;
566 }
567 fTail = block;
568 this->validate();
569 }
570 return true;
571}
static constexpr T SkAlign4(T x)
Definition: SkAlign.h:16
static void * sk_malloc_canfail(size_t size)
Definition: SkMalloc.h:93
#define SkDynamicMemoryWStream_MinBlockSize
Definition: SkStream.cpp:467
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ writeToAndReset() [1/2]

bool SkDynamicMemoryWStream::writeToAndReset ( SkDynamicMemoryWStream dst)

Equivalent to writeToStream() followed by reset(), but may save memory use. When the dst is also a SkDynamicMemoryWStream, the implementation is constant time.

Definition at line 573 of file SkStream.cpp.

573 {
574 SkASSERT(dst);
575 SkASSERT(dst != this);
576 if (0 == this->bytesWritten()) {
577 return true;
578 }
579 if (0 == dst->bytesWritten()) {
580 *dst = std::move(*this);
581 return true;
582 }
583 dst->fTail->fNext = fHead;
584 dst->fBytesWrittenBeforeTail += fBytesWrittenBeforeTail + dst->fTail->written();
585 dst->fTail = fTail;
586 fHead = fTail = nullptr;
587 fBytesWrittenBeforeTail = 0;
588 return true;
589}

◆ writeToAndReset() [2/2]

bool SkDynamicMemoryWStream::writeToAndReset ( SkWStream dst)

Equivalent to writeToStream() followed by reset(), but may save memory use.

Definition at line 689 of file SkStream.cpp.

689 {
690 SkASSERT(dst);
691 // By looping through the source and freeing as we copy, we
692 // can reduce real memory use with large streams.
693 bool dstStreamGood = true;
694 for (Block* block = fHead; block != nullptr; ) {
695 if (dstStreamGood && !dst->write(block->start(), block->written())) {
696 dstStreamGood = false;
697 }
698 Block* next = block->fNext;
699 sk_free(block);
700 block = next;
701 }
702 fHead = fTail = nullptr;
703 fBytesWrittenBeforeTail = 0;
704 return dstStreamGood;
705}

◆ writeToStream()

bool SkDynamicMemoryWStream::writeToStream ( SkWStream dst) const

Definition at line 642 of file SkStream.cpp.

642 {
643 SkASSERT(dst);
644 for (Block* block = fHead; block != nullptr; block = block->fNext) {
645 if (!dst->write(block->start(), block->written())) {
646 return false;
647 }
648 }
649 return true;
650}

Friends And Related Function Documentation

◆ SkBlockMemoryRefCnt

friend class SkBlockMemoryRefCnt
friend

Definition at line 507 of file SkStream.h.

◆ SkBlockMemoryStream

friend class SkBlockMemoryStream
friend

Definition at line 506 of file SkStream.h.


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