Extended Inst counting to find "unknown" leaked object (SkTMaskGamma)

http://codereview.appspot.com/6453127/



git-svn-id: http://skia.googlecode.com/svn/trunk@5123 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-08-16 14:58:06 +00:00
parent 1f47f4f732
commit a22e2117e4
30 changed files with 693 additions and 593 deletions

View File

@ -37,6 +37,8 @@ class SkColorSpace;
*/
class SkImage : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkImage)
enum ColorType {
kAlpha_8_ColorType,
kRGB_565_ColorType,

View File

@ -27,14 +27,20 @@ extern bool gPrintInstCount;
// 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); \
@ -93,7 +99,7 @@ extern bool gPrintInstCount;
return SkInstanceCountHelper::gInstanceCount; \
} \
\
static void AddInstChild(SkInstanceCountHelper::PFCheckInstCnt \
static void AddInstChild(templateType SkInstanceCountHelper::PFCheckInstCnt \
childCheckInstCnt) { \
if (CheckInstanceCount != childCheckInstCnt && \
NULL != SkInstanceCountHelper::gChildren) { \
@ -109,6 +115,7 @@ extern bool gPrintInstCount;
#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

View File

@ -26,6 +26,8 @@ class GrRenderTarget;
*/
class SkSurface : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkSurface)
/**
* Create a new surface, using the specified pixels/rowbytes as its
* backend.

View File

@ -13,6 +13,8 @@
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,
@ -22,6 +24,9 @@ public:
};
// Edge index goes clockwise around the boundary, beginning at the "top"
virtual SkPoint eval(Edge, SkScalar unitInterval) = 0;
private:
typedef SkRefCnt INHERITED;
};
class SkBoundaryPatch {

View File

@ -23,6 +23,8 @@ class SkCanvas;
class SkLayer : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkLayer)
SkLayer();
SkLayer(const SkLayer&);
virtual ~SkLayer();

View File

@ -21,7 +21,9 @@ struct SkTagList;
*/
class SkEventSink : public SkRefCnt {
public:
SkEventSink();
SK_DECLARE_INST_COUNT(SkEventSink)
SkEventSink();
virtual ~SkEventSink();
/**
@ -103,6 +105,8 @@ private:
// for our private link-list
SkEventSink* fNextSink;
typedef SkRefCnt INHERITED;
};
#endif

View File

@ -254,11 +254,15 @@ public:
*/
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.
@ -278,11 +282,15 @@ public:
*/
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

View File

@ -289,6 +289,8 @@ private:
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 */
@ -300,6 +302,8 @@ public:
virtual bool prepareWidgetEvent(SkEvent*, int rowIndex);
static SkListSource* Factory(const char name[]);
private:
typedef SkRefCnt INHERITED;
};
#endif

View File

@ -38,6 +38,8 @@ class GrContext;
#include "SkGPipe.h"
#include "SamplePipeControllers.h"
SK_DEFINE_INST_COUNT(SampleWindow::DeviceManager)
extern SampleView* CreateSamplePictFileView(const char filename[]);
class PictFileFactory : public SkViewFactory {

View File

@ -54,6 +54,8 @@ public:
*/
class DeviceManager : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(DeviceManager)
virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0;
virtual void tearDownBackend(SampleWindow* win) = 0;
@ -79,6 +81,8 @@ public:
// 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*);

View File

@ -12,6 +12,9 @@
#include "SkFlattenableBuffers.h"
#include "SkTSearch.h"
SK_DEFINE_INST_COUNT(SkBitmapHeapReader)
SK_DEFINE_INST_COUNT(SkBitmapHeap::ExternalStorage)
SkBitmapHeapEntry::SkBitmapHeapEntry()
: fSlot(-1)
, fRefCount(0)

View File

@ -52,6 +52,8 @@ private:
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;
@ -67,7 +69,12 @@ class SkBitmapHeap : public SkBitmapHeapReader {
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;

View File

@ -105,6 +105,8 @@ void SkTMaskGamma_build_correcting_lut(uint8_t table[256], U8CPU srcI, SkScalar
*/
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.
@ -151,6 +153,8 @@ private:
: (R_LUM_BITS > G_LUM_BITS ? R_LUM_BITS : G_LUM_BITS)
};
uint8_t fGammaTables[1 << kLuminanceBits_Max][256];
typedef SkRefCnt INHERITED;
};
/**

View File

@ -16,6 +16,8 @@
#include "SkTypeface.h"
#include "SkXfermode.h"
SK_DEFINE_INST_COUNT(SkFlatController)
///////////////////////////////////////////////////////////////////////////////
SkTypefacePlayback::SkTypefacePlayback() : fCount(0), fArray(NULL) {}

View File

@ -158,6 +158,8 @@ class SkFlatData;
class SkFlatController : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkFlatController)
SkFlatController();
virtual ~SkFlatController();
/**
@ -244,6 +246,8 @@ private:
SkTypefacePlayback* fTypefacePlayback;
SkNamedFactorySet* fFactorySet;
uint32_t fWriteBufferFlags;
typedef SkRefCnt INHERITED;
};
class SkFlatData {

View File

@ -9,6 +9,7 @@
#include "SkTSearch.h"
SK_DEFINE_INST_COUNT(SkPtrSet)
SK_DEFINE_INST_COUNT(SkNamedFactorySet)
void SkPtrSet::reset() {
Pair* p = fList.begin();

View File

@ -123,6 +123,8 @@ class SkFactorySet : public SkTPtrSet<SkFlattenable::Factory> {};
*/
class SkNamedFactorySet : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkNamedFactorySet)
SkNamedFactorySet();
/**
@ -142,6 +144,8 @@ private:
int fNextAddedFactory;
SkFactorySet fFactorySet;
SkTDArray<const char*> fNames;
typedef SkRefCnt INHERITED;
};
#endif

View File

@ -22,6 +22,8 @@
#include "SkStroke.h"
#include "SkThread.h"
SK_DEFINE_INST_COUNT(SkMaskGamma)
#define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3)
void SkGlyph::toMask(SkMask* mask) const {
@ -301,9 +303,9 @@ void SkScalerContext::getMetrics(SkGlyph* glyph) {
}
}
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;
@ -764,10 +766,10 @@ protected:
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));
}

View File

@ -10,6 +10,8 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
SK_DEFINE_INST_COUNT(SkImage)
static SkImage_Base* asIB(SkImage* image) {
return static_cast<SkImage_Base*>(image);
}

View File

@ -9,6 +9,8 @@
#include "SkImagePriv.h"
#include "SkCanvas.h"
SK_DEFINE_INST_COUNT(SkSurface)
///////////////////////////////////////////////////////////////////////////////
SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) {

View File

@ -7,6 +7,8 @@
*/
#include "SkBoundaryPatch.h"
SK_DEFINE_INST_COUNT(SkBoundary)
SkBoundaryPatch::SkBoundaryPatch() : fBoundary(NULL) {}
SkBoundaryPatch::~SkBoundaryPatch() {

View File

@ -15,6 +15,8 @@
static int gLayerAllocCount;
#endif
SK_DEFINE_INST_COUNT(SkLayer)
///////////////////////////////////////////////////////////////////////////////
SkLayer::SkLayer() {

View File

@ -14,6 +14,8 @@
#include "SkThread.h"
#include "SkTime.h"
SK_DEFINE_INST_COUNT(SkEventSink)
class SkEventSink_Globals {
public:
SkEventSink_Globals() {

File diff suppressed because it is too large Load Diff

View File

@ -15,79 +15,81 @@
/*
I have moved this to SkWidgetViews.h
enum SkinEnum {
kButton_SkinEnum,
kProgress_SkinEnum,
kScroll_SkinEnum,
kStaticText_SkinEnum,
kButton_SkinEnum,
kProgress_SkinEnum,
kScroll_SkinEnum,
kStaticText_SkinEnum,
kSkinEnumCount
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;
SkAnimator anim;
SkCanvas canvas;
init_skin_anim(se, &anim);
anim.draw(&canvas, paint, 0);
init_skin_anim(se, &anim);
anim.draw(&canvas, paint, 0);
}
void inflate_paint(const SkDOM& dom, const SkDOM::Node* node, SkPaint* paint)
{
SkASSERT(paint);
SkASSERT(paint);
SkAnimator anim;
SkCanvas canvas;
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);
if (!anim.decodeDOM(dom, node))
{
SkDEBUGF(("inflate_paint: decoding dom failed\n"));
SkDEBUGCODE(dom.dump(node);)
sk_throw();
}
anim.draw(&canvas, paint, 0);
}
////////////////////////////////////////////////////////////////////////////////////////
@ -98,99 +100,99 @@ SkWidgetView::SkWidgetView() : SkView(SkView::kFocusable_Mask | SkView::kEnabled
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 (!fEvent.isType(""))
{
SkEvent evt(fEvent); // make a copy since onPrepareWidgetEvent may edit the event
if (this->onPrepareWidgetEvent(&evt))
{
SkDEBUGCODE(evt.dump("SkWidgetView::postWidgetEvent");)
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;
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);
this->INHERITED::onInflate(dom, node);
const char* label = dom.findAttr(node, "label");
if (label)
this->setLabel(label);
const char* label = dom.findAttr(node, "label");
if (label)
this->setLabel(label);
if ((node = dom.getFirstChild(node, "event")) != NULL)
fEvent.inflate(dom, node);
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;
int32_t sinkID;
return evt.findS32(gWidgetEventSinkIDSlotName, &sinkID) ? (SkEventSinkID)sinkID : 0;
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);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -201,50 +203,50 @@ SkCheckButtonView::SkCheckButtonView() : fCheckState(kOff_CheckState)
void SkCheckButtonView::setCheckState(CheckState state)
{
SkASSERT((unsigned)state <= kUnknown_CheckState);
SkASSERT((unsigned)state <= kUnknown_CheckState);
if (fCheckState != state)
{
this->onCheckStateChange(this->getCheckState(), state);
fCheckState = SkToU8(state);
}
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);
this->INHERITED::onInflate(dom, node);
int index = dom.findList(node, "check-state", "off,on,unknown");
if (index >= 0)
this->setCheckState((CheckState)index);
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;
int32_t state32;
if (evt.findS32(gCheckStateSlotName, &state32))
{
if (state)
*state = (CheckState)state32;
return true;
}
return false;
if (evt.findS32(gCheckStateSlotName, &state32))
{
if (state)
*state = (CheckState)state32;
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -256,93 +258,93 @@ bool SkCheckButtonView::GetWidgetEventCheckState(const SkEvent& evt, CheckState*
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);
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);
}
SkEvent evt("user");
evt.setString("id", "setLabel");
evt.setString("LABEL", newLabel);
fAnim.doUserEvent(evt);
}
virtual void onFocusChange(bool gainFocus)
{
this->INHERITED::onFocusChange(gainFocus);
virtual void onFocusChange(bool gainFocus)
{
this->INHERITED::onFocusChange(gainFocus);
SkEvent evt("user");
evt.setString("id", "setFocus");
evt.setS32("FOCUS", gainFocus);
fAnim.doUserEvent(evt);
}
SkEvent evt("user");
evt.setString("id", "setFocus");
evt.setS32("FOCUS", gainFocus);
fAnim.doUserEvent(evt);
}
virtual void onSizeChange()
{
this->INHERITED::onSizeChange();
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);
}
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());
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);
}
}
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;
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);
}
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 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;
SkAnimator fAnim;
typedef SkButtonView INHERITED;
typedef SkButtonView INHERITED;
};
////////////////////////////////////////////////////////////////////////////////////////////
@ -350,26 +352,26 @@ private:
SkView* SkWidgetFactory(const char name[])
{
if (name == NULL)
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"
// 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);
for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); i++)
if (!strcmp(gNames[i], name))
return SkWidgetFactory((SkWidgetEnum)i);
return NULL;
return NULL;
}
#include "SkImageView.h"
@ -379,24 +381,24 @@ SkView* SkWidgetFactory(const char name[])
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;
}

View File

@ -337,6 +337,9 @@ static bool operator==(const SkRasterClip& a, const SkRasterClip& b) {
SkMask ma, mb;
copyToMask(a, &ma);
copyToMask(b, &mb);
SkAutoMaskFreeImage aCleanUp(ma.fImage);
SkAutoMaskFreeImage bCleanUp(mb.fImage);
return ma == mb;
}

View File

@ -9,8 +9,14 @@
#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;

View File

@ -16,6 +16,8 @@
class GrContext;
#endif
SK_DEFINE_INST_COUNT(skiatest::Reporter)
using namespace skiatest;
Reporter::Reporter() {

View File

@ -21,6 +21,7 @@ namespace skiatest {
class Reporter : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(Reporter)
Reporter();
enum Result {

View File

@ -14,13 +14,19 @@
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);