Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
SkPicture Class Referenceabstract

#include <SkPicture.h>

Inheritance diagram for SkPicture:
SkRefCnt SkRefCntBase SkBigPicture SkEmptyPicture

Classes

class  AbortCallback
 

Public Member Functions

 ~SkPicture () override
 
virtual void playback (SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
 
virtual SkRect cullRect () const =0
 
uint32_t uniqueID () const
 
sk_sp< SkDataserialize (const SkSerialProcs *procs=nullptr) const
 
void serialize (SkWStream *stream, const SkSerialProcs *procs=nullptr) const
 
virtual int approximateOpCount (bool nested=false) const =0
 
virtual size_t approximateBytesUsed () const =0
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, SkFilterMode mode) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkPictureMakeFromStream (SkStream *stream, const SkDeserialProcs *procs=nullptr)
 
static sk_sp< SkPictureMakeFromData (const SkData *data, const SkDeserialProcs *procs=nullptr)
 
static sk_sp< SkPictureMakeFromData (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
static sk_sp< SkPictureMakePlaceholder (SkRect cull)
 

Private Member Functions

virtual const class SkBigPictureasSkBigPicture () const
 

Friends

class SkBigPicture
 
class SkEmptyPicture
 
class SkPicturePriv
 
class SkPictureData
 
bool SkPicture_StreamIsSKP (SkStream *, struct SkPictInfo *)
 

Detailed Description

SkPicture records drawing commands made to SkCanvas. The command stream may be played in whole or in part at a later time.

SkPicture is an abstract class. SkPicture may be generated by SkPictureRecorder or SkDrawable, or from SkPicture previously saved to SkData or SkStream.

SkPicture may contain any SkCanvas drawing command, as well as one or more SkCanvas matrix or SkCanvas clip. SkPicture has a cull SkRect, which is used as a bounding box hint. To limit SkPicture bounds, use SkCanvas clip when recording or drawing SkPicture.

Definition at line 44 of file SkPicture.h.

Constructor & Destructor Documentation

◆ ~SkPicture()

SkPicture::~SkPicture ( )
override

Definition at line 52 of file SkPicture.cpp.

52 {
53 if (fAddedToCache.load()) {
55 }
56}
static uint64_t MakeSharedID(uint32_t pictureID)
Definition: SkPicturePriv.h:40
static void PostPurgeSharedID(uint64_t sharedID)

Member Function Documentation

◆ approximateBytesUsed()

virtual size_t SkPicture::approximateBytesUsed ( ) const
pure virtual

Returns the approximate byte size of SkPicture. Does not include large objects referenced by SkPicture.

Returns
approximate size

example: https://fiddle.skia.org/c/@Picture_approximateBytesUsed

Implemented in SkBigPicture, and SkEmptyPicture.

◆ approximateOpCount()

virtual int SkPicture::approximateOpCount ( bool  nested = false) const
pure virtual

Returns the approximate number of operations in SkPicture. Returned value may be greater or less than the number of SkCanvas calls recorded: some calls may be recorded as more than one operation, other calls may be optimized away.

Parameters
nestedif true, include the op-counts of nested pictures as well, else just return count the ops in the top-level picture.
Returns
approximate operation count

example: https://fiddle.skia.org/c/@Picture_approximateOpCount

Implemented in SkBigPicture, and SkEmptyPicture.

◆ asSkBigPicture()

virtual const class SkBigPicture * SkPicture::asSkBigPicture ( ) const
inlineprivatevirtual

Reimplemented in SkBigPicture.

Definition at line 277 of file SkPicture.h.

277{ return nullptr; }

◆ cullRect()

virtual SkRect SkPicture::cullRect ( ) const
pure virtual

Returns cull SkRect for this picture, passed in when SkPicture was created. Returned SkRect does not specify clipping SkRect for SkPicture; cull is hint of SkPicture bounds.

SkPicture is free to discard recorded drawing commands that fall outside cull.

Returns
bounds passed when SkPicture was created

example: https://fiddle.skia.org/c/@Picture_cullRect

Implemented in SkBigPicture, and SkEmptyPicture.

◆ MakeFromData() [1/2]

sk_sp< SkPicture > SkPicture::MakeFromData ( const SkData data,
const SkDeserialProcs procs = nullptr 
)
static

Recreates SkPicture that was serialized into data. Returns constructed SkPicture if successful; otherwise, returns nullptr. Fails if data does not permit constructing valid SkPicture.

procs->fPictureProc permits supplying a custom function to decode SkPicture. If procs->fPictureProc is nullptr, default decoding is used. procs->fPictureCtx may be used to provide user context to procs->fPictureProc; procs->fPictureProc is called with a pointer to data, data byte length, and user context.

Parameters
datacontainer for serial data
procscustom serial data decoders; may be nullptr
Returns
SkPicture constructed from data

Definition at line 160 of file SkPicture.cpp.

160 {
161 if (!data) {
162 return nullptr;
163 }
164 SkMemoryStream stream(data->data(), data->size());
165 return MakeFromStreamPriv(&stream, procs, nullptr, kNestedSKPLimit);
166}
static const int kNestedSKPLimit
Definition: SkPicture.cpp:145
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ MakeFromData() [2/2]

sk_sp< SkPicture > SkPicture::MakeFromData ( const void *  data,
size_t  size,
const SkDeserialProcs procs = nullptr 
)
static
Parameters
datapointer to serial data
sizesize of data
procscustom serial data decoders; may be nullptr
Returns
SkPicture constructed from data

Definition at line 151 of file SkPicture.cpp.

152 {
153 if (!data) {
154 return nullptr;
155 }
157 return MakeFromStreamPriv(&stream, procs, nullptr, kNestedSKPLimit);
158}
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

◆ MakeFromStream()

sk_sp< SkPicture > SkPicture::MakeFromStream ( SkStream stream,
const SkDeserialProcs procs = nullptr 
)
static

Recreates SkPicture that was serialized into a stream. Returns constructed SkPicture if successful; otherwise, returns nullptr. Fails if data does not permit constructing valid SkPicture.

procs->fPictureProc permits supplying a custom function to decode SkPicture. If procs->fPictureProc is nullptr, default decoding is used. procs->fPictureCtx may be used to provide user context to procs->fPictureProc; procs->fPictureProc is called with a pointer to data, data byte length, and user context.

Parameters
streamcontainer for serial data
procscustom serial data decoders; may be nullptr
Returns
SkPicture constructed from stream data

Definition at line 147 of file SkPicture.cpp.

147 {
148 return MakeFromStreamPriv(stream, procs, nullptr, kNestedSKPLimit);
149}

◆ MakePlaceholder()

sk_sp< SkPicture > SkPicture::MakePlaceholder ( SkRect  cull)
static

Returns a placeholder SkPicture. Result does not draw, and contains only cull SkRect, a hint of its bounds. Result is immutable; it cannot be changed later. Result identifier is unique.

Returned placeholder can be intercepted during playback to insert other commands into SkCanvas draw stream.

Parameters
cullplaceholder dimensions
Returns
placeholder with unique identifier

example: https://fiddle.skia.org/c/@Picture_MakePlaceholder

Definition at line 337 of file SkPicture.cpp.

337 {
338 struct Placeholder : public SkPicture {
339 explicit Placeholder(SkRect cull) : fCull(cull) {}
340
341 void playback(SkCanvas*, AbortCallback*) const override { }
342
343 // approximateOpCount() needs to be greater than kMaxPictureOpsToUnrollInsteadOfRef
344 // (SkCanvasPriv.h) to avoid unrolling this into a parent picture.
345 int approximateOpCount(bool) const override {
347 }
348 size_t approximateBytesUsed() const override { return sizeof(*this); }
349 SkRect cullRect() const override { return fCull; }
350
351 SkRect fCull;
352 };
353 return sk_make_sp<Placeholder>(cull);
354}
constexpr int kMaxPictureOpsToUnrollInsteadOfRef
Definition: SkCanvasPriv.h:108
virtual SkRect cullRect() const =0
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
virtual size_t approximateBytesUsed() const =0
virtual int approximateOpCount(bool nested=false) const =0

◆ makeShader() [1/2]

sk_sp< SkShader > SkPicture::makeShader ( SkTileMode  tmx,
SkTileMode  tmy,
SkFilterMode  mode 
) const
inline

Definition at line 246 of file SkPicture.h.

246 {
247 return this->makeShader(tmx, tmy, mode, nullptr, nullptr);
248 }
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
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 mode
Definition: switches.h:228
SkTileMode tmy
SkTileMode tmx

◆ makeShader() [2/2]

sk_sp< SkShader > SkPicture::makeShader ( SkTileMode  tmx,
SkTileMode  tmy,
SkFilterMode  mode,
const SkMatrix localMatrix,
const SkRect tileRect 
) const

Return a new shader that will draw with this picture.

Parameters
tmxThe tiling mode to use when sampling in the x-direction.
tmyThe tiling mode to use when sampling in the y-direction.
modeHow to filter the tiles
localMatrixOptional matrix used when sampling
tileRectThe tile rectangle in picture coordinates: this represents the subset (or superset) of the picture used when building a tile. It is not affected by localMatrix and does not imply scaling (only translation and cropping). If null, the tile rect is considered equal to the picture bounds.
Returns
Returns a new shader object. Note: this function never returns null.

Definition at line 39 of file SkPictureShader.cpp.

40 {
41 if (localMatrix && !localMatrix->invert(nullptr)) {
42 return nullptr;
43 }
44 return SkPictureShader::Make(sk_ref_sp(this), tmx, tmy, filter, localMatrix, tile);
45}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206
static sk_sp< SkShader > Make(sk_sp< SkPicture >, SkTileMode, SkTileMode, SkFilterMode, const SkMatrix *, const SkRect *)

◆ playback()

virtual void SkPicture::playback ( SkCanvas canvas,
AbortCallback callback = nullptr 
) const
pure virtual

Replays the drawing commands on the specified canvas. In the case that the commands are recorded, each command in the SkPicture is sent separately to canvas.

To add a single command to draw SkPicture to recording canvas, call SkCanvas::drawPicture instead.

Parameters
canvasreceiver of drawing commands
callbackallows interruption of playback

example: https://fiddle.skia.org/c/@Picture_playback

Implemented in SkBigPicture, and SkEmptyPicture.

◆ serialize() [1/2]

sk_sp< SkData > SkPicture::serialize ( const SkSerialProcs procs = nullptr) const

Returns storage containing SkData describing SkPicture, using optional custom encoders.

procs->fPictureProc permits supplying a custom function to encode SkPicture. If procs->fPictureProc is nullptr, default encoding is used. procs->fPictureCtx may be used to provide user context to procs->fPictureProc; procs->fPictureProc is called with a pointer to SkPicture and user context.

The default behavior for serializing SkImages is to encode a nullptr. Should clients want to, for example, encode these SkImages as PNGs so they can be deserialized, they must provide SkSerialProcs with the fImageProc set to do so.

Parameters
procscustom serial data encoders; may be nullptr
Returns
storage containing serialized SkPicture

example: https://fiddle.skia.org/c/@Picture_serialize

Definition at line 249 of file SkPicture.cpp.

249 {
251 this->serialize(&stream, procs, nullptr);
252 return stream.detachAsData();
253}
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
Definition: SkPicture.cpp:249

◆ serialize() [2/2]

void SkPicture::serialize ( SkWStream stream,
const SkSerialProcs procs = nullptr 
) const

Writes picture to stream, using optional custom encoders.

procs->fPictureProc permits supplying a custom function to encode SkPicture. If procs->fPictureProc is nullptr, default encoding is used. procs->fPictureCtx may be used to provide user context to procs->fPictureProc; procs->fPictureProc is called with a pointer to SkPicture and user context.

The default behavior for serializing SkImages is to encode a nullptr. Should clients want to, for example, encode these SkImages as PNGs so they can be deserialized, they must provide SkSerialProcs with the fImageProc set to do so.

Parameters
streamwritable serial data stream
procscustom serial data encoders; may be nullptr

example: https://fiddle.skia.org/c/@Picture_serialize_2

Definition at line 245 of file SkPicture.cpp.

245 {
246 this->serialize(stream, procs, nullptr);
247}

◆ uniqueID()

uint32_t SkPicture::uniqueID ( ) const
inline

Returns a non-zero value unique among SkPicture in Skia process.

Returns
identifier for SkPicture

Definition at line 155 of file SkPicture.h.

155{ return fUniqueID; }

Friends And Related Function Documentation

◆ SkBigPicture

friend class SkBigPicture
friend

Definition at line 253 of file SkPicture.h.

◆ SkEmptyPicture

friend class SkEmptyPicture
friend

Definition at line 254 of file SkPicture.h.

◆ SkPicture_StreamIsSKP

bool SkPicture_StreamIsSKP ( SkStream ,
struct SkPictInfo  
)
friend

Definition at line 109 of file SkPicture.cpp.

109 {
110 return SkPicture::StreamIsSKP(stream, pInfo);
111}

◆ SkPictureData

friend class SkPictureData
friend

Definition at line 262 of file SkPicture.h.

◆ SkPicturePriv

friend class SkPicturePriv
friend

Definition at line 255 of file SkPicture.h.


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