*/
class SkImage : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkImage)
+
enum ColorType {
kAlpha_8_ColorType,
kRGB_565_ColorType,
// The non-root classes just register themselves with their parent
#define SK_DECLARE_INST_COUNT(className) \
SK_DECLARE_INST_COUNT_INTERNAL(className, \
- INHERITED::AddInstChild(CheckInstanceCount);)
+ INHERITED::AddInstChild(CheckInstanceCount);,\
+ /**/)
+
+#define SK_DECLARE_INST_COUNT_TEMPLATE(className) \
+ SK_DECLARE_INST_COUNT_INTERNAL(className, \
+ INHERITED::AddInstChild(CheckInstanceCount);, \
+ typename)
// The root classes registers a function to print out the memory stats when
// the app ends
#define SK_DECLARE_INST_COUNT_ROOT(className) \
- SK_DECLARE_INST_COUNT_INTERNAL(className, atexit(exitPrint);)
+ SK_DECLARE_INST_COUNT_INTERNAL(className, atexit(exitPrint);, /**/)
-#define SK_DECLARE_INST_COUNT_INTERNAL(className, initStep) \
+#define SK_DECLARE_INST_COUNT_INTERNAL(className, initStep, templateType) \
class SkInstanceCountHelper { \
public: \
typedef int (*PFCheckInstCnt)(int level, bool cleanUp); \
return SkInstanceCountHelper::gInstanceCount; \
} \
\
- static void AddInstChild(SkInstanceCountHelper::PFCheckInstCnt \
+ static void AddInstChild(templateType SkInstanceCountHelper::PFCheckInstCnt \
childCheckInstCnt) { \
if (CheckInstanceCount != childCheckInstCnt && \
NULL != SkInstanceCountHelper::gChildren) { \
#else
#define SK_DECLARE_INST_COUNT(className)
+#define SK_DECLARE_INST_COUNT_TEMPLATE(className)
#define SK_DECLARE_INST_COUNT_ROOT(className)
#define SK_DEFINE_INST_COUNT(className)
#endif
*/
class SkSurface : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkSurface)
+
/**
* Create a new surface, using the specified pixels/rowbytes as its
* backend.
class SkBoundary : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkBoundary)
+
// These must be 0, 1, 2, 3 for efficiency in the subclass implementations
enum Edge {
kTop = 0,
};
// Edge index goes clockwise around the boundary, beginning at the "top"
virtual SkPoint eval(Edge, SkScalar unitInterval) = 0;
+
+private:
+ typedef SkRefCnt INHERITED;
};
class SkBoundaryPatch {
class SkLayer : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkLayer)
+
SkLayer();
SkLayer(const SkLayer&);
virtual ~SkLayer();
*/
class SkEventSink : public SkRefCnt {
public:
- SkEventSink();
+ SK_DECLARE_INST_COUNT(SkEventSink)
+
+ SkEventSink();
virtual ~SkEventSink();
/**
// for our private link-list
SkEventSink* fNextSink;
+
+ typedef SkRefCnt INHERITED;
};
#endif
*/
class Artist : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(Artist)
+
void draw(SkView*, SkCanvas*);
void inflate(const SkDOM&, const SkDOM::Node*);
protected:
virtual void onDraw(SkView*, SkCanvas*) = 0;
virtual void onInflate(const SkDOM&, const SkDOM::Node*);
+ private:
+ typedef SkRefCnt INHERITED;
};
/** Return the artist attached to this view (or null). The artist's reference
count is not affected.
*/
class Layout : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(Layout)
+
void layoutChildren(SkView* parent);
void inflate(const SkDOM&, const SkDOM::Node*);
protected:
virtual void onLayoutChildren(SkView* parent) = 0;
virtual void onInflate(const SkDOM&, const SkDOM::Node*);
+ private:
+ typedef SkRefCnt INHERITED;
};
/** Return the layout attached to this view (or null). The layout's reference
class SkListSource : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkListSource)
+
virtual int countFields();
virtual void getFieldName(int index, SkString* field);
/** Return the index of the named field, or -1 if not found */
virtual bool prepareWidgetEvent(SkEvent*, int rowIndex);
static SkListSource* Factory(const char name[]);
+private:
+ typedef SkRefCnt INHERITED;
};
#endif
#include "SkGPipe.h"
#include "SamplePipeControllers.h"
+SK_DEFINE_INST_COUNT(SampleWindow::DeviceManager)
+
extern SampleView* CreateSamplePictFileView(const char filename[]);
class PictFileFactory : public SkViewFactory {
*/
class DeviceManager : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(DeviceManager)
+
virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0;
virtual void tearDownBackend(SampleWindow* win) = 0;
// return the GrRenderTarget backing gpu devices (NULL if not built with GPU support)
virtual GrRenderTarget* getGrRenderTarget() = 0;
+ private:
+ typedef SkRefCnt INHERITED;
};
SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
#include "SkFlattenableBuffers.h"
#include "SkTSearch.h"
+SK_DEFINE_INST_COUNT(SkBitmapHeapReader)
+SK_DEFINE_INST_COUNT(SkBitmapHeap::ExternalStorage)
+
SkBitmapHeapEntry::SkBitmapHeapEntry()
: fSlot(-1)
, fRefCount(0)
class SkBitmapHeapReader : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkBitmapHeapReader)
+
SkBitmapHeapReader() : INHERITED() {}
virtual SkBitmap* getBitmap(int32_t slot) const = 0;
virtual void releaseRef(int32_t slot) = 0;
public:
class ExternalStorage : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(ExternalStorage)
+
virtual bool insert(const SkBitmap& bitmap, int32_t slot) = 0;
+
+ private:
+ typedef SkRefCnt INHERITED;
};
static const int32_t UNLIMITED_SIZE = -1;
*/
template <int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS> class SkTMaskGamma : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT_TEMPLATE(SkTMaskGamma)
+
/**
* Creates tables to convert linear alpha values to gamma correcting alpha
* values.
: (R_LUM_BITS > G_LUM_BITS ? R_LUM_BITS : G_LUM_BITS)
};
uint8_t fGammaTables[1 << kLuminanceBits_Max][256];
+
+ typedef SkRefCnt INHERITED;
};
/**
#include "SkTypeface.h"
#include "SkXfermode.h"
+SK_DEFINE_INST_COUNT(SkFlatController)
+
///////////////////////////////////////////////////////////////////////////////
SkTypefacePlayback::SkTypefacePlayback() : fCount(0), fArray(NULL) {}
class SkFlatController : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkFlatController)
+
SkFlatController();
virtual ~SkFlatController();
/**
SkTypefacePlayback* fTypefacePlayback;
SkNamedFactorySet* fFactorySet;
uint32_t fWriteBufferFlags;
+
+ typedef SkRefCnt INHERITED;
};
class SkFlatData {
#include "SkTSearch.h"
SK_DEFINE_INST_COUNT(SkPtrSet)
+SK_DEFINE_INST_COUNT(SkNamedFactorySet)
void SkPtrSet::reset() {
Pair* p = fList.begin();
*/
class SkNamedFactorySet : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkNamedFactorySet)
+
SkNamedFactorySet();
/**
int fNextAddedFactory;
SkFactorySet fFactorySet;
SkTDArray<const char*> fNames;
+
+ typedef SkRefCnt INHERITED;
};
#endif
#include "SkStroke.h"
#include "SkThread.h"
+SK_DEFINE_INST_COUNT(SkMaskGamma)
+
#define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3)
void SkGlyph::toMask(SkMask* mask) const {
}
}
- if (SkMask::kARGB32_Format != glyph->fMaskFormat) {
- glyph->fMaskFormat = fRec.fMaskFormat;
- }
+ if (SkMask::kARGB32_Format != glyph->fMaskFormat) {
+ glyph->fMaskFormat = fRec.fMaskFormat;
+ }
if (fMaskFilter) {
SkMask src, dst;
extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc);
SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) {
- SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc);
- if (NULL == c) {
- c = SkFontHost::CreateScalerContext(desc);
- }
+ SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc);
+ if (NULL == c) {
+ c = SkFontHost::CreateScalerContext(desc);
+ }
if (NULL == c) {
c = SkNEW_ARGS(SkScalerContext_Empty, (desc));
}
#include "SkBitmap.h"
#include "SkCanvas.h"
+SK_DEFINE_INST_COUNT(SkImage)
+
static SkImage_Base* asIB(SkImage* image) {
return static_cast<SkImage_Base*>(image);
}
#include "SkImagePriv.h"
#include "SkCanvas.h"
+SK_DEFINE_INST_COUNT(SkSurface)
+
///////////////////////////////////////////////////////////////////////////////
SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) {
*/
#include "SkBoundaryPatch.h"
+SK_DEFINE_INST_COUNT(SkBoundary)
+
SkBoundaryPatch::SkBoundaryPatch() : fBoundary(NULL) {}
SkBoundaryPatch::~SkBoundaryPatch() {
static int gLayerAllocCount;
#endif
+SK_DEFINE_INST_COUNT(SkLayer)
+
///////////////////////////////////////////////////////////////////////////////
SkLayer::SkLayer() {
#include "SkThread.h"
#include "SkTime.h"
+SK_DEFINE_INST_COUNT(SkEventSink)
+
class SkEventSink_Globals {
public:
SkEventSink_Globals() {
#include "SkView.h"
#include "SkCanvas.h"
+SK_DEFINE_INST_COUNT(SkView::Artist)
+SK_DEFINE_INST_COUNT(SkView::Layout)
+
////////////////////////////////////////////////////////////////////////
SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags))
{
- fWidth = fHeight = 0;
- fLoc.set(0, 0);
- fParent = fFirstChild = fNextSibling = fPrevSibling = NULL;
+ fWidth = fHeight = 0;
+ fLoc.set(0, 0);
+ fParent = fFirstChild = fNextSibling = fPrevSibling = NULL;
fMatrix.setIdentity();
- fContainsFocus = 0;
+ fContainsFocus = 0;
}
SkView::~SkView()
{
- this->detachAllChildren();
+ this->detachAllChildren();
}
void SkView::setFlags(uint32_t flags)
{
- SkASSERT((flags & ~kAllFlagMasks) == 0);
+ SkASSERT((flags & ~kAllFlagMasks) == 0);
- uint32_t diff = fFlags ^ flags;
+ uint32_t diff = fFlags ^ flags;
- if (diff & kVisible_Mask)
- this->inval(NULL);
+ if (diff & kVisible_Mask)
+ this->inval(NULL);
- fFlags = SkToU8(flags);
+ fFlags = SkToU8(flags);
- if (diff & kVisible_Mask)
- {
- this->inval(NULL);
- }
+ if (diff & kVisible_Mask)
+ {
+ this->inval(NULL);
+ }
}
void SkView::setVisibleP(bool pred)
{
- this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift));
+ this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift));
}
void SkView::setEnabledP(bool pred)
{
- this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift));
+ this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift));
}
void SkView::setFocusableP(bool pred)
{
- this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift));
+ this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift));
}
void SkView::setClipToBounds(bool pred) {
void SkView::setSize(SkScalar width, SkScalar height)
{
- width = SkMaxScalar(0, width);
- height = SkMaxScalar(0, height);
+ width = SkMaxScalar(0, width);
+ height = SkMaxScalar(0, height);
- if (fWidth != width || fHeight != height)
- {
- this->inval(NULL);
- fWidth = width;
- fHeight = height;
- this->inval(NULL);
- this->onSizeChange();
- this->invokeLayout();
- }
+ if (fWidth != width || fHeight != height)
+ {
+ this->inval(NULL);
+ fWidth = width;
+ fHeight = height;
+ this->inval(NULL);
+ this->onSizeChange();
+ this->invokeLayout();
+ }
}
void SkView::setLoc(SkScalar x, SkScalar y)
{
- if (fLoc.fX != x || fLoc.fY != y)
- {
- this->inval(NULL);
- fLoc.set(x, y);
+ if (fLoc.fX != x || fLoc.fY != y)
+ {
+ this->inval(NULL);
+ fLoc.set(x, y);
this->inval(NULL);
- }
+ }
}
void SkView::offset(SkScalar dx, SkScalar dy)
{
- if (dx || dy)
- this->setLoc(fLoc.fX + dx, fLoc.fY + dy);
+ if (dx || dy)
+ this->setLoc(fLoc.fX + dx, fLoc.fY + dy);
}
void SkView::setLocalMatrix(const SkMatrix& matrix)
void SkView::draw(SkCanvas* canvas)
{
- if (fWidth && fHeight && this->isVisible())
- {
- SkRect r;
- r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight);
- if (this->isClipToBounds() &&
+ if (fWidth && fHeight && this->isVisible())
+ {
+ SkRect r;
+ r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight);
+ if (this->isClipToBounds() &&
canvas->quickReject(r, SkCanvas::kBW_EdgeType)) {
return;
}
- SkAutoCanvasRestore as(canvas, true);
+ SkAutoCanvasRestore as(canvas, true);
if (this->isClipToBounds()) {
canvas->clipRect(r);
}
int sc = canvas->save();
- this->onDraw(canvas);
+ this->onDraw(canvas);
canvas->restoreToCount(sc);
if (fParent) {
fParent->afterChild(this, canvas);
}
- B2FIter iter(this);
- SkView* child;
+ B2FIter iter(this);
+ SkView* child;
SkCanvas* childCanvas = this->beforeChildren(canvas);
- while ((child = iter.next()) != NULL)
- child->draw(childCanvas);
+ while ((child = iter.next()) != NULL)
+ child->draw(childCanvas);
this->afterChildren(canvas);
- }
+ }
}
void SkView::inval(SkRect* rect) {
- SkView* view = this;
+ SkView* view = this;
SkRect storage;
- for (;;) {
+ for (;;) {
if (!view->isVisible()) {
return;
}
return;
}
- SkView* parent = view->fParent;
+ SkView* parent = view->fParent;
if (parent == NULL) {
return;
}
rect->offset(view->fLoc.fX, view->fLoc.fY);
}
view = parent;
- }
+ }
}
////////////////////////////////////////////////////////////////////////////
bool SkView::setFocusView(SkView* fv)
{
- SkView* view = this;
-
- do {
- if (view->onSetFocusView(fv))
- return true;
- } while ((view = view->fParent) != NULL);
- return false;
+ SkView* view = this;
+
+ do {
+ if (view->onSetFocusView(fv))
+ return true;
+ } while ((view = view->fParent) != NULL);
+ return false;
}
SkView* SkView::getFocusView() const
{
- SkView* focus = NULL;
- const SkView* view = this;
- do {
- if (view->onGetFocusView(&focus))
- break;
- } while ((view = view->fParent) != NULL);
- return focus;
+ SkView* focus = NULL;
+ const SkView* view = this;
+ do {
+ if (view->onGetFocusView(&focus))
+ break;
+ } while ((view = view->fParent) != NULL);
+ return focus;
}
bool SkView::hasFocus() const
{
- return this == this->getFocusView();
+ return this == this->getFocusView();
}
bool SkView::acceptFocus()
{
- return this->isFocusable() && this->setFocusView(this);
+ return this->isFocusable() && this->setFocusView(this);
}
/*
- Try to give focus to this view, or its children
+ Try to give focus to this view, or its children
*/
SkView* SkView::acceptFocus(FocusDirection dir)
{
- if (dir == kNext_FocusDirection)
- {
- if (this->acceptFocus())
- return this;
+ if (dir == kNext_FocusDirection)
+ {
+ if (this->acceptFocus())
+ return this;
- B2FIter iter(this);
- SkView* child, *focus;
- while ((child = iter.next()) != NULL)
- if ((focus = child->acceptFocus(dir)) != NULL)
- return focus;
- }
- else // prev
- {
- F2BIter iter(this);
- SkView* child, *focus;
- while ((child = iter.next()) != NULL)
- if ((focus = child->acceptFocus(dir)) != NULL)
- return focus;
+ B2FIter iter(this);
+ SkView* child, *focus;
+ while ((child = iter.next()) != NULL)
+ if ((focus = child->acceptFocus(dir)) != NULL)
+ return focus;
+ }
+ else // prev
+ {
+ F2BIter iter(this);
+ SkView* child, *focus;
+ while ((child = iter.next()) != NULL)
+ if ((focus = child->acceptFocus(dir)) != NULL)
+ return focus;
- if (this->acceptFocus())
- return this;
- }
+ if (this->acceptFocus())
+ return this;
+ }
- return NULL;
+ return NULL;
}
SkView* SkView::moveFocus(FocusDirection dir)
{
- SkView* focus = this->getFocusView();
-
- if (focus == NULL)
- { // start with the root
- focus = this;
- while (focus->fParent)
- focus = focus->fParent;
- }
-
- SkView* child, *parent;
-
- if (dir == kNext_FocusDirection)
- {
- parent = focus;
- child = focus->fFirstChild;
- if (child)
- goto FIRST_CHILD;
- else
- goto NEXT_SIB;
-
- do {
- while (child != parent->fFirstChild)
- {
- FIRST_CHILD:
- if ((focus = child->acceptFocus(dir)) != NULL)
- return focus;
- child = child->fNextSibling;
- }
- NEXT_SIB:
- child = parent->fNextSibling;
- parent = parent->fParent;
- } while (parent != NULL);
- }
- else // prevfocus
- {
- parent = focus->fParent;
- if (parent == NULL) // we're the root
- return focus->acceptFocus(dir);
- else
- {
- child = focus;
- while (parent)
- {
- while (child != parent->fFirstChild)
- {
- child = child->fPrevSibling;
- if ((focus = child->acceptFocus(dir)) != NULL)
- return focus;
- }
- if (parent->acceptFocus())
- return parent;
-
- child = parent;
- parent = parent->fParent;
- }
- }
- }
- return NULL;
+ SkView* focus = this->getFocusView();
+
+ if (focus == NULL)
+ { // start with the root
+ focus = this;
+ while (focus->fParent)
+ focus = focus->fParent;
+ }
+
+ SkView* child, *parent;
+
+ if (dir == kNext_FocusDirection)
+ {
+ parent = focus;
+ child = focus->fFirstChild;
+ if (child)
+ goto FIRST_CHILD;
+ else
+ goto NEXT_SIB;
+
+ do {
+ while (child != parent->fFirstChild)
+ {
+ FIRST_CHILD:
+ if ((focus = child->acceptFocus(dir)) != NULL)
+ return focus;
+ child = child->fNextSibling;
+ }
+ NEXT_SIB:
+ child = parent->fNextSibling;
+ parent = parent->fParent;
+ } while (parent != NULL);
+ }
+ else // prevfocus
+ {
+ parent = focus->fParent;
+ if (parent == NULL) // we're the root
+ return focus->acceptFocus(dir);
+ else
+ {
+ child = focus;
+ while (parent)
+ {
+ while (child != parent->fFirstChild)
+ {
+ child = child->fPrevSibling;
+ if ((focus = child->acceptFocus(dir)) != NULL)
+ return focus;
+ }
+ if (parent->acceptFocus())
+ return parent;
+
+ child = parent;
+ parent = parent->fParent;
+ }
+ }
+ }
+ return NULL;
}
void SkView::onFocusChange(bool gainFocusP)
{
- this->inval(NULL);
+ this->inval(NULL);
}
////////////////////////////////////////////////////////////////////////////
SkView::Click::~Click()
{
- this->resetType();
+ this->resetType();
}
void SkView::Click::resetType()
{
- if (fWeOwnTheType)
- {
- sk_free(fType);
- fWeOwnTheType = false;
- }
- fType = NULL;
+ if (fWeOwnTheType)
+ {
+ sk_free(fType);
+ fWeOwnTheType = false;
+ }
+ fType = NULL;
}
bool SkView::Click::isType(const char type[]) const
{
- const char* t = fType;
+ const char* t = fType;
- if (type == t)
- return true;
+ if (type == t)
+ return true;
- if (type == NULL)
- type = "";
- if (t == NULL)
- t = "";
- return !strcmp(t, type);
+ if (type == NULL)
+ type = "";
+ if (t == NULL)
+ t = "";
+ return !strcmp(t, type);
}
void SkView::Click::setType(const char type[])
{
- this->resetType();
- fType = (char*)type;
+ this->resetType();
+ fType = (char*)type;
}
void SkView::Click::copyType(const char type[])
{
- if (fType != type)
- {
- this->resetType();
- if (type)
- {
- size_t len = strlen(type) + 1;
- fType = (char*)sk_malloc_throw(len);
- memcpy(fType, type, len);
- fWeOwnTheType = true;
- }
- }
+ if (fType != type)
+ {
+ this->resetType();
+ if (type)
+ {
+ size_t len = strlen(type) + 1;
+ fType = (char*)sk_malloc_throw(len);
+ memcpy(fType, type, len);
+ fWeOwnTheType = true;
+ }
+ }
}
SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y)
//////////////////////////////////////////////////////////////////////
void SkView::invokeLayout() {
- SkView::Layout* layout = this->getLayout();
+ SkView::Layout* layout = this->getLayout();
- if (layout) {
- layout->layoutChildren(this);
+ if (layout) {
+ layout->layoutChildren(this);
}
}
void SkView::onDraw(SkCanvas* canvas) {
- Artist* artist = this->getArtist();
+ Artist* artist = this->getArtist();
- if (artist) {
- artist->draw(this, canvas);
+ if (artist) {
+ artist->draw(this, canvas);
}
}
}
SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y) {
- return NULL;
+ return NULL;
}
bool SkView::onClick(Click*) {
- return false;
+ return false;
}
bool SkView::handleInval(const SkRect*) {
- return false;
+ return false;
}
//////////////////////////////////////////////////////////////////////
void SkView::getLocalBounds(SkRect* bounds) const
{
- if (bounds)
- bounds->set(0, 0, fWidth, fHeight);
+ if (bounds)
+ bounds->set(0, 0, fWidth, fHeight);
}
//////////////////////////////////////////////////////////////////////
void SkView::detachFromParent_NoLayout()
{
- if (fParent == NULL)
- return;
+ if (fParent == NULL)
+ return;
- if (fContainsFocus)
- (void)this->setFocusView(NULL);
+ if (fContainsFocus)
+ (void)this->setFocusView(NULL);
- this->inval(NULL);
+ this->inval(NULL);
- SkView* next = NULL;
+ SkView* next = NULL;
- if (fNextSibling != this) // do we have any siblings
- {
- fNextSibling->fPrevSibling = fPrevSibling;
- fPrevSibling->fNextSibling = fNextSibling;
- next = fNextSibling;
- }
+ if (fNextSibling != this) // do we have any siblings
+ {
+ fNextSibling->fPrevSibling = fPrevSibling;
+ fPrevSibling->fNextSibling = fNextSibling;
+ next = fNextSibling;
+ }
- if (fParent->fFirstChild == this)
- fParent->fFirstChild = next;
+ if (fParent->fFirstChild == this)
+ fParent->fFirstChild = next;
- fParent = fNextSibling = fPrevSibling = NULL;
+ fParent = fNextSibling = fPrevSibling = NULL;
- this->unref();
+ this->unref();
}
void SkView::detachFromParent()
{
- SkView* parent = fParent;
+ SkView* parent = fParent;
- if (parent)
- {
- this->detachFromParent_NoLayout();
- parent->invokeLayout();
- }
+ if (parent)
+ {
+ this->detachFromParent_NoLayout();
+ parent->invokeLayout();
+ }
}
SkView* SkView::attachChildToBack(SkView* child)
{
- SkASSERT(child != this);
+ SkASSERT(child != this);
- if (child == NULL || fFirstChild == child)
- goto DONE;
+ if (child == NULL || fFirstChild == child)
+ goto DONE;
- child->ref();
- child->detachFromParent_NoLayout();
+ child->ref();
+ child->detachFromParent_NoLayout();
- if (fFirstChild == NULL)
- {
- child->fNextSibling = child;
- child->fPrevSibling = child;
- }
- else
- {
- child->fNextSibling = fFirstChild;
- child->fPrevSibling = fFirstChild->fPrevSibling;
- fFirstChild->fPrevSibling->fNextSibling = child;
- fFirstChild->fPrevSibling = child;
- }
+ if (fFirstChild == NULL)
+ {
+ child->fNextSibling = child;
+ child->fPrevSibling = child;
+ }
+ else
+ {
+ child->fNextSibling = fFirstChild;
+ child->fPrevSibling = fFirstChild->fPrevSibling;
+ fFirstChild->fPrevSibling->fNextSibling = child;
+ fFirstChild->fPrevSibling = child;
+ }
- fFirstChild = child;
- child->fParent = this;
- child->inval(NULL);
+ fFirstChild = child;
+ child->fParent = this;
+ child->inval(NULL);
- this->invokeLayout();
+ this->invokeLayout();
DONE:
- return child;
+ return child;
}
SkView* SkView::attachChildToFront(SkView* child)
{
- SkASSERT(child != this);
+ SkASSERT(child != this);
- if (child == NULL || (fFirstChild && fFirstChild->fPrevSibling == child))
- goto DONE;
+ if (child == NULL || (fFirstChild && fFirstChild->fPrevSibling == child))
+ goto DONE;
- child->ref();
- child->detachFromParent_NoLayout();
+ child->ref();
+ child->detachFromParent_NoLayout();
- if (fFirstChild == NULL)
- {
- fFirstChild = child;
- child->fNextSibling = child;
- child->fPrevSibling = child;
- }
- else
- {
- child->fNextSibling = fFirstChild;
- child->fPrevSibling = fFirstChild->fPrevSibling;
- fFirstChild->fPrevSibling->fNextSibling = child;
- fFirstChild->fPrevSibling = child;
- }
+ if (fFirstChild == NULL)
+ {
+ fFirstChild = child;
+ child->fNextSibling = child;
+ child->fPrevSibling = child;
+ }
+ else
+ {
+ child->fNextSibling = fFirstChild;
+ child->fPrevSibling = fFirstChild->fPrevSibling;
+ fFirstChild->fPrevSibling->fNextSibling = child;
+ fFirstChild->fPrevSibling = child;
+ }
- child->fParent = this;
- child->inval(NULL);
+ child->fParent = this;
+ child->inval(NULL);
- this->invokeLayout();
+ this->invokeLayout();
DONE:
- return child;
+ return child;
}
void SkView::detachAllChildren()
{
- while (fFirstChild)
- fFirstChild->detachFromParent_NoLayout();
+ while (fFirstChild)
+ fFirstChild->detachFromParent_NoLayout();
}
void SkView::localToGlobal(SkMatrix* matrix) const
//////////////////////////////////////////////////////////////////
/* Even if the subclass overrides onInflate, they should always be
- sure to call the inherited method, so that we get called.
+ sure to call the inherited method, so that we get called.
*/
void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
- SkScalar x, y;
+ SkScalar x, y;
- x = this->locX();
- y = this->locY();
- (void)dom.findScalar(node, "x", &x);
- (void)dom.findScalar(node, "y", &y);
- this->setLoc(x, y);
+ x = this->locX();
+ y = this->locY();
+ (void)dom.findScalar(node, "x", &x);
+ (void)dom.findScalar(node, "y", &y);
+ this->setLoc(x, y);
- x = this->width();
- y = this->height();
- (void)dom.findScalar(node, "width", &x);
- (void)dom.findScalar(node, "height", &y);
- this->setSize(x, y);
+ x = this->width();
+ y = this->height();
+ (void)dom.findScalar(node, "width", &x);
+ (void)dom.findScalar(node, "height", &y);
+ this->setSize(x, y);
- // inflate the flags
+ // inflate the flags
- static const char* gFlagNames[] = {
- "visible", "enabled", "focusable", "flexH", "flexV"
- };
- SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount);
+ static const char* gFlagNames[] = {
+ "visible", "enabled", "focusable", "flexH", "flexV"
+ };
+ SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount);
- bool b;
- uint32_t flags = this->getFlags();
- for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++)
- if (dom.findBool(node, gFlagNames[i], &b))
- flags = SkSetClearShift(flags, b, i);
- this->setFlags(flags);
+ bool b;
+ uint32_t flags = this->getFlags();
+ for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++)
+ if (dom.findBool(node, gFlagNames[i], &b))
+ flags = SkSetClearShift(flags, b, i);
+ this->setFlags(flags);
}
void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node)
{
- this->onInflate(dom, node);
+ this->onInflate(dom, node);
}
void SkView::onPostInflate(const SkTDict<SkView*>&)
{
- // override in subclass as needed
+ // override in subclass as needed
}
void SkView::postInflate(const SkTDict<SkView*>& dict)
{
- this->onPostInflate(dict);
+ this->onPostInflate(dict);
- B2FIter iter(this);
- SkView* child;
- while ((child = iter.next()) != NULL)
- child->postInflate(dict);
+ B2FIter iter(this);
+ SkView* child;
+ while ((child = iter.next()) != NULL)
+ child->postInflate(dict);
}
//////////////////////////////////////////////////////////////////
SkView* SkView::sendEventToParents(const SkEvent& evt)
{
- SkView* parent = fParent;
+ SkView* parent = fParent;
- while (parent)
- {
- if (parent->doEvent(evt))
- return parent;
- parent = parent->fParent;
- }
- return NULL;
+ while (parent)
+ {
+ if (parent->doEvent(evt))
+ return parent;
+ parent = parent->fParent;
+ }
+ return NULL;
}
SkView* SkView::sendQueryToParents(SkEvent* evt) {
- SkView* parent = fParent;
+ SkView* parent = fParent;
- while (parent) {
- if (parent->doQuery(evt)) {
- return parent;
+ while (parent) {
+ if (parent->doQuery(evt)) {
+ return parent;
}
- parent = parent->fParent;
- }
- return NULL;
+ parent = parent->fParent;
+ }
+ return NULL;
}
//////////////////////////////////////////////////////////////////
SkView::F2BIter::F2BIter(const SkView* parent)
{
- fFirstChild = parent ? parent->fFirstChild : NULL;
- fChild = fFirstChild ? fFirstChild->fPrevSibling : NULL;
+ fFirstChild = parent ? parent->fFirstChild : NULL;
+ fChild = fFirstChild ? fFirstChild->fPrevSibling : NULL;
}
SkView* SkView::F2BIter::next()
{
- SkView* curr = fChild;
+ SkView* curr = fChild;
- if (fChild)
- {
- if (fChild == fFirstChild)
- fChild = NULL;
- else
- fChild = fChild->fPrevSibling;
- }
- return curr;
+ if (fChild)
+ {
+ if (fChild == fFirstChild)
+ fChild = NULL;
+ else
+ fChild = fChild->fPrevSibling;
+ }
+ return curr;
}
SkView::B2FIter::B2FIter(const SkView* parent)
{
- fFirstChild = parent ? parent->fFirstChild : NULL;
- fChild = fFirstChild;
+ fFirstChild = parent ? parent->fFirstChild : NULL;
+ fChild = fFirstChild;
}
SkView* SkView::B2FIter::next()
{
- SkView* curr = fChild;
+ SkView* curr = fChild;
- if (fChild)
- {
- SkView* next = fChild->fNextSibling;
- if (next == fFirstChild)
- next = NULL;
- fChild = next;
- }
- return curr;
+ if (fChild)
+ {
+ SkView* next = fChild->fNextSibling;
+ if (next == fFirstChild)
+ next = NULL;
+ fChild = next;
+ }
+ return curr;
}
//////////////////////////////////////////////////////////////////
static inline void show_if_nonzero(const char name[], SkScalar value)
{
- if (value)
- SkDebugf("%s=\"%g\"", name, value/65536.);
+ if (value)
+ SkDebugf("%s=\"%g\"", name, value/65536.);
}
static void tab(int level)
{
- for (int i = 0; i < level; i++)
- SkDebugf(" ");
+ for (int i = 0; i < level; i++)
+ SkDebugf(" ");
}
static void dumpview(const SkView* view, int level, bool recurse)
{
- tab(level);
-
- SkDebugf("<view");
- show_if_nonzero(" x", view->locX());
- show_if_nonzero(" y", view->locY());
- show_if_nonzero(" width", view->width());
- show_if_nonzero(" height", view->height());
-
- if (recurse)
- {
- SkView::B2FIter iter(view);
- SkView* child;
- bool noChildren = true;
-
- while ((child = iter.next()) != NULL)
- {
- if (noChildren)
- SkDebugf(">\n");
- noChildren = false;
- dumpview(child, level + 1, true);
- }
-
- if (!noChildren)
- {
- tab(level);
- SkDebugf("</view>\n");
- }
- else
- goto ONELINER;
- }
- else
- {
- ONELINER:
- SkDebugf(" />\n");
- }
+ tab(level);
+
+ SkDebugf("<view");
+ show_if_nonzero(" x", view->locX());
+ show_if_nonzero(" y", view->locY());
+ show_if_nonzero(" width", view->width());
+ show_if_nonzero(" height", view->height());
+
+ if (recurse)
+ {
+ SkView::B2FIter iter(view);
+ SkView* child;
+ bool noChildren = true;
+
+ while ((child = iter.next()) != NULL)
+ {
+ if (noChildren)
+ SkDebugf(">\n");
+ noChildren = false;
+ dumpview(child, level + 1, true);
+ }
+
+ if (!noChildren)
+ {
+ tab(level);
+ SkDebugf("</view>\n");
+ }
+ else
+ goto ONELINER;
+ }
+ else
+ {
+ ONELINER:
+ SkDebugf(" />\n");
+ }
}
void SkView::dump(bool recurse) const
{
- dumpview(this, 0, recurse);
+ dumpview(this, 0, recurse);
}
#endif
/*
I have moved this to SkWidgetViews.h
enum SkinEnum {
- kButton_SkinEnum,
- kProgress_SkinEnum,
- kScroll_SkinEnum,
- kStaticText_SkinEnum,
-
- kSkinEnumCount
+ kButton_SkinEnum,
+ kProgress_SkinEnum,
+ kScroll_SkinEnum,
+ kStaticText_SkinEnum,
+
+ kSkinEnumCount
};
*/
+SK_DEFINE_INST_COUNT(SkListSource)
+
const char* get_skin_enum_path(SkinEnum se)
{
- SkASSERT((unsigned)se < kSkinEnumCount);
+ SkASSERT((unsigned)se < kSkinEnumCount);
- static const char* gSkinPaths[] = {
+ static const char* gSkinPaths[] = {
"common/default/default/skins/border3.xml",
"common/default/default/skins/button.xml",
"common/default/default/skins/progressBar.xml",
"common/default/default/skins/scrollBar.xml",
"common/default/default/skins/statictextpaint.xml"
- };
+ };
- return gSkinPaths[se];
+ return gSkinPaths[se];
}
void init_skin_anim(const char path[], SkAnimator* anim)
{
- SkASSERT(path && anim);
+ SkASSERT(path && anim);
- SkFILEStream stream(path);
+ SkFILEStream stream(path);
- if (!stream.isValid())
- {
- SkDEBUGF(("init_skin_anim: loading skin failed <%s>\n", path));
- sk_throw();
- }
+ if (!stream.isValid())
+ {
+ SkDEBUGF(("init_skin_anim: loading skin failed <%s>\n", path));
+ sk_throw();
+ }
- if (!anim->decodeStream(&stream))
- {
- SkDEBUGF(("init_skin_anim: decoding skin failed <%s>\n", path));
- sk_throw();
- }
+ if (!anim->decodeStream(&stream))
+ {
+ SkDEBUGF(("init_skin_anim: decoding skin failed <%s>\n", path));
+ sk_throw();
+ }
}
void init_skin_anim(SkinEnum se, SkAnimator* anim)
{
- init_skin_anim(get_skin_enum_path(se), anim);
+ init_skin_anim(get_skin_enum_path(se), anim);
}
void init_skin_paint(SkinEnum se, SkPaint* paint)
{
- SkASSERT(paint);
+ SkASSERT(paint);
- SkAnimator anim;
- SkCanvas canvas;
-
- init_skin_anim(se, &anim);
- anim.draw(&canvas, paint, 0);
+ SkAnimator anim;
+ SkCanvas canvas;
+
+ init_skin_anim(se, &anim);
+ anim.draw(&canvas, paint, 0);
}
void inflate_paint(const SkDOM& dom, const SkDOM::Node* node, SkPaint* paint)
{
- SkASSERT(paint);
-
- SkAnimator anim;
- SkCanvas canvas;
-
- if (!anim.decodeDOM(dom, node))
- {
- SkDEBUGF(("inflate_paint: decoding dom failed\n"));
- SkDEBUGCODE(dom.dump(node);)
- sk_throw();
- }
- anim.draw(&canvas, paint, 0);
+ SkASSERT(paint);
+
+ SkAnimator anim;
+ SkCanvas canvas;
+
+ if (!anim.decodeDOM(dom, node))
+ {
+ SkDEBUGF(("inflate_paint: decoding dom failed\n"));
+ SkDEBUGCODE(dom.dump(node);)
+ sk_throw();
+ }
+ anim.draw(&canvas, paint, 0);
}
////////////////////////////////////////////////////////////////////////////////////////
const char* SkWidgetView::getLabel() const
{
- return fLabel.c_str();
+ return fLabel.c_str();
}
-
+
void SkWidgetView::getLabel(SkString* label) const
{
- if (label)
- *label = fLabel;
+ if (label)
+ *label = fLabel;
}
void SkWidgetView::setLabel(const char label[])
{
- this->setLabel(label, label ? strlen(label) : 0);
+ this->setLabel(label, label ? strlen(label) : 0);
}
void SkWidgetView::setLabel(const char label[], size_t len)
{
- if ((label == NULL && fLabel.size() != 0) || !fLabel.equals(label, len))
- {
- SkString tmp(label, len);
+ if ((label == NULL && fLabel.size() != 0) || !fLabel.equals(label, len))
+ {
+ SkString tmp(label, len);
- this->onLabelChange(fLabel.c_str(), tmp.c_str());
- fLabel.swap(tmp);
- }
+ this->onLabelChange(fLabel.c_str(), tmp.c_str());
+ fLabel.swap(tmp);
+ }
}
void SkWidgetView::setLabel(const SkString& label)
{
- if (fLabel != label)
- {
- this->onLabelChange(fLabel.c_str(), label.c_str());
- fLabel = label;
- }
+ if (fLabel != label)
+ {
+ this->onLabelChange(fLabel.c_str(), label.c_str());
+ fLabel = label;
+ }
}
bool SkWidgetView::postWidgetEvent()
{
- if (!fEvent.isType(""))
- {
- SkEvent evt(fEvent); // make a copy since onPrepareWidgetEvent may edit the event
-
- if (this->onPrepareWidgetEvent(&evt))
- {
- SkDEBUGCODE(evt.dump("SkWidgetView::postWidgetEvent");)
-
- this->postToListeners(evt); // wonder if this should return true if there are > 0 listeners...
- return true;
- }
- }
- return false;
+ if (!fEvent.isType(""))
+ {
+ SkEvent evt(fEvent); // make a copy since onPrepareWidgetEvent may edit the event
+
+ if (this->onPrepareWidgetEvent(&evt))
+ {
+ SkDEBUGCODE(evt.dump("SkWidgetView::postWidgetEvent");)
+
+ this->postToListeners(evt); // wonder if this should return true if there are > 0 listeners...
+ return true;
+ }
+ }
+ return false;
}
/*virtual*/ void SkWidgetView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
- this->INHERITED::onInflate(dom, node);
-
- const char* label = dom.findAttr(node, "label");
- if (label)
- this->setLabel(label);
-
- if ((node = dom.getFirstChild(node, "event")) != NULL)
- fEvent.inflate(dom, node);
+ this->INHERITED::onInflate(dom, node);
+
+ const char* label = dom.findAttr(node, "label");
+ if (label)
+ this->setLabel(label);
+
+ if ((node = dom.getFirstChild(node, "event")) != NULL)
+ fEvent.inflate(dom, node);
}
/*virtual*/ void SkWidgetView::onLabelChange(const char oldLabel[], const char newLabel[])
{
- this->inval(NULL);
+ this->inval(NULL);
}
static const char gWidgetEventSinkIDSlotName[] = "sk-widget-sinkid-slot";
/*virtual*/ bool SkWidgetView::onPrepareWidgetEvent(SkEvent* evt)
{
- evt->setS32(gWidgetEventSinkIDSlotName, this->getSinkID());
- return true;
+ evt->setS32(gWidgetEventSinkIDSlotName, this->getSinkID());
+ return true;
}
SkEventSinkID SkWidgetView::GetWidgetEventSinkID(const SkEvent& evt)
{
- int32_t sinkID;
-
- return evt.findS32(gWidgetEventSinkIDSlotName, &sinkID) ? (SkEventSinkID)sinkID : 0;
+ int32_t sinkID;
+
+ return evt.findS32(gWidgetEventSinkIDSlotName, &sinkID) ? (SkEventSinkID)sinkID : 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
/*virtual*/ bool SkButtonView::onEvent(const SkEvent& evt)
{
- if (evt.isType(SK_EventType_Key) && evt.getFast32() == kOK_SkKey)
- {
- this->postWidgetEvent();
- return true;
- }
- return this->INHERITED::onEvent(evt);
+ if (evt.isType(SK_EventType_Key) && evt.getFast32() == kOK_SkKey)
+ {
+ this->postWidgetEvent();
+ return true;
+ }
+ return this->INHERITED::onEvent(evt);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SkCheckButtonView::setCheckState(CheckState state)
{
- SkASSERT((unsigned)state <= kUnknown_CheckState);
-
- if (fCheckState != state)
- {
- this->onCheckStateChange(this->getCheckState(), state);
- fCheckState = SkToU8(state);
- }
+ SkASSERT((unsigned)state <= kUnknown_CheckState);
+
+ if (fCheckState != state)
+ {
+ this->onCheckStateChange(this->getCheckState(), state);
+ fCheckState = SkToU8(state);
+ }
}
-
+
/*virtual*/ void SkCheckButtonView::onCheckStateChange(CheckState oldState, CheckState newState)
{
- this->inval(NULL);
+ this->inval(NULL);
}
/*virtual*/ void SkCheckButtonView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
- this->INHERITED::onInflate(dom, node);
-
- int index = dom.findList(node, "check-state", "off,on,unknown");
- if (index >= 0)
- this->setCheckState((CheckState)index);
+ this->INHERITED::onInflate(dom, node);
+
+ int index = dom.findList(node, "check-state", "off,on,unknown");
+ if (index >= 0)
+ this->setCheckState((CheckState)index);
}
static const char gCheckStateSlotName[] = "sk-checkbutton-check-slot";
/*virtual*/ bool SkCheckButtonView::onPrepareWidgetEvent(SkEvent* evt)
{
- // could check if we're "disabled", and return false...
+ // could check if we're "disabled", and return false...
- evt->setS32(gCheckStateSlotName, this->getCheckState());
- return true;
+ evt->setS32(gCheckStateSlotName, this->getCheckState());
+ return true;
}
bool SkCheckButtonView::GetWidgetEventCheckState(const SkEvent& evt, CheckState* state)
{
- int32_t state32;
-
- if (evt.findS32(gCheckStateSlotName, &state32))
- {
- if (state)
- *state = (CheckState)state32;
- return true;
- }
- return false;
+ int32_t state32;
+
+ if (evt.findS32(gCheckStateSlotName, &state32))
+ {
+ if (state)
+ *state = (CheckState)state32;
+ return true;
+ }
+ return false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
class SkAnimButtonView : public SkButtonView {
public:
- SkAnimButtonView()
- {
- fAnim.setHostEventSink(this);
- init_skin_anim(kButton_SkinEnum, &fAnim);
- }
+ SkAnimButtonView()
+ {
+ fAnim.setHostEventSink(this);
+ init_skin_anim(kButton_SkinEnum, &fAnim);
+ }
protected:
- virtual void onLabelChange(const char oldLabel[], const char newLabel[])
- {
- this->INHERITED::onLabelChange(oldLabel, newLabel);
-
- SkEvent evt("user");
- evt.setString("id", "setLabel");
- evt.setString("LABEL", newLabel);
- fAnim.doUserEvent(evt);
- }
-
- virtual void onFocusChange(bool gainFocus)
- {
- this->INHERITED::onFocusChange(gainFocus);
-
- SkEvent evt("user");
- evt.setString("id", "setFocus");
- evt.setS32("FOCUS", gainFocus);
- fAnim.doUserEvent(evt);
- }
-
- virtual void onSizeChange()
- {
- this->INHERITED::onSizeChange();
-
- SkEvent evt("user");
- evt.setString("id", "setDim");
- evt.setScalar("dimX", this->width());
- evt.setScalar("dimY", this->height());
- fAnim.doUserEvent(evt);
- }
-
- virtual void onDraw(SkCanvas* canvas)
- {
- SkPaint paint;
- SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
-
- if (diff == SkAnimator::kDifferent)
- this->inval(NULL);
- else if (diff == SkAnimator::kPartiallyDifferent)
- {
- SkRect bounds;
- fAnim.getInvalBounds(&bounds);
- this->inval(&bounds);
- }
- }
-
- virtual bool onEvent(const SkEvent& evt)
- {
- if (evt.isType(SK_EventType_Inval))
- {
- this->inval(NULL);
- return true;
- }
- if (evt.isType("recommendDim"))
- {
- SkScalar height;
-
- if (evt.findScalar("y", &height))
- this->setHeight(height);
- return true;
- }
- return this->INHERITED::onEvent(evt);
- }
-
- virtual bool onPrepareWidgetEvent(SkEvent* evt)
- {
- if (this->INHERITED::onPrepareWidgetEvent(evt))
- {
- SkEvent e("user");
- e.setString("id", "handlePress");
- (void)fAnim.doUserEvent(e);
- return true;
- }
- return false;
- }
+ virtual void onLabelChange(const char oldLabel[], const char newLabel[])
+ {
+ this->INHERITED::onLabelChange(oldLabel, newLabel);
+
+ SkEvent evt("user");
+ evt.setString("id", "setLabel");
+ evt.setString("LABEL", newLabel);
+ fAnim.doUserEvent(evt);
+ }
+
+ virtual void onFocusChange(bool gainFocus)
+ {
+ this->INHERITED::onFocusChange(gainFocus);
+
+ SkEvent evt("user");
+ evt.setString("id", "setFocus");
+ evt.setS32("FOCUS", gainFocus);
+ fAnim.doUserEvent(evt);
+ }
+
+ virtual void onSizeChange()
+ {
+ this->INHERITED::onSizeChange();
+
+ SkEvent evt("user");
+ evt.setString("id", "setDim");
+ evt.setScalar("dimX", this->width());
+ evt.setScalar("dimY", this->height());
+ fAnim.doUserEvent(evt);
+ }
+
+ virtual void onDraw(SkCanvas* canvas)
+ {
+ SkPaint paint;
+ SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
+
+ if (diff == SkAnimator::kDifferent)
+ this->inval(NULL);
+ else if (diff == SkAnimator::kPartiallyDifferent)
+ {
+ SkRect bounds;
+ fAnim.getInvalBounds(&bounds);
+ this->inval(&bounds);
+ }
+ }
+
+ virtual bool onEvent(const SkEvent& evt)
+ {
+ if (evt.isType(SK_EventType_Inval))
+ {
+ this->inval(NULL);
+ return true;
+ }
+ if (evt.isType("recommendDim"))
+ {
+ SkScalar height;
+
+ if (evt.findScalar("y", &height))
+ this->setHeight(height);
+ return true;
+ }
+ return this->INHERITED::onEvent(evt);
+ }
+
+ virtual bool onPrepareWidgetEvent(SkEvent* evt)
+ {
+ if (this->INHERITED::onPrepareWidgetEvent(evt))
+ {
+ SkEvent e("user");
+ e.setString("id", "handlePress");
+ (void)fAnim.doUserEvent(e);
+ return true;
+ }
+ return false;
+ }
private:
- SkAnimator fAnim;
-
- typedef SkButtonView INHERITED;
+ SkAnimator fAnim;
+
+ typedef SkButtonView INHERITED;
};
////////////////////////////////////////////////////////////////////////////////////////////
SkView* SkWidgetFactory(const char name[])
{
- if (name == NULL)
- return NULL;
-
- // must be in the same order as the SkSkinWidgetEnum is declared
- static const char* gNames[] = {
- "sk-border",
- "sk-button",
- "sk-image",
- "sk-list",
- "sk-progress",
- "sk-scroll",
- "sk-text"
-
- };
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); i++)
- if (!strcmp(gNames[i], name))
- return SkWidgetFactory((SkWidgetEnum)i);
-
- return NULL;
+ if (name == NULL)
+ return NULL;
+
+ // must be in the same order as the SkSkinWidgetEnum is declared
+ static const char* gNames[] = {
+ "sk-border",
+ "sk-button",
+ "sk-image",
+ "sk-list",
+ "sk-progress",
+ "sk-scroll",
+ "sk-text"
+
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); i++)
+ if (!strcmp(gNames[i], name))
+ return SkWidgetFactory((SkWidgetEnum)i);
+
+ return NULL;
}
#include "SkImageView.h"
SkView* SkWidgetFactory(SkWidgetEnum sw)
{
- switch (sw) {
- case kBorder_WidgetEnum:
- return new SkBorderView;
- case kButton_WidgetEnum:
- return new SkAnimButtonView;
- case kImage_WidgetEnum:
- return new SkImageView;
- case kList_WidgetEnum:
- return new SkListView;
- case kProgress_WidgetEnum:
- return new SkProgressBarView;
- case kScroll_WidgetEnum:
- return new SkScrollBarView;
- case kText_WidgetEnum:
- return new SkStaticTextView;
- default:
- SkDEBUGFAIL("unknown enum passed to SkWidgetFactory");
- break;
- }
- return NULL;
+ switch (sw) {
+ case kBorder_WidgetEnum:
+ return new SkBorderView;
+ case kButton_WidgetEnum:
+ return new SkAnimButtonView;
+ case kImage_WidgetEnum:
+ return new SkImageView;
+ case kList_WidgetEnum:
+ return new SkListView;
+ case kProgress_WidgetEnum:
+ return new SkProgressBarView;
+ case kScroll_WidgetEnum:
+ return new SkScrollBarView;
+ case kText_WidgetEnum:
+ return new SkStaticTextView;
+ default:
+ SkDEBUGFAIL("unknown enum passed to SkWidgetFactory");
+ break;
+ }
+ return NULL;
}
SkMask ma, mb;
copyToMask(a, &ma);
copyToMask(b, &mb);
+ SkAutoMaskFreeImage aCleanUp(ma.fImage);
+ SkAutoMaskFreeImage bCleanUp(mb.fImage);
+
return ma == mb;
}
#include "SkRefDict.h"
class TestRC : public SkRefCnt {
+public:
+ SK_DECLARE_INST_COUNT(TestRC)
+private:
+ typedef SkRefCnt INHERITED;
};
+SK_DEFINE_INST_COUNT(TestRC)
+
static void TestRefDict(skiatest::Reporter* reporter) {
TestRC data0, data1;
SkRefDict dict;
class GrContext;
#endif
+SK_DEFINE_INST_COUNT(skiatest::Reporter)
+
using namespace skiatest;
Reporter::Reporter() {
class Reporter : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(Reporter)
Reporter();
enum Result {
class RefClass : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(RefClass)
+
RefClass(int n) : fN(n) {}
int get() const { return fN; }
private:
int fN;
+
+ typedef SkRefCnt INHERITED;
};
+SK_DEFINE_INST_COUNT(RefClass)
+
static void test_refptr(skiatest::Reporter* reporter) {
RefClass* r0 = new RefClass(0);