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
diff --git a/gm/gm_expectations.cpp b/gm/gm_expectations.cpp
index 9c0c274..7d6ccf6 100644
--- a/gm/gm_expectations.cpp
+++ b/gm/gm_expectations.cpp
@@ -27,6 +27,7 @@
namespace skiagm {
+ SK_DEFINE_INST_COUNT(ExpectationsSource)
void gm_fprintf(FILE *stream, const char format[], ...) {
va_list args;
diff --git a/gm/gm_expectations.h b/gm/gm_expectations.h
index ec68997..96c6d11 100644
--- a/gm/gm_expectations.h
+++ b/gm/gm_expectations.h
@@ -172,7 +172,12 @@
*/
class ExpectationsSource : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(ExpectationsSource)
+
virtual Expectations get(const char *testName) = 0;
+
+ private:
+ typedef SkRefCnt INHERITED;
};
/**
diff --git a/gm/megalooper.cpp b/gm/megalooper.cpp
index 832b0a8..0f3811a 100644
--- a/gm/megalooper.cpp
+++ b/gm/megalooper.cpp
@@ -131,7 +131,7 @@
for (int i = 0; i < 4; ++i) {
SkPaint loopPaint;
- loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]));
+ loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]))->unref();
loopPaint.setAntiAlias(true);
SkRect outerClip = {
@@ -194,7 +194,7 @@
SkPaint paint;
paint.setAntiAlias(true);
- paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0));
+ paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0))->unref();
canvas->save();
canvas->clipRect(outerClip, SkRegion::kIntersect_Op);
diff --git a/include/core/SkDocument.h b/include/core/SkDocument.h
index b1c1fcf..bbed64a 100644
--- a/include/core/SkDocument.h
+++ b/include/core/SkDocument.h
@@ -26,6 +26,8 @@
*/
class SkDocument : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkDocument)
+
/**
* Create a PDF-backed document, writing the results into a file.
* If there is an error trying to create the doc, returns NULL.
@@ -89,6 +91,8 @@
SkWStream* fStream;
void (*fDoneProc)(SkWStream*);
State fState;
+
+ typedef SkRefCnt INHERITED;
};
#endif
diff --git a/include/gpu/GrOvalRenderer.h b/include/gpu/GrOvalRenderer.h
index a6ec52c..a9d41b4 100644
--- a/include/gpu/GrOvalRenderer.h
+++ b/include/gpu/GrOvalRenderer.h
@@ -27,7 +27,11 @@
SK_DECLARE_INST_COUNT(GrOvalRenderer)
GrOvalRenderer() : fRRectIndexBuffer(NULL) {}
- ~GrOvalRenderer() {}
+ ~GrOvalRenderer() {
+ this->reset();
+ }
+
+ void reset();
bool drawOval(GrDrawTarget* target, const GrContext* context, bool useAA,
const GrRect& oval, const SkStrokeRec& stroke);
diff --git a/include/lazy/SkBitmapFactory.h b/include/lazy/SkBitmapFactory.h
index eb427ee..e967a91 100644
--- a/include/lazy/SkBitmapFactory.h
+++ b/include/lazy/SkBitmapFactory.h
@@ -72,12 +72,16 @@
class CacheSelector : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(CacheSelector)
/**
* 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
* as a result of this call.
*/
virtual SkImageCache* selectCache(const SkImage::Info&) = 0;
+
+ private:
+ typedef SkRefCnt INHERITED;
};
/**
diff --git a/include/lazy/SkImageCache.h b/include/lazy/SkImageCache.h
index 7c49261..6d30ae7 100644
--- a/include/lazy/SkImageCache.h
+++ b/include/lazy/SkImageCache.h
@@ -17,6 +17,8 @@
class SkImageCache : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkImageCache)
+
typedef intptr_t ID;
/**
@@ -123,5 +125,8 @@
*/
virtual void purgeAllUnpinnedCaches() = 0;
#endif
+
+private:
+ typedef SkRefCnt INHERITED;
};
#endif // SkImageCache_DEFINED
diff --git a/include/lazy/SkLruImageCache.h b/include/lazy/SkLruImageCache.h
index 3e9d315..5170a05 100644
--- a/include/lazy/SkLruImageCache.h
+++ b/include/lazy/SkLruImageCache.h
@@ -20,6 +20,8 @@
class SkLruImageCache : public SkImageCache {
public:
+ SK_DECLARE_INST_COUNT(SkLruImageCache)
+
SkLruImageCache(size_t budget);
virtual ~SkLruImageCache();
diff --git a/include/lazy/SkPurgeableImageCache.h b/include/lazy/SkPurgeableImageCache.h
index cc2db81..24525b0 100644
--- a/include/lazy/SkPurgeableImageCache.h
+++ b/include/lazy/SkPurgeableImageCache.h
@@ -20,6 +20,8 @@
class SkPurgeableImageCache : public SkImageCache {
public:
+ SK_DECLARE_INST_COUNT(SkPurgeableImageCache)
+
static SkImageCache* Create();
virtual void* allocAndPinCache(size_t bytes, ID*) SK_OVERRIDE;
diff --git a/include/ports/SkFontConfigInterface.h b/include/ports/SkFontConfigInterface.h
index 3284d38..661c3be 100644
--- a/include/ports/SkFontConfigInterface.h
+++ b/include/ports/SkFontConfigInterface.h
@@ -22,6 +22,8 @@
*/
class SK_API SkFontConfigInterface : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkFontConfigInterface)
+
/**
* Returns the global SkFontConfigInterface instance, and if it is not
* NULL, calls ref() on it. The caller must balance this with a call to
diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h
index 986edd3..d353f3a 100644
--- a/include/ports/SkFontMgr.h
+++ b/include/ports/SkFontMgr.h
@@ -18,16 +18,23 @@
class SK_API SkFontStyleSet : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkFontStyleSet)
+
virtual int count() = 0;
virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
virtual SkTypeface* createTypeface(int index) = 0;
virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0;
static SkFontStyleSet* CreateEmpty();
+
+private:
+ typedef SkRefCnt INHERITED;
};
class SK_API SkFontMgr : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkFontMgr)
+
int countFamilies();
void getFamilyName(int index, SkString* familyName);
SkFontStyleSet* createStyleSet(int index);
diff --git a/src/core/SkFontHost.cpp b/src/core/SkFontHost.cpp
index 5fabb0f..734b3aa 100644
--- a/src/core/SkFontHost.cpp
+++ b/src/core/SkFontHost.cpp
@@ -68,6 +68,9 @@
#include "SkFontMgr.h"
+
+SK_DEFINE_INST_COUNT(SkFontStyleSet)
+
class SkEmptyFontStyleSet : public SkFontStyleSet {
public:
virtual int count() SK_OVERRIDE { return 0; }
@@ -89,6 +92,8 @@
///////////////////////////////////////////////////////////////////////////////
+SK_DEFINE_INST_COUNT(SkFontMgr)
+
class SkEmptyFontMgr : public SkFontMgr {
protected:
virtual int onCountFamilies() SK_OVERRIDE {
diff --git a/src/doc/SkDocument.cpp b/src/doc/SkDocument.cpp
index b051300..e94c89b 100644
--- a/src/doc/SkDocument.cpp
+++ b/src/doc/SkDocument.cpp
@@ -8,6 +8,8 @@
#include "SkDocument.h"
#include "SkStream.h"
+SK_DEFINE_INST_COUNT(SkDocument)
+
SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) {
fStream = stream; // we do not own this object.
fDoneProc = doneProc;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 39d0db3..d9924bf 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -198,6 +198,7 @@
fDrawBufferIBAllocPool = NULL;
fAARectRenderer->reset();
+ fOvalRenderer->reset();
fTextureCache->purgeAllUnlocked();
fFontCache->freeAll();
@@ -214,6 +215,7 @@
fGpu->purgeResources();
fAARectRenderer->reset();
+ fOvalRenderer->reset();
fTextureCache->purgeAllUnlocked();
fFontCache->freeAll();
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index bcd64d7..85526dc 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -286,6 +286,10 @@
///////////////////////////////////////////////////////////////////////////////
+void GrOvalRenderer::reset() {
+ GrSafeSetNull(fRRectIndexBuffer);
+}
+
bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bool useAA,
const GrRect& oval, const SkStrokeRec& stroke)
{
diff --git a/src/lazy/SkBitmapFactory.cpp b/src/lazy/SkBitmapFactory.cpp
index 60c4993..0ff4ee2 100644
--- a/src/lazy/SkBitmapFactory.cpp
+++ b/src/lazy/SkBitmapFactory.cpp
@@ -13,6 +13,8 @@
#include "SkImagePriv.h"
#include "SkLazyPixelRef.h"
+SK_DEFINE_INST_COUNT(SkBitmapFactory::CacheSelector)
+
SkBitmapFactory::SkBitmapFactory(SkBitmapFactory::DecodeProc proc)
: fDecodeProc(proc)
, fImageCache(NULL)
diff --git a/src/lazy/SkLruImageCache.cpp b/src/lazy/SkLruImageCache.cpp
index 26f7ef5..40cfefa 100644
--- a/src/lazy/SkLruImageCache.cpp
+++ b/src/lazy/SkLruImageCache.cpp
@@ -7,6 +7,9 @@
#include "SkLruImageCache.h"
+SK_DEFINE_INST_COUNT(SkImageCache)
+SK_DEFINE_INST_COUNT(SkLruImageCache)
+
static intptr_t NextGenerationID() {
static intptr_t gNextID;
do {
diff --git a/src/lazy/SkPurgeableImageCache.cpp b/src/lazy/SkPurgeableImageCache.cpp
index 0f2c5e3..0d36e4a 100644
--- a/src/lazy/SkPurgeableImageCache.cpp
+++ b/src/lazy/SkPurgeableImageCache.cpp
@@ -13,6 +13,7 @@
#include "SkTSearch.h"
#endif
+SK_DEFINE_INST_COUNT(SkPurgeableImageCache)
SK_DECLARE_STATIC_MUTEX(gPurgeableImageMutex);
SkImageCache* SkPurgeableImageCache::Create() {