The two leaks are:

missing unrefs in megalooper GM
  missing reset capability in oval renderer

This CL also expands the instance counting system to some recently adding classes (e.g., SkFontStyleSet)

R=bsalomon@google.com, jvanverth@google.com

Author: robertphillips@google.com

Review URL: https://chromiumcodereview.appspot.com/18461007

git-svn-id: http://skia.googlecode.com/svn/trunk@10030 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-07-11 22:29:29 +00:00
parent 40ea172f1e
commit ef284a84f5
18 changed files with 58 additions and 3 deletions

View File

@ -27,6 +27,7 @@ const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5";
namespace skiagm { namespace skiagm {
SK_DEFINE_INST_COUNT(ExpectationsSource)
void gm_fprintf(FILE *stream, const char format[], ...) { void gm_fprintf(FILE *stream, const char format[], ...) {
va_list args; va_list args;

View File

@ -172,7 +172,12 @@ namespace skiagm {
*/ */
class ExpectationsSource : public SkRefCnt { class ExpectationsSource : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(ExpectationsSource)
virtual Expectations get(const char *testName) = 0; virtual Expectations get(const char *testName) = 0;
private:
typedef SkRefCnt INHERITED;
}; };
/** /**

View File

@ -131,7 +131,7 @@ private:
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
SkPaint loopPaint; SkPaint loopPaint;
loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i])); loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]))->unref();
loopPaint.setAntiAlias(true); loopPaint.setAntiAlias(true);
SkRect outerClip = { SkRect outerClip = {
@ -194,7 +194,7 @@ private:
SkPaint paint; SkPaint paint;
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0)); paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0))->unref();
canvas->save(); canvas->save();
canvas->clipRect(outerClip, SkRegion::kIntersect_Op); canvas->clipRect(outerClip, SkRegion::kIntersect_Op);

View File

@ -26,6 +26,8 @@ class SkWStream;
*/ */
class SkDocument : public SkRefCnt { class SkDocument : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(SkDocument)
/** /**
* Create a PDF-backed document, writing the results into a file. * Create a PDF-backed document, writing the results into a file.
* If there is an error trying to create the doc, returns NULL. * If there is an error trying to create the doc, returns NULL.
@ -89,6 +91,8 @@ private:
SkWStream* fStream; SkWStream* fStream;
void (*fDoneProc)(SkWStream*); void (*fDoneProc)(SkWStream*);
State fState; State fState;
typedef SkRefCnt INHERITED;
}; };
#endif #endif

View File

@ -27,7 +27,11 @@ public:
SK_DECLARE_INST_COUNT(GrOvalRenderer) SK_DECLARE_INST_COUNT(GrOvalRenderer)
GrOvalRenderer() : fRRectIndexBuffer(NULL) {} GrOvalRenderer() : fRRectIndexBuffer(NULL) {}
~GrOvalRenderer() {} ~GrOvalRenderer() {
this->reset();
}
void reset();
bool drawOval(GrDrawTarget* target, const GrContext* context, bool useAA, bool drawOval(GrDrawTarget* target, const GrContext* context, bool useAA,
const GrRect& oval, const SkStrokeRec& stroke); const GrRect& oval, const SkStrokeRec& stroke);

View File

@ -72,12 +72,16 @@ public:
class CacheSelector : public SkRefCnt { class CacheSelector : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(CacheSelector)
/** /**
* Return an SkImageCache to use based on the provided SkImage::Info. If the caller decides * Return an SkImageCache to use based on the provided SkImage::Info. If the caller decides
* to hang on to the result, it will call ref, so the implementation should not add a ref * to hang on to the result, it will call ref, so the implementation should not add a ref
* as a result of this call. * as a result of this call.
*/ */
virtual SkImageCache* selectCache(const SkImage::Info&) = 0; virtual SkImageCache* selectCache(const SkImage::Info&) = 0;
private:
typedef SkRefCnt INHERITED;
}; };
/** /**

View File

@ -17,6 +17,8 @@
class SkImageCache : public SkRefCnt { class SkImageCache : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(SkImageCache)
typedef intptr_t ID; typedef intptr_t ID;
/** /**
@ -123,5 +125,8 @@ public:
*/ */
virtual void purgeAllUnpinnedCaches() = 0; virtual void purgeAllUnpinnedCaches() = 0;
#endif #endif
private:
typedef SkRefCnt INHERITED;
}; };
#endif // SkImageCache_DEFINED #endif // SkImageCache_DEFINED

View File

@ -20,6 +20,8 @@ class CachedPixels;
class SkLruImageCache : public SkImageCache { class SkLruImageCache : public SkImageCache {
public: public:
SK_DECLARE_INST_COUNT(SkLruImageCache)
SkLruImageCache(size_t budget); SkLruImageCache(size_t budget);
virtual ~SkLruImageCache(); virtual ~SkLruImageCache();

View File

@ -20,6 +20,8 @@
class SkPurgeableImageCache : public SkImageCache { class SkPurgeableImageCache : public SkImageCache {
public: public:
SK_DECLARE_INST_COUNT(SkPurgeableImageCache)
static SkImageCache* Create(); static SkImageCache* Create();
virtual void* allocAndPinCache(size_t bytes, ID*) SK_OVERRIDE; virtual void* allocAndPinCache(size_t bytes, ID*) SK_OVERRIDE;

View File

@ -22,6 +22,8 @@
*/ */
class SK_API SkFontConfigInterface : public SkRefCnt { class SK_API SkFontConfigInterface : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(SkFontConfigInterface)
/** /**
* Returns the global SkFontConfigInterface instance, and if it is not * Returns the global SkFontConfigInterface instance, and if it is not
* NULL, calls ref() on it. The caller must balance this with a call to * NULL, calls ref() on it. The caller must balance this with a call to

View File

@ -18,16 +18,23 @@ class SkTypeface;
class SK_API SkFontStyleSet : public SkRefCnt { class SK_API SkFontStyleSet : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(SkFontStyleSet)
virtual int count() = 0; virtual int count() = 0;
virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
virtual SkTypeface* createTypeface(int index) = 0; virtual SkTypeface* createTypeface(int index) = 0;
virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0;
static SkFontStyleSet* CreateEmpty(); static SkFontStyleSet* CreateEmpty();
private:
typedef SkRefCnt INHERITED;
}; };
class SK_API SkFontMgr : public SkRefCnt { class SK_API SkFontMgr : public SkRefCnt {
public: public:
SK_DECLARE_INST_COUNT(SkFontMgr)
int countFamilies(); int countFamilies();
void getFamilyName(int index, SkString* familyName); void getFamilyName(int index, SkString* familyName);
SkFontStyleSet* createStyleSet(int index); SkFontStyleSet* createStyleSet(int index);

View File

@ -68,6 +68,9 @@ SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
#include "SkFontMgr.h" #include "SkFontMgr.h"
SK_DEFINE_INST_COUNT(SkFontStyleSet)
class SkEmptyFontStyleSet : public SkFontStyleSet { class SkEmptyFontStyleSet : public SkFontStyleSet {
public: public:
virtual int count() SK_OVERRIDE { return 0; } virtual int count() SK_OVERRIDE { return 0; }
@ -89,6 +92,8 @@ SkFontStyleSet* SkFontStyleSet::CreateEmpty() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SK_DEFINE_INST_COUNT(SkFontMgr)
class SkEmptyFontMgr : public SkFontMgr { class SkEmptyFontMgr : public SkFontMgr {
protected: protected:
virtual int onCountFamilies() SK_OVERRIDE { virtual int onCountFamilies() SK_OVERRIDE {

View File

@ -8,6 +8,8 @@
#include "SkDocument.h" #include "SkDocument.h"
#include "SkStream.h" #include "SkStream.h"
SK_DEFINE_INST_COUNT(SkDocument)
SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) { SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) {
fStream = stream; // we do not own this object. fStream = stream; // we do not own this object.
fDoneProc = doneProc; fDoneProc = doneProc;

View File

@ -198,6 +198,7 @@ void GrContext::contextDestroyed() {
fDrawBufferIBAllocPool = NULL; fDrawBufferIBAllocPool = NULL;
fAARectRenderer->reset(); fAARectRenderer->reset();
fOvalRenderer->reset();
fTextureCache->purgeAllUnlocked(); fTextureCache->purgeAllUnlocked();
fFontCache->freeAll(); fFontCache->freeAll();
@ -214,6 +215,7 @@ void GrContext::freeGpuResources() {
fGpu->purgeResources(); fGpu->purgeResources();
fAARectRenderer->reset(); fAARectRenderer->reset();
fOvalRenderer->reset();
fTextureCache->purgeAllUnlocked(); fTextureCache->purgeAllUnlocked();
fFontCache->freeAll(); fFontCache->freeAll();

View File

@ -286,6 +286,10 @@ GrEffectRef* EllipseEdgeEffect::TestCreate(SkMWCRandom* random,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void GrOvalRenderer::reset() {
GrSafeSetNull(fRRectIndexBuffer);
}
bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bool useAA, bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bool useAA,
const GrRect& oval, const SkStrokeRec& stroke) const GrRect& oval, const SkStrokeRec& stroke)
{ {

View File

@ -13,6 +13,8 @@
#include "SkImagePriv.h" #include "SkImagePriv.h"
#include "SkLazyPixelRef.h" #include "SkLazyPixelRef.h"
SK_DEFINE_INST_COUNT(SkBitmapFactory::CacheSelector)
SkBitmapFactory::SkBitmapFactory(SkBitmapFactory::DecodeProc proc) SkBitmapFactory::SkBitmapFactory(SkBitmapFactory::DecodeProc proc)
: fDecodeProc(proc) : fDecodeProc(proc)
, fImageCache(NULL) , fImageCache(NULL)

View File

@ -7,6 +7,9 @@
#include "SkLruImageCache.h" #include "SkLruImageCache.h"
SK_DEFINE_INST_COUNT(SkImageCache)
SK_DEFINE_INST_COUNT(SkLruImageCache)
static intptr_t NextGenerationID() { static intptr_t NextGenerationID() {
static intptr_t gNextID; static intptr_t gNextID;
do { do {

View File

@ -13,6 +13,7 @@
#include "SkTSearch.h" #include "SkTSearch.h"
#endif #endif
SK_DEFINE_INST_COUNT(SkPurgeableImageCache)
SK_DECLARE_STATIC_MUTEX(gPurgeableImageMutex); SK_DECLARE_STATIC_MUTEX(gPurgeableImageMutex);
SkImageCache* SkPurgeableImageCache::Create() { SkImageCache* SkPurgeableImageCache::Create() {