aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-13 18:54:08 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-13 18:54:08 +0000
commit4d73ac22a1b99402fc8cff78a4eb4b27aa8fe019 (patch)
treee12e9be96cdc105dfc275ee9ada6982d81d3e4fb
parent972265db219ce25b5159879c75e6c62efaf0fa79 (diff)
Version 2 of the Instance Counting system. This one simplifies the print out of information.
-rw-r--r--gm/gmmain.cpp6
-rw-r--r--include/core/SkInstCnt.h90
-rw-r--r--include/core/SkRefCnt.h4
-rw-r--r--include/gpu/GrAARectRenderer.h4
-rw-r--r--include/gpu/GrRenderTarget.h1
-rw-r--r--include/gpu/GrResource.h2
-rw-r--r--include/gpu/GrTexture.h2
-rw-r--r--src/core/SkPathHeap.cpp2
-rw-r--r--src/core/SkPathHeap.h8
-rw-r--r--src/core/SkRefCnt.cpp12
-rw-r--r--src/gpu/GrAARectRenderer.cpp2
-rw-r--r--src/gpu/GrPathRendererChain.cpp2
-rw-r--r--src/gpu/GrPathRendererChain.h3
-rw-r--r--src/gpu/GrRenderTarget.cpp2
-rw-r--r--src/gpu/GrResource.cpp2
-rw-r--r--src/gpu/GrTexture.cpp2
-rw-r--r--src/pdf/SkPDFTypes.cpp2
-rw-r--r--src/pdf/SkPDFTypes.h4
18 files changed, 106 insertions, 44 deletions
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index e91ea8f549..877d0afa56 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -1086,9 +1086,9 @@ int main(int argc, char * const argv[]) {
delete grFactory;
SkGraphics::Term();
- PRINT_INST_COUNT(SkRefCnt);
- PRINT_INST_COUNT(GrResource);
- PRINT_INST_COUNT(GrAARectRenderer);
+#ifdef SK_DEBUG
+ SkRefCnt::CheckInstanceCount();
+#endif
return (0 == testsFailed) ? 0 : -1;
}
diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h
index 3c63ef7e28..f3519a14dd 100644
--- a/include/core/SkInstCnt.h
+++ b/include/core/SkInstCnt.h
@@ -12,40 +12,74 @@
/*
* The instance counting system consists of three macros that create the
* instance counting machinery. A class is added to the system by adding:
- * DECLARE_INST_COUNT at the top of its declaration
- * DEFINE_INST_COUNT at the top of its .cpp file
- * and a PRINT_INST_COUNT line at the application's end point
+ * SK_DECLARE_INST_COUNT at the top of its declaration for derived classes
+ * SK_DECLARE_INST_COUNT_ROOT at the top of its declaration for a root class
+ * SK_DEFINE_INST_COUNT at the top of its .cpp file (for both kinds).
+ * At the end of an application a call to all the "root" objects'
+ * CheckInstanceCount methods should be made
*/
#ifdef SK_DEBUG
-#define DECLARE_INST_COUNT \
- class SkInstanceCountHelper { \
- public: \
- SkInstanceCountHelper() { \
- gInstanceCount++; \
- } \
- \
- ~SkInstanceCountHelper() { \
- gInstanceCount--; \
- } \
- \
- static int32_t gInstanceCount; \
- } fInstanceCountHelper; \
- \
- static int32_t GetInstanceCount() { \
- return SkInstanceCountHelper::gInstanceCount; \
+#include "SkTArray.h"
+
+#define SK_DECLARE_INST_COUNT(className) \
+ SK_DECLARE_INST_COUNT_INTERNAL(className, \
+ INHERITED::AddInstChild(CheckInstanceCount);)
+
+#define SK_DECLARE_INST_COUNT_ROOT(className) \
+ SK_DECLARE_INST_COUNT_INTERNAL(className, ;)
+
+#define SK_DECLARE_INST_COUNT_INTERNAL(className, initStep) \
+ class SkInstanceCountHelper { \
+ public: \
+ typedef void (*PFCheckInstCnt)(); \
+ SkInstanceCountHelper() { \
+ if (!gInited) { \
+ initStep \
+ gInited = true; \
+ } \
+ gInstanceCount++; \
+ } \
+ \
+ SkInstanceCountHelper(const SkInstanceCountHelper& other) { \
+ gInstanceCount++; \
+ } \
+ \
+ ~SkInstanceCountHelper() { \
+ gInstanceCount--; \
+ } \
+ \
+ static int32_t gInstanceCount; \
+ static bool gInited; \
+ static SkTArray<PFCheckInstCnt> gChildren; \
+ } fInstanceCountHelper; \
+ \
+ static void CheckInstanceCount() { \
+ if (0 != SkInstanceCountHelper::gInstanceCount) { \
+ SkDebugf("Leaked %s objects: %d\n", #className, \
+ SkInstanceCountHelper::gInstanceCount); \
+ } \
+ for (int i = 0; i < SkInstanceCountHelper::gChildren.count(); ++i) { \
+ (*SkInstanceCountHelper::gChildren[i])(); \
+ } \
+ } \
+ \
+ static void AddInstChild(SkInstanceCountHelper::PFCheckInstCnt \
+ childCheckInstCnt) { \
+ if (CheckInstanceCount != childCheckInstCnt) { \
+ SkInstanceCountHelper::gChildren.push_back(childCheckInstCnt); \
+ } \
}
-#define DEFINE_INST_COUNT(className) \
- int32_t className::SkInstanceCountHelper::gInstanceCount = 0;
+#define SK_DEFINE_INST_COUNT(className) \
+ int32_t className::SkInstanceCountHelper::gInstanceCount = 0; \
+ bool className::SkInstanceCountHelper::gInited = false; \
+ SkTArray<className::SkInstanceCountHelper::PFCheckInstCnt> \
+ className::SkInstanceCountHelper::gChildren;
-#define PRINT_INST_COUNT(className) \
- SkDebugf("Leaked %s objects: %d\n", \
- #className, \
- className::GetInstanceCount());
#else
-#define DECLARE_INST_COUNT
-#define DEFINE_INST_COUNT(className)
-#define PRINT_INST_COUNT(className)
+#define SK_DECLARE_INST_COUNT(className)
+#define SK_DECLARE_INST_COUNT_ROOT(className)
+#define SK_DEFINE_INST_COUNT(className)
#endif
#endif // SkInstCnt_DEFINED
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 761546b12b..a00bc3e3f1 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -25,7 +25,7 @@
*/
class SK_API SkRefCnt : SkNoncopyable {
public:
- DECLARE_INST_COUNT
+ SK_DECLARE_INST_COUNT_ROOT(SkRefCnt)
/** Default construct, initializing the reference count to 1.
*/
@@ -83,6 +83,8 @@ private:
friend class SkWeakRefCnt;
mutable int32_t fRefCnt;
+
+ typedef SkNoncopyable INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
diff --git a/include/gpu/GrAARectRenderer.h b/include/gpu/GrAARectRenderer.h
index c809091181..fdaa30a47e 100644
--- a/include/gpu/GrAARectRenderer.h
+++ b/include/gpu/GrAARectRenderer.h
@@ -21,7 +21,7 @@ class GrIndexBuffer;
*/
class GrAARectRenderer : public GrRefCnt {
public:
- DECLARE_INST_COUNT
+ SK_DECLARE_INST_COUNT(GrAARectRenderer)
GrAARectRenderer()
: fAAFillRectIndexBuffer(NULL)
@@ -62,6 +62,8 @@ private:
static int aaStrokeRectIndexCount();
GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu);
+
+ typedef GrRefCnt INHERITED;
};
#endif // GrAARectRenderer_DEFINED
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index 4a2c254da2..c26ca4bb7e 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -33,6 +33,7 @@ class GrTexture;
*/
class GrRenderTarget : public GrResource {
public:
+ SK_DECLARE_INST_COUNT(GrRenderTarget)
/**
* @return the width of the rendertarget
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h
index 4c491c7369..94d2173ec2 100644
--- a/include/gpu/GrResource.h
+++ b/include/gpu/GrResource.h
@@ -20,7 +20,7 @@ class GrContext;
*/
class GrResource : public GrRefCnt {
public:
- DECLARE_INST_COUNT
+ SK_DECLARE_INST_COUNT(GrResource)
/**
* Frees the resource in the underlying 3D API. It must be safe to call this
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 1997f68ddf..704bb28f0b 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -31,6 +31,8 @@ static const uint64_t kScratch_CacheID = 0xBBBBBBBB;
class GrTexture : public GrResource {
public:
+ SK_DECLARE_INST_COUNT(GrTexture)
+
/**
* Retrieves the width of the texture.
*
diff --git a/src/core/SkPathHeap.cpp b/src/core/SkPathHeap.cpp
index a9183c3242..8713e7672f 100644
--- a/src/core/SkPathHeap.cpp
+++ b/src/core/SkPathHeap.cpp
@@ -11,6 +11,8 @@
#include "SkFlattenable.h"
#include <new>
+SK_DEFINE_INST_COUNT(SkPathHeap)
+
#define kPathCount 64
SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
diff --git a/src/core/SkPathHeap.h b/src/core/SkPathHeap.h
index 99c2626b04..32adbc0839 100644
--- a/src/core/SkPathHeap.h
+++ b/src/core/SkPathHeap.h
@@ -18,8 +18,10 @@ class SkFlattenableWriteBuffer;
class SkPathHeap : public SkRefCnt {
public:
- SkPathHeap();
- SkPathHeap(SkFlattenableReadBuffer&);
+ SK_DECLARE_INST_COUNT(SkPathHeap)
+
+ SkPathHeap();
+ SkPathHeap(SkFlattenableReadBuffer&);
virtual ~SkPathHeap();
/** Copy the path into the heap, and return the new total number of paths.
@@ -41,6 +43,8 @@ private:
SkChunkAlloc fHeap;
// we just store ptrs into fHeap here
SkTDArray<SkPath*> fPaths;
+
+ typedef SkRefCnt INHERITED;
};
#endif
diff --git a/src/core/SkRefCnt.cpp b/src/core/SkRefCnt.cpp
index 111ecd834c..599e7f269e 100644
--- a/src/core/SkRefCnt.cpp
+++ b/src/core/SkRefCnt.cpp
@@ -1,12 +1,12 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
#include "SkRefCnt.h"
-DEFINE_INST_COUNT(SkRefCnt)
+SK_DEFINE_INST_COUNT(SkRefCnt)
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index 3eca36215a..a771532b41 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -9,7 +9,7 @@
#include "GrRefCnt.h"
#include "GrGpu.h"
-DEFINE_INST_COUNT(GrAARectRenderer)
+SK_DEFINE_INST_COUNT(GrAARectRenderer)
namespace {
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index 00f0b81d85..648225e567 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -13,6 +13,8 @@
#include "GrDefaultPathRenderer.h"
#include "GrGpu.h"
+SK_DEFINE_INST_COUNT(GrPathRendererChain)
+
GrPathRendererChain::GrPathRendererChain(GrContext* context, UsageFlags flags)
: fInit(false)
, fOwner(context)
diff --git a/src/gpu/GrPathRendererChain.h b/src/gpu/GrPathRendererChain.h
index 529b4cb751..e5ccabb95d 100644
--- a/src/gpu/GrPathRendererChain.h
+++ b/src/gpu/GrPathRendererChain.h
@@ -27,6 +27,7 @@ class GrPathRenderer;
*/
class GrPathRendererChain : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(GrPathRendererChain)
enum UsageFlags {
kNone_UsageFlag = 0,
@@ -58,6 +59,8 @@ private:
GrContext* fOwner;
UsageFlags fFlags;
SkSTArray<kPreAllocCount, GrPathRenderer*, true> fChain;
+
+ typedef SkRefCnt INHERITED;
};
GR_MAKE_BITFIELD_OPS(GrPathRendererChain::UsageFlags)
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index be0844460e..071c885caf 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -13,6 +13,8 @@
#include "GrGpu.h"
#include "GrStencilBuffer.h"
+SK_DEFINE_INST_COUNT(GrRenderTarget)
+
bool GrRenderTarget::readPixels(int left, int top, int width, int height,
GrPixelConfig config, void* buffer,
size_t rowBytes) {
diff --git a/src/gpu/GrResource.cpp b/src/gpu/GrResource.cpp
index a5168c8473..7e2d4a8bb5 100644
--- a/src/gpu/GrResource.cpp
+++ b/src/gpu/GrResource.cpp
@@ -10,7 +10,7 @@
#include "GrResource.h"
#include "GrGpu.h"
-DEFINE_INST_COUNT(GrResource)
+SK_DEFINE_INST_COUNT(GrResource)
GrResource::GrResource(GrGpu* gpu) {
fGpu = gpu;
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 4f4c5f5850..67ce62913e 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -14,6 +14,8 @@
#include "GrRenderTarget.h"
#include "GrResourceCache.h"
+SK_DEFINE_INST_COUNT(GrTexture)
+
bool GrTexture::readPixels(int left, int top, int width, int height,
GrPixelConfig config, void* buffer,
size_t rowBytes) {
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 5a0ede8253..b367318553 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -17,6 +17,8 @@
#define SNPRINTF snprintf
#endif
+SK_DEFINE_INST_COUNT(SkPDFObject)
+
SkPDFObject::SkPDFObject() {}
SkPDFObject::~SkPDFObject() {}
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index 6334938d77..d5fe4ae72c 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -27,6 +27,8 @@ class SkWStream;
*/
class SkPDFObject : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkPDFObject)
+
/** Create a PDF object.
*/
SkPDFObject();
@@ -91,6 +93,8 @@ protected:
*/
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) = 0;
+
+ typedef SkRefCnt INHERITED;
};
/** \class SkPDFObjRef