Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | List of all members
SkFILEStream Class Reference

#include <SkStream.h>

Inheritance diagram for SkFILEStream:
SkStreamAsset SkStreamSeekable SkStreamRewindable SkStream

Public Member Functions

 SkFILEStream (const char path[]=nullptr)
 
 SkFILEStream (FILE *file)
 
 SkFILEStream (FILE *file, size_t size)
 
 ~SkFILEStream () override
 
bool isValid () const
 
void close ()
 
size_t read (void *buffer, size_t size) override
 
bool isAtEnd () const override
 
bool rewind () override
 
std::unique_ptr< SkStreamAssetduplicate () const
 
size_t getPosition () const override
 
bool seek (size_t position) override
 
bool move (long offset) override
 
std::unique_ptr< SkStreamAssetfork () const
 
size_t getLength () const override
 
- 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< SkFILEStreamMake (const char path[])
 
- Static Public Member Functions inherited from SkStream
static std::unique_ptr< SkStreamAssetMakeFromFile (const char path[])
 

Detailed Description

A stream that wraps a C FILE* file stream.

Definition at line 291 of file SkStream.h.

Constructor & Destructor Documentation

◆ SkFILEStream() [1/3]

SkFILEStream::SkFILEStream ( const char  path[] = nullptr)
explicit

Initialize the stream by calling sk_fopen on the specified path. This internal stream will be closed in the destructor.

Definition at line 190 of file SkStream.cpp.

192{ }
FILE * sk_fopen(const char path[], SkFILE_Flags)
@ kRead_SkFILE_Flag
Definition: SkOSFile.h:20
SkFILEStream(const char path[]=nullptr)
Definition: SkStream.cpp:190
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
Definition: switches.h:57

◆ SkFILEStream() [2/3]

SkFILEStream::SkFILEStream ( FILE *  file)
explicit

Initialize the stream with an existing C FILE stream. The current position of the C FILE stream will be considered the beginning of the SkFILEStream and the current seek end of the FILE will be the end. The C FILE stream will be closed in the destructor.

Definition at line 184 of file SkStream.cpp.

185 : SkFILEStream(std::shared_ptr<FILE>(file, sk_fclose),
186 file ? sk_fgetsize(file) : 0,
187 file ? sk_ftell(file) : 0)
188{ }
void sk_fclose(FILE *)
size_t sk_ftell(FILE *)
size_t sk_fgetsize(FILE *)

◆ SkFILEStream() [3/3]

SkFILEStream::SkFILEStream ( FILE *  file,
size_t  size 
)
explicit

Initialize the stream with an existing C FILE stream. The current position of the C FILE stream will be considered the beginning of the SkFILEStream and size bytes later will be the end. The C FILE stream will be closed in the destructor.

Definition at line 180 of file SkStream.cpp.

182{ }
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

◆ ~SkFILEStream()

SkFILEStream::~SkFILEStream ( )
override

Definition at line 194 of file SkStream.cpp.

194 {
195 this->close();
196}
void close()
Definition: SkStream.cpp:198

Member Function Documentation

◆ close()

void SkFILEStream::close ( )

Close this SkFILEStream.

Definition at line 198 of file SkStream.cpp.

198 {
199 fFILE.reset();
200 fEnd = 0;
201 fStart = 0;
202 fCurrent = 0;
203}

◆ duplicate()

std::unique_ptr< SkStreamAsset > SkFILEStream::duplicate ( ) const
inline

Definition at line 329 of file SkStream.h.

329 {
330 return std::unique_ptr<SkStreamAsset>(this->onDuplicate());
331 }

◆ fork()

std::unique_ptr< SkStreamAsset > SkFILEStream::fork ( ) const
inline

Definition at line 337 of file SkStream.h.

337 {
338 return std::unique_ptr<SkStreamAsset>(this->onFork());
339 }

◆ getLength()

size_t SkFILEStream::getLength ( ) const
overridevirtual

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

Implements SkStreamAsset.

Definition at line 270 of file SkStream.cpp.

270 {
271 return fEnd - fStart;
272}

◆ getPosition()

size_t SkFILEStream::getPosition ( ) const
overridevirtual

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

Implements SkStreamSeekable.

Definition at line 236 of file SkStream.cpp.

236 {
237 SkASSERT(fCurrent >= fStart);
238 return fCurrent - fStart;
239}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ isAtEnd()

bool SkFILEStream::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 220 of file SkStream.cpp.

220 {
221 if (fCurrent == fEnd) {
222 return true;
223 }
224 return fCurrent >= sk_fgetsize(fFILE.get());
225}

◆ isValid()

bool SkFILEStream::isValid ( ) const
inline

Returns true if the current path could be opened.

Definition at line 320 of file SkStream.h.

320{ return fFILE != nullptr; }

◆ Make()

static std::unique_ptr< SkFILEStream > SkFILEStream::Make ( const char  path[])
inlinestatic

Definition at line 314 of file SkStream.h.

314 {
315 std::unique_ptr<SkFILEStream> stream(new SkFILEStream(path));
316 return stream->isValid() ? std::move(stream) : nullptr;
317 }

◆ move()

bool SkFILEStream::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 246 of file SkStream.cpp.

246 {
247 if (offset < 0) {
249 !SkTFitsIn<size_t>(-offset) ||
250 (size_t) (-offset) >= this->getPosition())
251 {
252 fCurrent = fStart;
253 } else {
254 fCurrent += offset;
255 }
256 } else if (!SkTFitsIn<size_t>(offset)) {
257 fCurrent = fEnd;
258 } else {
259 fCurrent = std::min(SkSafeMath::Add(fCurrent, (size_t) offset), fEnd);
260 }
261
262 SkASSERT(fCurrent >= fStart && fCurrent <= fEnd);
263 return true;
264}
size_t getPosition() const override
Definition: SkStream.cpp:236
static size_t Add(size_t x, size_t y)
Definition: SkSafeMath.cpp:10
static float min(float r, float g, float b)
Definition: hsl.cpp:48
SeparatedVector2 offset

◆ read()

size_t SkFILEStream::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 205 of file SkStream.cpp.

205 {
206 if (size > fEnd - fCurrent) {
207 size = fEnd - fCurrent;
208 }
209 size_t bytesRead = size;
210 if (buffer) {
211 bytesRead = sk_qread(fFILE.get(), buffer, size, fCurrent);
212 }
213 if (bytesRead == SIZE_MAX) {
214 return 0;
215 }
216 fCurrent += bytesRead;
217 return bytesRead;
218}
size_t sk_qread(FILE *, void *buffer, size_t count, size_t offset)
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

◆ rewind()

bool SkFILEStream::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 227 of file SkStream.cpp.

227 {
228 fCurrent = fStart;
229 return true;
230}

◆ seek()

bool SkFILEStream::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 241 of file SkStream.cpp.

241 {
242 fCurrent = std::min(SkSafeMath::Add(position, fStart), fEnd);
243 return true;
244}

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