Flutter Engine
The Flutter Engine
Classes | Macros | Functions
SkStream.cpp File Reference
#include "include/core/SkStream.h"
#include "include/core/SkData.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTFitsIn.h"
#include "include/private/base/SkTPin.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkSafeMath.h"
#include "src/core/SkOSFile.h"
#include "src/core/SkStreamPriv.h"
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <limits>
#include <new>

Go to the source code of this file.

Classes

struct  SkDynamicMemoryWStream::Block
 
class  SkBlockMemoryRefCnt
 
class  SkBlockMemoryStream
 

Macros

#define SK_MAX_BYTE_FOR_U8   0xFD
 
#define SK_BYTE_SENTINEL_FOR_U16   0xFE
 
#define SK_BYTE_SENTINEL_FOR_U32   0xFF
 
#define SkDynamicMemoryWStream_MinBlockSize   4096
 

Functions

static sk_sp< SkDatanewFromParams (const void *src, size_t size, bool copyData)
 
static void sk_memcpy_4bytes (void *dst, const void *src, size_t size)
 
static sk_sp< SkDatammap_filename (const char path[])
 
sk_sp< SkDataSkCopyStreamToData (SkStream *stream)
 
bool SkStreamCopy (SkWStream *out, SkStream *input)
 
bool StreamRemainingLengthIsBelow (SkStream *stream, size_t len)
 

Macro Definition Documentation

◆ SK_BYTE_SENTINEL_FOR_U16

#define SK_BYTE_SENTINEL_FOR_U16   0xFE

Definition at line 49 of file SkStream.cpp.

◆ SK_BYTE_SENTINEL_FOR_U32

#define SK_BYTE_SENTINEL_FOR_U32   0xFF

Definition at line 50 of file SkStream.cpp.

◆ SK_MAX_BYTE_FOR_U8

#define SK_MAX_BYTE_FOR_U8   0xFD

Definition at line 48 of file SkStream.cpp.

◆ SkDynamicMemoryWStream_MinBlockSize

#define SkDynamicMemoryWStream_MinBlockSize   4096

Definition at line 467 of file SkStream.cpp.

Function Documentation

◆ mmap_filename()

static sk_sp< SkData > mmap_filename ( const char  path[])
static

Definition at line 911 of file SkStream.cpp.

911 {
913 if (nullptr == file) {
914 return nullptr;
915 }
916
919 return data;
920}
FILE * sk_fopen(const char path[], SkFILE_Flags)
void sk_fclose(FILE *)
@ kRead_SkFILE_Flag
Definition: SkOSFile.h:20
static sk_sp< SkData > MakeFromFILE(FILE *f)
Definition: SkData.cpp:138
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
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ newFromParams()

static sk_sp< SkData > newFromParams ( const void *  src,
size_t  size,
bool  copyData 
)
static

Definition at line 276 of file SkStream.cpp.

276 {
277 if (copyData) {
279 } else {
281 }
282}
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition: SkData.h:116
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
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

◆ sk_memcpy_4bytes()

static void sk_memcpy_4bytes ( void *  dst,
const void *  src,
size_t  size 
)
inlinestatic

Definition at line 459 of file SkStream.cpp.

459 {
460 if (size == 4) {
461 memcpy(dst, src, 4);
462 } else {
463 memcpy(dst, src, size);
464 }
465}
dst
Definition: cp.py:12

◆ SkCopyStreamToData()

sk_sp< SkData > SkCopyStreamToData ( SkStream stream)

Copy the provided stream to an SkData variable.

Note: Assumes the stream is at the beginning. If it has a length, but is not at the beginning, this call will fail (return NULL).

Parameters
streamSkStream to be copied into data.
Returns
The resulting SkData after the copy, nullptr on failure.

Definition at line 937 of file SkStream.cpp.

937 {
938 SkASSERT(stream != nullptr);
939
940 if (stream->hasLength()) {
941 return SkData::MakeFromStream(stream, stream->getLength());
942 }
943
944 SkDynamicMemoryWStream tempStream;
945 const size_t bufferSize = 4096;
946 char buffer[bufferSize];
947 do {
948 size_t bytesRead = stream->read(buffer, bufferSize);
949 tempStream.write(buffer, bytesRead);
950 } while (!stream->isAtEnd());
951 return tempStream.detachAsData();
952}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition: SkData.cpp:208
bool write(const void *buffer, size_t size) override
Definition: SkStream.cpp:535
sk_sp< SkData > detachAsData()
Definition: SkStream.cpp:707
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

◆ SkStreamCopy()

bool SkStreamCopy ( SkWStream out,
SkStream input 
)

Copies the input stream from the current position to the end. Does not rewind the input stream.

Definition at line 954 of file SkStream.cpp.

954 {
955 const char* base = static_cast<const char*>(input->getMemoryBase());
956 if (base && input->hasPosition() && input->hasLength()) {
957 // Shortcut that avoids the while loop.
958 size_t position = input->getPosition();
959 size_t length = input->getLength();
960 SkASSERT(length >= position);
961 return out->write(&base[position], length - position);
962 }
963 char scratch[4096];
964 size_t count;
965 while (true) {
966 count = input->read(scratch, sizeof(scratch));
967 if (0 == count) {
968 return true;
969 }
970 if (!out->write(scratch, count)) {
971 return false;
972 }
973 }
974}
int count
Definition: FontMgrTest.cpp:50
virtual bool hasPosition() const
Definition: SkStream.h:117
virtual size_t getPosition() const
Definition: SkStream.h:119
virtual size_t getLength() const
Definition: SkStream.h:137
virtual const void * getMemoryBase()
Definition: SkStream.h:141
virtual bool hasLength() const
Definition: SkStream.h:135
virtual size_t read(void *buffer, size_t size)=0
size_t length

◆ StreamRemainingLengthIsBelow()

bool StreamRemainingLengthIsBelow ( SkStream stream,
size_t  len 
)

Definition at line 976 of file SkStream.cpp.

976 {
978 if (stream->hasLength()) {
979 if (stream->hasPosition()) {
980 size_t remainingBytes = stream->getLength() - stream->getPosition();
981 return remainingBytes < len;
982 }
983 // We don't know the position, but we can still return true if the
984 // stream's entire length is shorter than the requested length.
985 return stream->getLength() < len;
986 }
987 return false;
988}