Flutter Engine
The Flutter Engine
SkPictureData.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
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 SkPictureData_DEFINED
9#define SkPictureData_DEFINED
10
12#include "include/core/SkData.h"
16#include "include/core/SkPath.h"
18#include "include/core/SkRect.h"
27
28#include <cstdint>
29#include <memory>
30
31class SkFactorySet;
32class SkPictureRecord;
33class SkRefCntSet;
34class SkStream;
35class SkWStream;
36class SkWriteBuffer;
37struct SkDeserialProcs;
38struct SkSerialProcs;
39
40struct SkPictInfo {
41 SkPictInfo() : fVersion(~0U) {}
42
43 uint32_t getVersion() const {
44 SkASSERT(fVersion != ~0U);
45 return fVersion;
46 }
47
48 void setVersion(uint32_t version) {
49 SkASSERT(version != ~0U);
50 fVersion = version;
51 }
52
53public:
54 char fMagic[8];
55private:
56 uint32_t fVersion;
57public:
59};
60
61#define SK_PICT_READER_TAG SkSetFourByteTag('r', 'e', 'a', 'd')
62#define SK_PICT_FACTORY_TAG SkSetFourByteTag('f', 'a', 'c', 't')
63#define SK_PICT_TYPEFACE_TAG SkSetFourByteTag('t', 'p', 'f', 'c')
64#define SK_PICT_PICTURE_TAG SkSetFourByteTag('p', 'c', 't', 'r')
65#define SK_PICT_DRAWABLE_TAG SkSetFourByteTag('d', 'r', 'a', 'w')
66
67// This tag specifies the size of the ReadBuffer, needed for the following tags
68#define SK_PICT_BUFFER_SIZE_TAG SkSetFourByteTag('a', 'r', 'a', 'y')
69// these are all inside the ARRAYS tag
70#define SK_PICT_PAINT_BUFFER_TAG SkSetFourByteTag('p', 'n', 't', ' ')
71#define SK_PICT_PATH_BUFFER_TAG SkSetFourByteTag('p', 't', 'h', ' ')
72#define SK_PICT_TEXTBLOB_BUFFER_TAG SkSetFourByteTag('b', 'l', 'o', 'b')
73#define SK_PICT_SLUG_BUFFER_TAG SkSetFourByteTag('s', 'l', 'u', 'g')
74#define SK_PICT_VERTICES_BUFFER_TAG SkSetFourByteTag('v', 'e', 'r', 't')
75#define SK_PICT_IMAGE_BUFFER_TAG SkSetFourByteTag('i', 'm', 'a', 'g')
76
77// Always write this last (with no length field afterwards)
78#define SK_PICT_EOF_TAG SkSetFourByteTag('e', 'o', 'f', ' ')
79
80template <typename T>
82 const skia_private::TArray<sk_sp<T>>& array) {
83 int index = reader->readInt();
84 return reader->validate(index > 0 && index <= array.size()) ? array[index - 1].get() : nullptr;
85}
86
88public:
89 SkPictureData(const SkPictureRecord& record, const SkPictInfo&);
90 // Does not affect ownership of SkStream.
92 const SkPictInfo&,
93 const SkDeserialProcs&,
95 int recursionLimit);
97
98 void serialize(SkWStream*, const SkSerialProcs&, SkRefCntSet*, bool textBlobsOnly=false) const;
99 void flatten(SkWriteBuffer&) const;
100
101 const SkPictInfo& info() const { return fInfo; }
102
103 const sk_sp<SkData>& opData() const { return fOpData; }
104
105protected:
106 explicit SkPictureData(const SkPictInfo& info);
107
108 // Does not affect ownership of SkStream.
110 int recursionLimit);
112
113public:
114 const SkImage* getImage(SkReadBuffer* reader) const {
115 // images are written base-0, unlike paths, pictures, drawables, etc.
116 const int index = reader->readInt();
117 return reader->validateIndex(index, fImages.size()) ? fImages[index].get() : nullptr;
118 }
119
120 const SkPath& getPath(SkReadBuffer* reader) const {
121 int index = reader->readInt();
122 return reader->validate(index > 0 && index <= fPaths.size()) ?
123 fPaths[index - 1] : fEmptyPath;
124 }
125
126 const SkPicture* getPicture(SkReadBuffer* reader) const {
127 return read_index_base_1_or_null(reader, fPictures);
128 }
129
131 return read_index_base_1_or_null(reader, fDrawables);
132 }
133
134 // Return a paint if one was used for this op, or nullptr if none was used.
135 const SkPaint* optionalPaint(SkReadBuffer* reader) const;
136
137 // Return the paint used for this op, invalidating the SkReadBuffer if there appears to be none.
138 // The returned paint is always safe to use.
139 const SkPaint& requiredPaint(SkReadBuffer* reader) const;
140
141 const SkTextBlob* getTextBlob(SkReadBuffer* reader) const {
142 return read_index_base_1_or_null(reader, fTextBlobs);
143 }
144
145 const sktext::gpu::Slug* getSlug(SkReadBuffer* reader) const {
146 return read_index_base_1_or_null(reader, fSlugs);
147 }
148
149 const SkVertices* getVertices(SkReadBuffer* reader) const {
150 return read_index_base_1_or_null(reader, fVertices);
151 }
152
153private:
154 // these help us with reading/writing
155 // Does not affect ownership of SkStream.
156 bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size,
158 int recursionLimit);
159 void parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size);
160 void flattenToBuffer(SkWriteBuffer&, bool textBlobsOnly) const;
161
164
165 sk_sp<SkData> fOpData; // opcodes and parameters
166
167 const SkPath fEmptyPath;
168 const SkBitmap fEmptyBitmap;
169
176
177 SkTypefacePlayback fTFPlayback;
178 std::unique_ptr<SkFactoryPlayback> fFactoryPlayback;
179
180 const SkPictInfo fInfo;
181
182 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec);
183 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec, const SkSerialProcs&);
184
185 void initForPlayback() const;
186};
187
188#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
T * read_index_base_1_or_null(SkReadBuffer *reader, const skia_private::TArray< sk_sp< T > > &array)
Definition: SkPictureData.h:81
Definition: SkPath.h:59
const sktext::gpu::Slug * getSlug(SkReadBuffer *reader) const
bool parseBuffer(SkReadBuffer &buffer)
static SkPictureData * CreateFromStream(SkStream *, const SkPictInfo &, const SkDeserialProcs &, SkTypefacePlayback *, int recursionLimit)
static SkPictureData * CreateFromBuffer(SkReadBuffer &, const SkPictInfo &)
bool parseStream(SkStream *, const SkDeserialProcs &, SkTypefacePlayback *, int recursionLimit)
const SkPaint * optionalPaint(SkReadBuffer *reader) const
const SkPath & getPath(SkReadBuffer *reader) const
const SkVertices * getVertices(SkReadBuffer *reader) const
const sk_sp< SkData > & opData() const
const SkTextBlob * getTextBlob(SkReadBuffer *reader) const
const SkPaint & requiredPaint(SkReadBuffer *reader) const
void flatten(SkWriteBuffer &) const
const SkImage * getImage(SkReadBuffer *reader) const
const SkPicture * getPicture(SkReadBuffer *reader) const
SkDrawable * getDrawable(SkReadBuffer *reader) const
SkPictureData(const SkPictureRecord &record, const SkPictInfo &)
void serialize(SkWStream *, const SkSerialProcs &, SkRefCntSet *, bool textBlobsOnly=false) const
const SkPictInfo & info() const
bool validate(bool isValid)
Definition: SkReadBuffer.h:191
bool validateIndex(int index, int count)
Definition: SkReadBuffer.h:209
int32_t readInt()
int size() const
Definition: SkTArray.h:421
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
void setVersion(uint32_t version)
Definition: SkPictureData.h:48
uint32_t getVersion() const
Definition: SkPictureData.h:43
SkRect fCullRect
Definition: SkPictureData.h:58
char fMagic[8]
Definition: SkPictureData.h:54