Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 {
912 FILE* file = sk_fopen(path, kRead_SkFILE_Flag);
913 if (nullptr == file) {
914 return nullptr;
915 }
916
917 auto data = SkData::MakeFromFILE(file);
918 sk_fclose(file);
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 data
Definition switches.h:41

◆ 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) {
278 return SkData::MakeWithCopy(src, size);
279 } else {
280 return SkData::MakeWithoutCopy(src, size);
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

◆ 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}

◆ 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
static const uint8_t buffer[]

◆ 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
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 {
977 SkASSERT(stream);
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}