Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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}
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:139
void foreach(Fn &&fn)
Definition SkTHash.h:506
int count() const
Definition SkTHash.h:460
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}
static const uint8_t buffer[]
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
uint32_t getVersion() const

◆ 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
#define SK_PICT_EOF_TAG
#define SK_PICT_DRAWABLE_TAG
#define SK_PICT_READER_TAG
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)
bool empty() const
Definition SkTArray.h:194
int size() const
Definition SkTArray.h:416

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

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

◆ 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

◆ 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.
230 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size());
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.
267 write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten());
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
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: