Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkPictureData Class Reference

#include <SkPictureData.h>

Public Member Functions

 SkPictureData (const SkPictureRecord &record, const SkPictInfo &)
 
void serialize (SkWStream *, const SkSerialProcs &, SkRefCntSet *, bool textBlobsOnly=false) const
 
void flatten (SkWriteBuffer &) const
 
const SkPictInfoinfo () const
 
const sk_sp< SkData > & opData () const
 
const SkImagegetImage (SkReadBuffer *reader) const
 
const SkPathgetPath (SkReadBuffer *reader) const
 
const SkPicturegetPicture (SkReadBuffer *reader) const
 
SkDrawablegetDrawable (SkReadBuffer *reader) const
 
const SkPaintoptionalPaint (SkReadBuffer *reader) const
 
const SkPaintrequiredPaint (SkReadBuffer *reader) const
 
const SkTextBlobgetTextBlob (SkReadBuffer *reader) const
 
const sktext::gpu::SluggetSlug (SkReadBuffer *reader) const
 
const SkVerticesgetVertices (SkReadBuffer *reader) const
 

Static Public Member Functions

static SkPictureDataCreateFromStream (SkStream *, const SkPictInfo &, const SkDeserialProcs &, SkTypefacePlayback *, int recursionLimit)
 
static SkPictureDataCreateFromBuffer (SkReadBuffer &, const SkPictInfo &)
 

Protected Member Functions

 SkPictureData (const SkPictInfo &info)
 
bool parseStream (SkStream *, const SkDeserialProcs &, SkTypefacePlayback *, int recursionLimit)
 
bool parseBuffer (SkReadBuffer &buffer)
 

Detailed Description

Definition at line 87 of file SkPictureData.h.

Constructor & Destructor Documentation

◆ SkPictureData() [1/2]

SkPictureData::SkPictureData ( const SkPictureRecord record,
const SkPictInfo info 
)

Definition at line 50 of file SkPictureData.cpp.

52 : fPictures(record.getPictures())
53 , fDrawables(record.getDrawables())
54 , fTextBlobs(record.getTextBlobs())
55 , fVertices(record.getVertices())
56 , fImages(record.getImages())
57 , fSlugs(record.getSlugs())
58 , fInfo(info) {
59
60 fOpData = record.opData();
61
62 fPaints = record.fPaints;
63
64 fPaths.reset(record.fPaths.count());
65 record.fPaths.foreach([this](const SkPath& path, int n) {
66 // These indices are logically 1-based, but we need to serialize them
67 // 0-based to keep the deserializing SkPictureData::getPath() working.
68 fPaths[n-1] = path;
69 });
70
71 this->initForPlayback();
72}
Definition: SkPath.h:59
const SkPictInfo & info() const
const skia_private::TArray< sk_sp< const SkPicture > > & getPictures() const
const skia_private::TArray< sk_sp< const SkTextBlob > > & getTextBlobs() const
const skia_private::TArray< sk_sp< const SkImage > > & getImages() const
const skia_private::TArray< sk_sp< const SkVertices > > & getVertices() const
sk_sp< SkData > opData() const
const skia_private::TArray< sk_sp< SkDrawable > > & getDrawables() const
const skia_private::TArray< sk_sp< const sktext::gpu::Slug > > & getSlugs() const
void reset(int n)
Definition: SkTArray.h:144
void foreach(Fn &&fn)
Definition: SkTHash.h:521
int count() const
Definition: SkTHash.h:471
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

◆ SkPictureData() [2/2]

SkPictureData::SkPictureData ( const SkPictInfo info)
explicitprotected

Definition at line 40 of file SkPictureData.cpp.

41 : fInfo(info) {}

Member Function Documentation

◆ CreateFromBuffer()

SkPictureData * SkPictureData::CreateFromBuffer ( SkReadBuffer buffer,
const SkPictInfo info 
)
static

Definition at line 534 of file SkPictureData.cpp.

535 {
536 std::unique_ptr<SkPictureData> data(new SkPictureData(info));
537 buffer.setVersion(info.getVersion());
538
539 if (!data->parseBuffer(buffer)) {
540 return nullptr;
541 }
542 return data.release();
543}
SkPictureData(const SkPictureRecord &record, const SkPictInfo &)
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
uint32_t getVersion() const
Definition: SkPictureData.h:43
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ CreateFromStream()

SkPictureData * SkPictureData::CreateFromStream ( SkStream stream,
const SkPictInfo info,
const SkDeserialProcs procs,
SkTypefacePlayback topLevelTFPlayback,
int  recursionLimit 
)
static

Definition at line 518 of file SkPictureData.cpp.

522 {
523 std::unique_ptr<SkPictureData> data(new SkPictureData(info));
524 if (!topLevelTFPlayback) {
525 topLevelTFPlayback = &data->fTFPlayback;
526 }
527
528 if (!data->parseStream(stream, procs, topLevelTFPlayback, recursionLimit)) {
529 return nullptr;
530 }
531 return data.release();
532}

◆ flatten()

void SkPictureData::flatten ( SkWriteBuffer buffer) const

Definition at line 281 of file SkPictureData.cpp.

281 {
283 buffer.writeByteArray(fOpData->bytes(), fOpData->size());
284
285 if (!fPictures.empty()) {
287 for (const auto& pic : fPictures) {
289 }
290 }
291
292 if (!fDrawables.empty()) {
294 for (const auto& draw : fDrawables) {
295 buffer.writeFlattenable(draw.get());
296 }
297 }
298
299 // Write this picture playback's data into a writebuffer
300 this->flattenToBuffer(buffer, false);
301 buffer.write32(SK_PICT_EOF_TAG);
302}
static void write_tag_size(SkWriteBuffer &buffer, uint32_t tag, size_t size)
#define SK_PICT_PICTURE_TAG
Definition: SkPictureData.h:64
#define SK_PICT_EOF_TAG
Definition: SkPictureData.h:78
#define SK_PICT_DRAWABLE_TAG
Definition: SkPictureData.h:65
#define SK_PICT_READER_TAG
Definition: SkPictureData.h:61
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
const uint8_t * bytes() const
Definition: SkData.h:43
size_t size() const
Definition: SkData.h:30
static void Flatten(const sk_sp< const SkPicture >, SkWriteBuffer &buffer)
Definition: SkPicture.cpp:314
bool empty() const
Definition: SkTArray.h:199
int size() const
Definition: SkTArray.h:421

◆ getDrawable()

SkDrawable * SkPictureData::getDrawable ( SkReadBuffer reader) const
inline

Definition at line 130 of file SkPictureData.h.

130 {
131 return read_index_base_1_or_null(reader, fDrawables);
132 }
T * read_index_base_1_or_null(SkReadBuffer *reader, const skia_private::TArray< sk_sp< T > > &array)
Definition: SkPictureData.h:81

◆ getImage()

const SkImage * SkPictureData::getImage ( SkReadBuffer reader) const
inline

Definition at line 114 of file SkPictureData.h.

114 {
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 }
bool validateIndex(int index, int count)
Definition: SkReadBuffer.h:209
int32_t readInt()

◆ getPath()

const SkPath & SkPictureData::getPath ( SkReadBuffer reader) const
inline

Definition at line 120 of file SkPictureData.h.

120 {
121 int index = reader->readInt();
122 return reader->validate(index > 0 && index <= fPaths.size()) ?
123 fPaths[index - 1] : fEmptyPath;
124 }
bool validate(bool isValid)
Definition: SkReadBuffer.h:191

◆ getPicture()

const SkPicture * SkPictureData::getPicture ( SkReadBuffer reader) const
inline

Definition at line 126 of file SkPictureData.h.

126 {
127 return read_index_base_1_or_null(reader, fPictures);
128 }

◆ getSlug()

const sktext::gpu::Slug * SkPictureData::getSlug ( SkReadBuffer reader) const
inline

Definition at line 145 of file SkPictureData.h.

145 {
146 return read_index_base_1_or_null(reader, fSlugs);
147 }

◆ getTextBlob()

const SkTextBlob * SkPictureData::getTextBlob ( SkReadBuffer reader) const
inline

Definition at line 141 of file SkPictureData.h.

141 {
142 return read_index_base_1_or_null(reader, fTextBlobs);
143 }

◆ getVertices()

const SkVertices * SkPictureData::getVertices ( SkReadBuffer reader) const
inline

Definition at line 149 of file SkPictureData.h.

149 {
150 return read_index_base_1_or_null(reader, fVertices);
151 }

◆ info()

const SkPictInfo & SkPictureData::info ( ) const
inline

Definition at line 101 of file SkPictureData.h.

101{ return fInfo; }

◆ opData()

const sk_sp< SkData > & SkPictureData::opData ( ) const
inline

Definition at line 103 of file SkPictureData.h.

103{ return fOpData; }

◆ optionalPaint()

const SkPaint * SkPictureData::optionalPaint ( SkReadBuffer reader) const

Definition at line 583 of file SkPictureData.cpp.

583 {
584 int index = reader->readInt();
585 if (index == 0) {
586 return nullptr; // recorder wrote a zero for no paint (likely drawimage)
587 }
588 return reader->validate(index > 0 && index <= fPaints.size()) ?
589 &fPaints[index - 1] : nullptr;
590}

◆ parseBuffer()

bool SkPictureData::parseBuffer ( SkReadBuffer buffer)
protected

Definition at line 565 of file SkPictureData.cpp.

565 {
566 while (buffer.isValid()) {
567 uint32_t tag = buffer.readUInt();
568 if (SK_PICT_EOF_TAG == tag) {
569 break;
570 }
571 this->parseBufferTag(buffer, tag, buffer.readUInt());
572 }
573
574 // Check that we encountered required tags
575 if (!buffer.validate(this->opData() != nullptr)) {
576 // If we didn't build any opData, we are invalid. Even an EmptyPicture allocates the
577 // SkData for the ops (though its length may be zero).
578 return false;
579 }
580 return true;
581}

◆ parseStream()

bool SkPictureData::parseStream ( SkStream stream,
const SkDeserialProcs procs,
SkTypefacePlayback topLevelTFPlayback,
int  recursionLimit 
)
protected

Definition at line 545 of file SkPictureData.cpp.

548 {
549 for (;;) {
550 uint32_t tag;
551 if (!stream->readU32(&tag)) { return false; }
552 if (SK_PICT_EOF_TAG == tag) {
553 break;
554 }
555
556 uint32_t size;
557 if (!stream->readU32(&size)) { return false; }
558 if (!this->parseStreamTag(stream, tag, size, procs, topLevelTFPlayback, recursionLimit)) {
559 return false; // we're invalid
560 }
561 }
562 return true;
563}
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

◆ requiredPaint()

const SkPaint & SkPictureData::requiredPaint ( SkReadBuffer reader) const

Definition at line 592 of file SkPictureData.cpp.

592 {
593 const SkPaint* paint = this->optionalPaint(reader);
594 if (reader->validate(paint != nullptr)) {
595 return *paint;
596 }
597 static const SkPaint& stub = *(new SkPaint);
598 return stub;
599}
const SkPaint * optionalPaint(SkReadBuffer *reader) const
const Paint & paint
Definition: color_source.cc:38

◆ serialize()

void SkPictureData::serialize ( SkWStream stream,
const SkSerialProcs procs,
SkRefCntSet topLevelTypeFaceSet,
bool  textBlobsOnly = false 
) const

Definition at line 227 of file SkPictureData.cpp.

228 {
229 // This can happen at pretty much any time, so might as well do it first.
231 stream->write(fOpData->bytes(), fOpData->size());
232
233 // We serialize all typefaces into the typeface section of the top-level picture.
234 SkRefCntSet localTypefaceSet;
235 SkRefCntSet* typefaceSet = topLevelTypeFaceSet ? topLevelTypeFaceSet : &localTypefaceSet;
236
237 // We delay serializing the bulk of our data until after we've serialized
238 // factories and typefaces by first serializing to an in-memory write buffer.
239 SkFactorySet factSet; // buffer refs factSet, so factSet must come first.
241 buffer.setFactoryRecorder(sk_ref_sp(&factSet));
242 buffer.setTypefaceRecorder(sk_ref_sp(typefaceSet));
243 this->flattenToBuffer(buffer, textBlobsOnly);
244
245 // Pretend to serialize our sub-pictures for the side effect of filling typefaceSet
246 // with typefaces from sub-pictures.
247 struct DevNull: public SkWStream {
248 DevNull() : fBytesWritten(0) {}
249 size_t fBytesWritten;
250 bool write(const void*, size_t size) override { fBytesWritten += size; return true; }
251 size_t bytesWritten() const override { return fBytesWritten; }
252 } devnull;
253 for (const auto& pic : fPictures) {
254 pic->serialize(&devnull, nullptr, typefaceSet, /*textBlobsOnly=*/ true);
255 }
256 if (textBlobsOnly) { return; } // return early from fake serialize
257
258 // We need to write factories before we write the buffer.
259 // We need to write typefaces before we write the buffer or any sub-picture.
260 WriteFactories(stream, factSet);
261 // Pass the original typefaceproc (if any) now that we're ready to actually serialize the
262 // typefaces. We skipped this proc before, when we were serializing paints, so that the
263 // paints would just write indices into our typeface set.
264 WriteTypefaces(stream, *typefaceSet, procs);
265
266 // Write the buffer.
268 buffer.writeToStream(stream);
269
270 // Write sub-pictures by calling serialize again.
271 if (!fPictures.empty()) {
272 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictures.size());
273 for (const auto& pic : fPictures) {
274 pic->serialize(stream, &procs, typefaceSet, /*textBlobsOnly=*/ false);
275 }
276 }
277
278 stream->write32(SK_PICT_EOF_TAG);
279}
static SkSerialProcs skip_typeface_proc(const SkSerialProcs &procs)
#define SK_PICT_BUFFER_SIZE_TAG
Definition: SkPictureData.h:68
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
void write(SkWStream *wStream, const T &text)
Definition: skqp.cpp:188

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