Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkDrawable Class Referenceabstract

#include <SkDrawable.h>

Inheritance diagram for SkDrawable:
SkFlattenable SkRefCnt SkRefCntBase CompoundDrawable DrawAtlasDrawable IntDrawable ModeDrawable MyDrawable PaintDrawable RootDrawable SkAnimatedImage SkPictureBackedGlyphDrawable SkRecordedDrawable

Classes

class  GpuDrawHandler
 

Public Member Functions

void draw (SkCanvas *, const SkMatrix *=nullptr)
 
void draw (SkCanvas *, SkScalar x, SkScalar y)
 
std::unique_ptr< GpuDrawHandlersnapGpuDrawHandler (GrBackendApi backendApi, const SkMatrix &matrix, const SkIRect &clipBounds, const SkImageInfo &bufferInfo)
 
sk_sp< SkPicturemakePictureSnapshot ()
 
uint32_t getGenerationID ()
 
SkRect getBounds ()
 
size_t approximateBytesUsed ()
 
void notifyDrawingChanged ()
 
SkFlattenable::Type getFlattenableType () const override
 
Factory getFactory () const override
 
const char * getTypeName () const override
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual void flatten (SkWriteBuffer &) const
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static SkFlattenable::Type GetFlattenableType ()
 
static sk_sp< SkDrawableDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static void Register (const char name[], Factory)
 
static sk_sp< SkFlattenableDeserialize (Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
 

Protected Member Functions

 SkDrawable ()
 
virtual SkRect onGetBounds ()=0
 
virtual size_t onApproximateBytesUsed ()
 
virtual void onDraw (SkCanvas *)=0
 
virtual std::unique_ptr< GpuDrawHandleronSnapGpuDrawHandler (GrBackendApi, const SkMatrix &, const SkIRect &, const SkImageInfo &)
 
virtual std::unique_ptr< GpuDrawHandleronSnapGpuDrawHandler (GrBackendApi, const SkMatrix &)
 
virtual sk_sp< SkPictureonMakePictureSnapshot ()
 

Additional Inherited Members

- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type , kSkBlender_Type , kSkDrawable_Type , kSkDrawLooper_Type ,
  kSkImageFilter_Type , kSkMaskFilter_Type , kSkPathEffect_Type , kSkShader_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 

Detailed Description

Base-class for objects that draw into SkCanvas.

The object has a generation ID, which is guaranteed to be unique across all drawables. To allow for clients of the drawable that may want to cache the results, the drawable must change its generation ID whenever its internal state changes such that it will draw differently.

Definition at line 37 of file SkDrawable.h.

Constructor & Destructor Documentation

◆ SkDrawable()

SkDrawable::SkDrawable ( )
protected

Definition at line 32 of file SkDrawable.cpp.

32: fGenerationID(0) {}

Member Function Documentation

◆ approximateBytesUsed()

size_t SkDrawable::approximateBytesUsed ( )

Return approximately how many bytes would be freed if this drawable is destroyed. The base implementation returns 0 to indicate that this is unknown.

Definition at line 75 of file SkDrawable.cpp.

75 {
76 return this->onApproximateBytesUsed();
77}
virtual size_t onApproximateBytesUsed()

◆ Deserialize()

static sk_sp< SkDrawable > SkDrawable::Deserialize ( const void *  data,
size_t  size,
const SkDeserialProcs procs = nullptr 
)
inlinestatic

Definition at line 138 of file SkDrawable.h.

139 {
140 return sk_sp<SkDrawable>(static_cast<SkDrawable*>(
142 kSkDrawable_Type, data, size, procs).release()));
143 }
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)

◆ draw() [1/2]

void SkDrawable::draw ( SkCanvas canvas,
const SkMatrix matrix = nullptr 
)

Draws into the specified content. The drawing sequence will be balanced upon return (i.e. the saveLevel() on the canvas will match what it was when draw() was called, and the current matrix and clip settings will not be changed.

Definition at line 43 of file SkDrawable.cpp.

43 {
44 SkAutoCanvasRestore acr(canvas, true);
45 if (matrix) {
46 canvas->concat(*matrix);
47 }
48 this->onDraw(canvas);
49
50 if ((false)) {
51 draw_bbox(canvas, this->getBounds());
52 }
53}
static void draw_bbox(SkCanvas *canvas, const SkRect &r)
void concat(const SkMatrix &matrix)
SkRect getBounds()
virtual void onDraw(SkCanvas *)=0

◆ draw() [2/2]

void SkDrawable::draw ( SkCanvas canvas,
SkScalar  x,
SkScalar  y 
)

Definition at line 55 of file SkDrawable.cpp.

55 {
57 this->draw(canvas, &matrix);
58}
void draw(SkCanvas *, const SkMatrix *=nullptr)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ getBounds()

SkRect SkDrawable::getBounds ( )

Return the (conservative) bounds of what the drawable will draw. If the drawable can change what it draws (e.g. animation or in response to some external change), then this must return a bounds that is always valid for all possible states.

Definition at line 71 of file SkDrawable.cpp.

71 {
72 return this->onGetBounds();
73}
virtual SkRect onGetBounds()=0

◆ getFactory()

Factory SkDrawable::getFactory ( ) const
inlineoverridevirtual

Implement this to return a factory function pointer that can be called to recreate your class given a buffer (previously written to by your override of flatten().

Implements SkFlattenable.

Definition at line 145 of file SkDrawable.h.

145{ return nullptr; }

◆ GetFlattenableType()

static SkFlattenable::Type SkDrawable::GetFlattenableType ( )
inlinestatic

Definition at line 130 of file SkDrawable.h.

130 {
131 return kSkDrawable_Type;
132 }

◆ getFlattenableType()

SkFlattenable::Type SkDrawable::getFlattenableType ( ) const
inlineoverridevirtual

Implements SkFlattenable.

Definition at line 134 of file SkDrawable.h.

134 {
135 return kSkDrawable_Type;
136 }

◆ getGenerationID()

uint32_t SkDrawable::getGenerationID ( )

Return a unique value for this instance. If two calls to this return the same value, it is presumed that calling the draw() method will render the same thing as well.

Subclasses that change their state should call notifyDrawingChanged() to ensure that a new value will be returned the next time it is called.

Definition at line 64 of file SkDrawable.cpp.

64 {
65 if (0 == fGenerationID) {
66 fGenerationID = next_generation_id();
67 }
68 return fGenerationID;
69}
static int32_t next_generation_id()

◆ getTypeName()

const char * SkDrawable::getTypeName ( ) const
inlineoverridevirtual

Returns the name of the object's class.

Implements SkFlattenable.

Definition at line 146 of file SkDrawable.h.

146{ return nullptr; }

◆ makePictureSnapshot()

sk_sp< SkPicture > SkDrawable::makePictureSnapshot ( )

Returns an SkPicture with the contents of this SkDrawable.

Definition at line 60 of file SkDrawable.cpp.

60 {
61 return this->onMakePictureSnapshot();
62}
virtual sk_sp< SkPicture > onMakePictureSnapshot()

◆ notifyDrawingChanged()

void SkDrawable::notifyDrawingChanged ( )

Calling this invalidates the previous generation ID, and causes a new one to be computed the next time getGenerationID() is called. Typically this is called by the object itself, in response to its internal state changing.

Definition at line 82 of file SkDrawable.cpp.

82 {
83 fGenerationID = 0;
84}

◆ onApproximateBytesUsed()

size_t SkDrawable::onApproximateBytesUsed ( )
protectedvirtual

Reimplemented in SkPictureBackedGlyphDrawable, and SkRecordedDrawable.

Definition at line 78 of file SkDrawable.cpp.

78 {
79 return 0;
80}

◆ onDraw()

virtual void SkDrawable::onDraw ( SkCanvas )
protectedpure virtual

◆ onGetBounds()

virtual SkRect SkDrawable::onGetBounds ( )
protectedpure virtual

◆ onMakePictureSnapshot()

sk_sp< SkPicture > SkDrawable::onMakePictureSnapshot ( )
protectedvirtual

Default implementation calls onDraw() with a canvas that records into a picture. Subclasses may override if they have a more efficient way to return a picture for the current state of their drawable. Note: this picture must draw the same as what would be drawn from onDraw().

Reimplemented in SkRecordedDrawable.

Definition at line 88 of file SkDrawable.cpp.

88 {
89 SkPictureRecorder recorder;
90
91 const SkRect bounds = this->getBounds();
92 SkCanvas* canvas = recorder.beginRecording(bounds);
93 this->draw(canvas);
94 if ((false)) {
95 draw_bbox(canvas, bounds);
96 }
97 return recorder.finishRecordingAsPicture();
98}
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
Optional< SkRect > bounds
Definition SkRecords.h:189

◆ onSnapGpuDrawHandler() [1/2]

virtual std::unique_ptr< GpuDrawHandler > SkDrawable::onSnapGpuDrawHandler ( GrBackendApi  ,
const SkMatrix  
)
inlineprotectedvirtual

Definition at line 162 of file SkDrawable.h.

162 {
163 return nullptr;
164 }

◆ onSnapGpuDrawHandler() [2/2]

virtual std::unique_ptr< GpuDrawHandler > SkDrawable::onSnapGpuDrawHandler ( GrBackendApi  ,
const SkMatrix ,
const SkIRect ,
const SkImageInfo  
)
inlineprotectedvirtual

Definition at line 155 of file SkDrawable.h.

157 {
158 return nullptr;
159 }

◆ snapGpuDrawHandler()

std::unique_ptr< GpuDrawHandler > SkDrawable::snapGpuDrawHandler ( GrBackendApi  backendApi,
const SkMatrix matrix,
const SkIRect clipBounds,
const SkImageInfo bufferInfo 
)
inline

Snaps off a GpuDrawHandler to represent the state of the SkDrawable at the time the snap is called. This is used for executing GPU backend specific draws intermixed with normal Skia GPU draws. The GPU API, which will be used for the draw, as well as the full matrix, device clip bounds and imageInfo of the target buffer are passed in as inputs.

Definition at line 89 of file SkDrawable.h.

92 {
93 return this->onSnapGpuDrawHandler(backendApi, matrix, clipBounds, bufferInfo);
94 }
virtual std::unique_ptr< GpuDrawHandler > onSnapGpuDrawHandler(GrBackendApi, const SkMatrix &, const SkIRect &, const SkImageInfo &)
Definition SkDrawable.h:155

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