SkPicture Reference
===
# Picture
# Class SkPicture
## Constructor
SkPicture can be constructed or initialized by these functions, including C++ class constructors.
An SkPicture records drawing commands made to a canvas to be played back at a later time.
This base class handles serialization and a few other miscellany.
## Overview
## Class
SkPicture uses C++ classes to declare the public data structures and interfaces.
## Member Function
SkPicture member functions read and modify the structure properties.
# Class SkPicture::AbortCallback
## Constructor
SkPicture can be constructed or initialized by these functions, including C++ class constructors.
## Member_Function
SkPicture member functions read and modify the structure properties.
class AbortCallback {
public:
AbortCallback() {}
virtual
Subclasses of this can be passed to playback. During the playback
of the picture, this callback will periodically be invoked. If its
abort returns true, then picture playback will be interrupted.
The resulting drawing is undefined, as there is no guarantee how often the
callback will be invoked. If the abort happens inside some level of nested
calls to save(), restore will automatically be called to return the state
to the same level it was before the playback call was made.
## AbortCallback
AbortCallback()
Has no effect.
### Return Value
abstract class cannot be instantiated
### See Also
playback
---
## ~AbortCallback
virtual
Has no effect.
### See Also
playback
---
## abort
virtual bool abort() = 0
Stops Picture playback when some condition is met. A subclass of
AbortCallback provides an override for abort that can stop playback from
drawing the entire picture.
### Return Value
true to stop playback
### See Also
playback
---
### Example
JustOneDraw allows the black rectangle to draw but stops playback before the
white rectangle appears.
## MakeFromStream
static sk sp<SkPicture> MakeFromStream(SkStream* stream, const SkDeserialProcs* procs = nullptr)
Recreates a picture that was serialized into a stream.
### Parameters
stream |
container for serial data |
procs |
custom serial data decoders; may be nullptr |
### Return Value
Picture constructed from stream data
### Example
### See Also
MakeFromData[2] SkPictureRecorder
---
## MakeFromData
static sk sp<SkPicture> MakeFromData(const SkData* data, const SkDeserialProcs* procs = nullptr)
Recreates a picture that was serialized into data.
### Parameters
### Return Value
Picture constructed from data
### Example
### See Also
MakeFromStream SkPictureRecorder
---
static sk sp<SkPicture> MakeFromData(const void* data, size_t size,
const SkDeserialProcs* procs = nullptr)
### Parameters
### Return Value
Picture constructed from data
### Example
### See Also
MakeFromStream SkPictureRecorder
---
## playback
virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0
Replays the drawing commands on the specified canvas. Note that
this has the effect of unfurling this picture into the destination
canvas. Using the SkCanvas::drawPicture entry point gives the destination
canvas the option of just taking a ref.
### Parameters
canvas |
receiver of drawing commands |
callback |
allows interruption of playback |
### Example
### See Also
SkCanvas::drawPicture[2][3][4]
---
## cullRect
virtual SkRect cullRect() const = 0
Returns cull Rect for this picture.
Ops recorded into this picture that attempt to draw outside the cull might not be drawn.
### Return Value
bounds passed when Picture was created
### Example
Picture recorded bounds are smaller than contents; contents outside recorded
bounds may be drawn, and are drawn in this example.
### See Also
SkCanvas::clipRect[2][3]
---
## uniqueID
uint32_t uniqueID() const
Returns a non-zero value unique among all pictures.
### Return Value
identifier for Picture
### Example
#### Example Output
~~~~
empty picture id = 1
placeholder id = 2
~~~~
### See Also
SkRefCnt
---
## serialize
sk sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const
Returns storage containing data describing Picture, using optional custom encoders.
### Parameters
procs |
custom serial data encoders; may be nullptr |
### Return Value
storage containing serialized Picture
### Example
### See Also
MakeFromData[2] SkData SkSerialProcs
---
void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const
Writes picture to stream, using optional custom encoders.
### Parameters
### Example
### See Also
MakeFromStream SkWStream SkSerialProcs
---
## MakePlaceholder
static sk sp<SkPicture> MakePlaceholder(SkRect cull)
Returns a placeholder SkPicture.
This placeholder does not draw anything itself. It has a distinct uniqueID
(just like all Pictures) and will always be visible to SkSerialProcs.
### Parameters
cull |
placeholder dimensions |
### Return Value
placeholder with unique identifier
### Example
#### Example Output
~~~~
id:1 bounds:{10, 40, 80, 110}
id:2 bounds:{10, 40, 80, 110}
~~~~
### See Also
MakeFromStream MakeFromData[2]
---
## approximateOpCount
virtual int approximateOpCount() const = 0
Returns the approximate number of operations in this picture. This
number may be greater or less than the number of SkCanvas calls
recorded: some calls may be recorded as more than one operation, or some
calls may be optimized away.
### Return Value
approximate operation count
### Example
### See Also
approximateBytesUsed
---
## approximateBytesUsed
virtual size_t approximateBytesUsed() const = 0
Returns the approximate byte size of Picture. Does not include large objects
referenced Picture.
### Return Value
approximate size
### Example
### See Also
approximateOpCount
---