Skia
2D Graphics Library
SkPicture Class Referenceabstract

SkPicture records drawing commands made to SkCanvas. More...

#include <SkPicture.h>

Inheritance diagram for SkPicture:

Classes

class  AbortCallback
 AbortCallback is an abstract class. More...
 

Public Member Functions

 ~SkPicture () override
 
virtual void playback (SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
 Replays the drawing commands on the specified canvas. More...
 
virtual SkRect cullRect () const =0
 Returns cull SkRect for this picture, passed in when SkPicture was created. More...
 
uint32_t uniqueID () const
 Returns a non-zero value unique among SkPicture in Skia process. More...
 
sk_sp< SkDataserialize (const SkSerialProcs *procs=nullptr) const
 Returns storage containing SkData describing SkPicture, using optional custom encoders. More...
 
void serialize (SkWStream *stream, const SkSerialProcs *procs=nullptr) const
 Writes picture to stream, using optional custom encoders. More...
 
virtual int approximateOpCount (bool nested=false) const =0
 Returns the approximate number of operations in SkPicture. More...
 
virtual size_t approximateBytesUsed () const =0
 Returns the approximate byte size of SkPicture. More...
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
 Return a new shader that will draw with this picture. More...
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, SkFilterMode mode) const
 
bool unique () const
 May return true if the caller is the only owner. More...
 
void ref () const
 Increment the reference count. More...
 
void unref () const
 Decrement the reference count. More...
 

Static Public Member Functions

static sk_sp< SkPictureMakeFromStream (SkStream *stream, const SkDeserialProcs *procs=nullptr)
 Recreates SkPicture that was serialized into a stream. More...
 
static sk_sp< SkPictureMakeFromData (const SkData *data, const SkDeserialProcs *procs=nullptr)
 Recreates SkPicture that was serialized into data. More...
 
static sk_sp< SkPictureMakeFromData (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
static sk_sp< SkPictureMakePlaceholder (SkRect cull)
 Returns a placeholder SkPicture. More...
 

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.

Constructor & Destructor Documentation

◆ ~SkPicture()

SkPicture::~SkPicture ( )
override

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

◆ 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

◆ 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

◆ MakeFromData() [1/2]

static 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

◆ MakeFromData() [2/2]

static 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

◆ MakeFromStream()

static 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

◆ MakePlaceholder()

static 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

◆ makeShader() [1/2]

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

◆ 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
tileThe 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.

◆ 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

◆ ref()

void SkRefCntBase::ref ( ) const
inlineinherited

Increment the reference count.

Must be balanced by a call to unref().

◆ 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

◆ 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

◆ unique()

bool SkRefCntBase::unique ( ) const
inlineinherited

May return true if the caller is the only owner.

Ensures that all previous owner's actions are complete.

◆ uniqueID()

uint32_t SkPicture::uniqueID ( ) const
inline

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

Returns
identifier for SkPicture

◆ unref()

void SkRefCntBase::unref ( ) const
inlineinherited

Decrement the reference count.

If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.

Friends And Related Function Documentation

◆ SkBigPicture

friend class SkBigPicture
friend

◆ SkEmptyPicture

friend class SkEmptyPicture
friend

◆ SkPicture_StreamIsSKP

bool SkPicture_StreamIsSKP ( SkStream ,
struct SkPictInfo *   
)
friend

◆ SkPictureData

friend class SkPictureData
friend

◆ SkPicturePriv

friend class SkPicturePriv
friend

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