Flutter Engine
The Flutter Engine
SkBuffer.h
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkBuffer_DEFINED
9#define SkBuffer_DEFINED
10
13#include "src/base/SkSafeMath.h"
14
15#include <cstddef>
16#include <cstdint>
17
18typedef float SkScalar;
19
20/** \class SkRBuffer
21
22 Light weight class for reading data from a memory block.
23 The RBuffer is given the buffer to read from, with either a specified size
24 or no size (in which case no range checking is performed). It is iillegal
25 to attempt to read a value from an empty RBuffer (data == null).
26*/
28public:
29 SkRBuffer() : fData(nullptr), fPos(nullptr), fStop(nullptr) {}
30
31 /** Initialize RBuffer with a data point and length.
32 */
33 SkRBuffer(const void* data, size_t size) {
34 SkASSERT(data != nullptr || size == 0);
35 fData = (const char*)data;
36 fPos = (const char*)data;
37 fStop = (const char*)data + size;
38 }
39
40 /** Return the number of bytes that have been read from the beginning
41 of the data pointer.
42 */
43 size_t pos() const { return fPos - fData; }
44 /** Return the total size of the data pointer. Only defined if the length was
45 specified in the constructor or in a call to reset().
46 */
47 size_t size() const { return fStop - fData; }
48 /** Return true if the buffer has read to the end of the data pointer.
49 Only defined if the length was specified in the constructor or in a call
50 to reset(). Always returns true if the length was not specified.
51 */
52 bool eof() const { return fPos >= fStop; }
53
54 size_t available() const { return fStop - fPos; }
55
56 bool isValid() const { return fValid; }
57
58 /** Read the specified number of bytes from the data pointer. If buffer is not
59 null, copy those bytes into buffer.
60 */
61 bool read(void* buffer, size_t size);
62 bool skipToAlign4();
63
64 bool readU8(uint8_t* x) { return this->read(x, 1); }
65 bool readS32(int32_t* x) { return this->read(x, 4); }
66 bool readU32(uint32_t* x) { return this->read(x, 4); }
67
68 // returns nullptr on failure
69 const void* skip(size_t bytes);
70 template <typename T> const T* skipCount(size_t count) {
71 return static_cast<const T*>(this->skip(SkSafeMath::Mul(count, sizeof(T))));
72 }
73
74private:
75 const char* fData;
76 const char* fPos;
77 const char* fStop;
78 bool fValid = true;
79};
80
81/** \class SkWBuffer
82
83 Light weight class for writing data to a memory block.
84 The WBuffer is given the buffer to write into, with either a specified size
85 or no size, in which case no range checking is performed. An empty WBuffer
86 is legal, in which case no data is ever written, but the relative pos()
87 is updated.
88*/
90public:
91 SkWBuffer() : fData(nullptr), fPos(nullptr), fStop(nullptr) {}
92 SkWBuffer(void* data) { reset(data); }
93 SkWBuffer(void* data, size_t size) { reset(data, size); }
94
95 void reset(void* data) {
96 fData = (char*)data;
97 fPos = (char*)data;
98 fStop = nullptr; // no bounds checking
99 }
100
101 void reset(void* data, size_t size) {
102 SkASSERT(data != nullptr || size == 0);
103 fData = (char*)data;
104 fPos = (char*)data;
105 fStop = (char*)data + size;
106 }
107
108 size_t pos() const { return fPos - fData; }
109 void* skip(size_t size); // return start of skipped data
110
111 void write(const void* buffer, size_t size) {
112 if (size) {
113 this->writeNoSizeCheck(buffer, size);
114 }
115 }
116
117 size_t padToAlign4();
118
119 void writePtr(const void* x) { this->writeNoSizeCheck(&x, sizeof(x)); }
120 void writeScalar(SkScalar x) { this->writeNoSizeCheck(&x, 4); }
121 void write32(int32_t x) { this->writeNoSizeCheck(&x, 4); }
122 void write16(int16_t x) { this->writeNoSizeCheck(&x, 2); }
123 void write8(int8_t x) { this->writeNoSizeCheck(&x, 1); }
124 void writeBool(bool x) { this->write8(x); }
125
126private:
127 void writeNoSizeCheck(const void* buffer, size_t size);
128
129 char* fData;
130 char* fPos;
131 char* fStop;
132};
133
134#endif
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
float SkScalar
Definition: SkBuffer.h:18
bool eof() const
Definition: SkBuffer.h:52
bool read(void *buffer, size_t size)
Definition: SkBuffer.cpp:27
bool isValid() const
Definition: SkBuffer.h:56
size_t pos() const
Definition: SkBuffer.h:43
const T * skipCount(size_t count)
Definition: SkBuffer.h:70
size_t available() const
Definition: SkBuffer.h:54
SkRBuffer()
Definition: SkBuffer.h:29
bool readS32(int32_t *x)
Definition: SkBuffer.h:65
size_t size() const
Definition: SkBuffer.h:47
SkRBuffer(const void *data, size_t size)
Definition: SkBuffer.h:33
const void * skip(size_t bytes)
Definition: SkBuffer.cpp:17
bool skipToAlign4()
Definition: SkBuffer.cpp:35
bool readU32(uint32_t *x)
Definition: SkBuffer.h:66
bool readU8(uint8_t *x)
Definition: SkBuffer.h:64
static size_t Mul(size_t x, size_t y)
Definition: SkSafeMath.cpp:16
SkWBuffer(void *data, size_t size)
Definition: SkBuffer.h:93
void write16(int16_t x)
Definition: SkBuffer.h:122
void * skip(size_t size)
Definition: SkBuffer.cpp:49
size_t padToAlign4()
Definition: SkBuffer.cpp:63
void write32(int32_t x)
Definition: SkBuffer.h:121
void writePtr(const void *x)
Definition: SkBuffer.h:119
void writeBool(bool x)
Definition: SkBuffer.h:124
SkWBuffer()
Definition: SkBuffer.h:91
size_t pos() const
Definition: SkBuffer.h:108
void reset(void *data, size_t size)
Definition: SkBuffer.h:101
SkWBuffer(void *data)
Definition: SkBuffer.h:92
void write8(int8_t x)
Definition: SkBuffer.h:123
void writeScalar(SkScalar x)
Definition: SkBuffer.h:120
void reset(void *data)
Definition: SkBuffer.h:95
void write(const void *buffer, size_t size)
Definition: SkBuffer.h:111
float SkScalar
Definition: extension.cpp:12
double x
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
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
#define T
Definition: precompiler.cc:65
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63