From ef284a84f503adfd08ee52b5aee142c548698ea4 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Thu, 11 Jul 2013 22:29:29 +0000 Subject: [PATCH] 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 --- gm/gm_expectations.cpp | 1 + gm/gm_expectations.h | 5 +++++ gm/megalooper.cpp | 4 ++-- include/core/SkDocument.h | 4 ++++ include/gpu/GrOvalRenderer.h | 6 +++++- include/lazy/SkBitmapFactory.h | 4 ++++ include/lazy/SkImageCache.h | 5 +++++ include/lazy/SkLruImageCache.h | 2 ++ include/lazy/SkPurgeableImageCache.h | 2 ++ include/ports/SkFontConfigInterface.h | 2 ++ include/ports/SkFontMgr.h | 7 +++++++ src/core/SkFontHost.cpp | 5 +++++ src/doc/SkDocument.cpp | 2 ++ src/gpu/GrContext.cpp | 2 ++ src/gpu/GrOvalRenderer.cpp | 4 ++++ src/lazy/SkBitmapFactory.cpp | 2 ++ src/lazy/SkLruImageCache.cpp | 3 +++ src/lazy/SkPurgeableImageCache.cpp | 1 + 18 files changed, 58 insertions(+), 3 deletions(-) diff --git a/gm/gm_expectations.cpp b/gm/gm_expectations.cpp index 9c0c274d3f..7d6ccf6464 100644 --- a/gm/gm_expectations.cpp +++ b/gm/gm_expectations.cpp @@ -27,6 +27,7 @@ const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5"; 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 ec6899794a..96c6d11d25 100644 --- a/gm/gm_expectations.h +++ b/gm/gm_expectations.h @@ -172,7 +172,12 @@ namespace skiagm { */ 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 832b0a8749..0f3811a8bf 100644 --- a/gm/megalooper.cpp +++ b/gm/megalooper.cpp @@ -131,7 +131,7 @@ private: 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 @@ private: 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 b1c1fcf9c0..bbed64a806 100644 --- a/include/core/SkDocument.h +++ b/include/core/SkDocument.h @@ -26,6 +26,8 @@ class SkWStream; */ 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 @@ private: SkWStream* fStream; void (*fDoneProc)(SkWStream*); State fState; + + typedef SkRefCnt INHERITED; }; #endif diff --git a/include/gpu/GrOvalRenderer.h b/include/gpu/GrOvalRenderer.h index a6ec52c7a8..a9d41b40e0 100644 --- a/include/gpu/GrOvalRenderer.h +++ b/include/gpu/GrOvalRenderer.h @@ -27,7 +27,11 @@ public: 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 eb427ee390..e967a915b2 100644 --- a/include/lazy/SkBitmapFactory.h +++ b/include/lazy/SkBitmapFactory.h @@ -72,12 +72,16 @@ public: 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 7c4926109a..6d30ae73f0 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 @@ public: */ 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 3e9d315095..5170a05a54 100644 --- a/include/lazy/SkLruImageCache.h +++ b/include/lazy/SkLruImageCache.h @@ -20,6 +20,8 @@ class CachedPixels; 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 cc2db819f9..24525b0e50 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 3284d387ac..661c3beff2 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 986edd3fa1..d353f3a984 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -18,16 +18,23 @@ class SkTypeface; 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 5fabb0fc59..734b3aa1b8 100644 --- a/src/core/SkFontHost.cpp +++ b/src/core/SkFontHost.cpp @@ -68,6 +68,9 @@ SkFontStyle::SkFontStyle(int weight, int width, Slant slant) { #include "SkFontMgr.h" + +SK_DEFINE_INST_COUNT(SkFontStyleSet) + class SkEmptyFontStyleSet : public SkFontStyleSet { public: virtual int count() SK_OVERRIDE { return 0; } @@ -89,6 +92,8 @@ SkFontStyleSet* SkFontStyleSet::CreateEmpty() { /////////////////////////////////////////////////////////////////////////////// +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 b051300617..e94c89bbeb 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 39d0db33b4..d9924bf314 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -198,6 +198,7 @@ void GrContext::contextDestroyed() { fDrawBufferIBAllocPool = NULL; fAARectRenderer->reset(); + fOvalRenderer->reset(); fTextureCache->purgeAllUnlocked(); fFontCache->freeAll(); @@ -214,6 +215,7 @@ void GrContext::freeGpuResources() { fGpu->purgeResources(); fAARectRenderer->reset(); + fOvalRenderer->reset(); fTextureCache->purgeAllUnlocked(); fFontCache->freeAll(); diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index bcd64d740d..85526dc6b3 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -286,6 +286,10 @@ GrEffectRef* EllipseEdgeEffect::TestCreate(SkMWCRandom* random, /////////////////////////////////////////////////////////////////////////////// +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 60c4993e3c..0ff4ee2d17 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 26f7ef5483..40cfefa29b 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 0f2c5e3c8e..0d36e4a9a9 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() {