Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkDrawable Class Referenceabstract

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

#include <SkDrawable.h>

Inheritance diagram for SkDrawable:
SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

void draw (SkCanvas *, const SkMatrix *=NULL)
 Draws into the specified content. More...
 
void draw (SkCanvas *, SkScalar x, SkScalar y)
 
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...
 
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().
 
- Public Member Functions inherited from SkFlattenable
virtual const char * getTypeName () const
 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()).
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 Default construct, initializing the reference count to 1.
 
virtual ~SkRefCntBase ()
 Destruct, asserting that the reference count is 1.
 
int32_t getRefCnt () const
 Return the reference count. More...
 
void validate () 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...
 

Protected Member Functions

virtual SkRect onGetBounds ()=0
 
virtual void onDraw (SkCanvas *)=0
 
virtual SkPictureonNewPictureSnapshot ()
 Default implementation calls onDraw() with a canvas that records into a picture. More...
 
- Protected Member Functions inherited from SkRefCntBase
void internal_dispose_restore_refcnt_to_1 () const
 Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More...
 

Private Attributes

int32_t fGenerationID
 

Additional Inherited Members

- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type, kSkDrawable_Type, kSkDrawLooper_Type, kSkImageFilter_Type,
  kSkMaskFilter_Type, kSkPathEffect_Type, kSkPixelRef_Type, kSkRasterizer_Type,
  kSkShaderBase_Type, kSkUnused_Type, kSkUnused_Xfermode_Type, kSkNormalSource_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory )(SkReadBuffer &)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static bool NameToType (const char name[], Type *type)
 
static void Register (const char name[], Factory, Type)
 

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 Function Documentation

void SkDrawable::draw ( SkCanvas ,
const SkMatrix = NULL 
)

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.

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.

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.

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.

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().


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