19 FrontBufferedStream(std::unique_ptr<SkStream>,
size_t bufferSize);
20 ~FrontBufferedStream()
override;
22 bool failedToAllocateBuffer()
const {
return !fBuffer; }
32 bool hasLength()
const override {
return fHasLength; }
34 size_t getLength()
const override {
return fLength; }
39 std::unique_ptr<SkStream> fStream;
40 const bool fHasLength;
46 size_t fBufferedSoFar;
48 const size_t fBufferSize;
51 char fStorage[kStorageSize];
56 size_t readFromBuffer(
char*
dst,
size_t size);
61 size_t bufferAndWriteTo(
char*
dst,
size_t size);
66 size_t readDirectlyFromStream(
char*
dst,
size_t size);
80 auto frontBufferedStream = std::make_unique<::FrontBufferedStream>(
81 std::move(
stream), bufferSize);
82 if (frontBufferedStream->failedToAllocateBuffer()) {
86 return frontBufferedStream;
92FrontBufferedStream::FrontBufferedStream(std::unique_ptr<SkStream>
stream,
size_t bufferSize)
94 , fHasLength(fStream->hasPosition() && fStream->hasLength())
95 , fLength(fStream->getLength() - fStream->getPosition())
98 , fBufferSize(bufferSize)
99 , fBuffer(bufferSize <= kStorageSize ? fStorage
100 : reinterpret_cast<char*>(
malloc(bufferSize))) {}
102FrontBufferedStream::~FrontBufferedStream() {
103 if (fBuffer != fStorage) {
108bool FrontBufferedStream::isAtEnd()
const {
109 if (fOffset < fBufferedSoFar) {
115 return fStream->isAtEnd();
120 if (fOffset <= fBufferSize) {
127size_t FrontBufferedStream::readFromBuffer(
char*
dst,
size_t size) {
132 const size_t bytesToCopy =
std::min(
size, fBufferedSoFar - fOffset);
133 if (
dst !=
nullptr) {
134 memcpy(
dst, fBuffer + fOffset, bytesToCopy);
139 fOffset += bytesToCopy;
140 SkASSERT(fOffset <= fBufferedSoFar);
145size_t FrontBufferedStream::bufferAndWriteTo(
char*
dst,
size_t size) {
147 SkASSERT(fOffset >= fBufferedSoFar);
151 const size_t bytesToBuffer =
std::min(
size, fBufferSize - fBufferedSoFar);
152 char*
buffer = fBuffer + fOffset;
153 const size_t buffered = fStream->read(
buffer, bytesToBuffer);
155 fBufferedSoFar += buffered;
156 fOffset = fBufferedSoFar;
157 SkASSERT(fBufferedSoFar <= fBufferSize);
160 if (
dst !=
nullptr) {
167size_t FrontBufferedStream::readDirectlyFromStream(
char*
dst,
size_t size) {
170 SkASSERT(fBufferSize == fBufferedSoFar && fOffset >= fBufferSize);
172 const size_t bytesReadDirectly = fStream->read(
dst,
size);
173 fOffset += bytesReadDirectly;
177 if (bytesReadDirectly > 0 && fBuffer != fStorage) {
182 return bytesReadDirectly;
185size_t FrontBufferedStream::peek(
void*
dst,
size_t size)
const {
187 const size_t start = fOffset;
189 if (start >= fBufferSize) {
195 FrontBufferedStream* nonConstThis =
const_cast<FrontBufferedStream*
>(
this);
196 const size_t bytesRead = nonConstThis->read(
dst,
size);
197 nonConstThis->fOffset =
start;
203 char*
dst =
reinterpret_cast<char*
>(voidDst);
205 const size_t start = fOffset;
208 if (fOffset < fBufferedSoFar) {
209 const size_t bytesCopied = this->readFromBuffer(
dst,
size);
215 if (
dst !=
nullptr) {
222 if (
size > 0 && fBufferedSoFar < fBufferSize && !fStream->isAtEnd()) {
223 const size_t buffered = this->bufferAndWriteTo(
dst,
size);
229 if (
dst !=
nullptr) {
234 if (
size > 0 && !fStream->isAtEnd()) {
235 SkDEBUGCODE(
const size_t bytesReadDirectly =) this->readDirectlyFromStream(
dst,
size);
240 return fOffset - start;
static bool rewind(EdgeList *activeEdges, Vertex **current, Vertex *dst, const Comparator &c)
static bool read(SkStream *stream, void *buffer, size_t amount)
#define INHERITED(method,...)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr size_t MinBufferedBytesNeeded()
SkStreamRewindable * onDuplicate() const override=0
virtual size_t peek(void *, size_t) const
virtual bool isAtEnd() const =0
virtual size_t getLength() const
virtual bool hasLength() const
virtual size_t read(void *buffer, size_t size)=0
static std::unique_ptr< SkStreamRewindable > Make(std::unique_ptr< SkStream > stream, size_t minBufferSize)
static float min(float r, float g, float b)
void * malloc(size_t size)
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
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