Skia
2D Graphics Library
SkDrawable Class Referenceabstract

Base-class for objects that draw into SkCanvas. More...

#include <SkDrawable.h>

Inheritance diagram for SkDrawable:

Classes

class  GpuDrawHandler
 When using the GPU backend it is possible for a drawable to execute using the underlying 3D API rather than the SkCanvas API. More...
 

Public Types

enum  Type {
  kSkColorFilter_Type, kSkDrawable_Type, kSkDrawLooper_Type, kSkImageFilter_Type,
  kSkMaskFilter_Type, kSkPathEffect_Type, kSkPixelRef_Type, kSkUnused_Type4,
  kSkShaderBase_Type, kSkUnused_Type, kSkUnused_Type2, kSkUnused_Type3
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 

Public Member Functions

void draw (SkCanvas *, const SkMatrix *=nullptr)
 Draws into the specified content. More...
 
void draw (SkCanvas *, SkScalar x, SkScalar y)
 
std::unique_ptr< GpuDrawHandlersnapGpuDrawHandler (GrBackendApi backendApi, const SkMatrix &matrix, const SkIRect &clipBounds, const SkImageInfo &bufferInfo)
 Snaps off a GpuDrawHandler to represent the state of the SkDrawable at the time the snap is called. More...
 
SkPicturenewPictureSnapshot ()
 
uint32_t getGenerationID ()
 Return a unique value for this instance. More...
 
SkRect getBounds ()
 Return the (conservative) bounds of what the drawable will draw. More...
 
void notifyDrawingChanged ()
 Calling this invalidates the previous generation ID, and causes a new one to be computed the next time getGenerationID() is called. More...
 
SkFlattenable::Type getFlattenableType () const override
 
Factory getFactory () const override
 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(). More...
 
const char * getTypeName () const override
 Returns the name of the object's class. More...
 
virtual void flatten (SkWriteBuffer &) const
 Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()). More...
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) 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 SkFlattenable::Type GetFlattenableType ()
 
static sk_sp< SkDrawableDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
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 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 SkPictureonNewPictureSnapshot ()
 Default implementation calls onDraw() with a canvas that records into a picture. More...
 

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.

Member Typedef Documentation

◆ Factory

typedef sk_sp<SkFlattenable>(* SkFlattenable::Factory) (SkReadBuffer &)
inherited

Member Enumeration Documentation

◆ Type

enum SkFlattenable::Type
inherited
Enumerator
kSkColorFilter_Type 
kSkDrawable_Type 
kSkDrawLooper_Type 
kSkImageFilter_Type 
kSkMaskFilter_Type 
kSkPathEffect_Type 
kSkPixelRef_Type 
kSkUnused_Type4 
kSkShaderBase_Type 
kSkUnused_Type 
kSkUnused_Type2 
kSkUnused_Type3 

Constructor & Destructor Documentation

◆ SkDrawable()

SkDrawable::SkDrawable ( )
protected

Member Function Documentation

◆ Deserialize() [1/2]

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

◆ Deserialize() [2/2]

static sk_sp<SkFlattenable> SkFlattenable::Deserialize ( Type  ,
const void *  data,
size_t  length,
const SkDeserialProcs procs = nullptr 
)
staticinherited

◆ draw() [1/2]

void SkDrawable::draw ( SkCanvas ,
const SkMatrix = 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.

◆ draw() [2/2]

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

◆ FactoryToName()

static const char* SkFlattenable::FactoryToName ( Factory  )
staticinherited

◆ flatten()

virtual void SkFlattenable::flatten ( SkWriteBuffer &  ) const
inlinevirtualinherited

Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()).

DEPRECATED public : will move to protected ... use serialize() instead

Reimplemented in SkPath2DPathEffect, SkLayerDrawLooper, SkLine2DPathEffect, SkPath1DPathEffect, SkDiscretePathEffect, Sk2DPathEffect, and SkCornerPathEffect.

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

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

◆ GetFlattenableType()

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

◆ getFlattenableType()

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

Implements SkFlattenable.

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

◆ getTypeName()

const char* SkDrawable::getTypeName ( ) const
inlineoverridevirtual

Returns the name of the object's class.

Implements SkFlattenable.

◆ NameToFactory()

static Factory SkFlattenable::NameToFactory ( const char  name[])
staticinherited

◆ newPictureSnapshot()

SkPicture* SkDrawable::newPictureSnapshot ( )

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

◆ onDraw()

virtual void SkDrawable::onDraw ( SkCanvas )
protectedpure virtual

◆ onGetBounds()

virtual SkRect SkDrawable::onGetBounds ( )
protectedpure virtual

◆ onNewPictureSnapshot()

virtual SkPicture* SkDrawable::onNewPictureSnapshot ( )
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().

◆ onSnapGpuDrawHandler() [1/2]

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

◆ onSnapGpuDrawHandler() [2/2]

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

◆ ref()

void SkRefCntBase::ref ( ) const
inlineinherited

Increment the reference count.

Must be balanced by a call to unref().

◆ Register()

static void SkFlattenable::Register ( const char  name[],
Factory   
)
staticinherited

◆ serialize() [1/2]

sk_sp<SkData> SkFlattenable::serialize ( const SkSerialProcs = nullptr) const
inherited

◆ serialize() [2/2]

size_t SkFlattenable::serialize ( void *  memory,
size_t  memory_size,
const SkSerialProcs = nullptr 
) const
inherited

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

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

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


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