aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/gmmain.cpp5
-rw-r--r--gyp/common.gypi1
-rw-r--r--gyp/core.gyp1
-rw-r--r--include/config/SkUserConfig.h6
-rw-r--r--include/core/SkInstCnt.h8
-rw-r--r--src/core/SkInstCnt.cpp12
-rw-r--r--tests/GrMemoryPoolTest.cpp4
7 files changed, 34 insertions, 3 deletions
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index ca18e493bc..b34a4424e6 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -810,6 +810,11 @@ private:
}
int main(int argc, char * const argv[]) {
+
+#ifdef SK_ENABLE_INST_COUNT
+ gPrintInstCount = true;
+#endif
+
SkGraphics::Init();
// we don't need to see this during a run
gSkSuppressFontCachePurgeSpew = true;
diff --git a/gyp/common.gypi b/gyp/common.gypi
index a9b274da48..717e6ebbd8 100644
--- a/gyp/common.gypi
+++ b/gyp/common.gypi
@@ -68,6 +68,7 @@
'Debug': {
'defines': [
'SK_DEBUG',
+ 'SK_ENABLE_INST_COUNT',
'GR_DEBUG=1',
],
},
diff --git a/gyp/core.gyp b/gyp/core.gyp
index f50d64ab03..ab2e117ea2 100644
--- a/gyp/core.gyp
+++ b/gyp/core.gyp
@@ -79,6 +79,7 @@
'../src/core/SkGlyphCache.cpp',
'../src/core/SkGlyphCache.h',
'../src/core/SkGraphics.cpp',
+ '../src/core/SkInstCnt.cpp',
'../src/core/SkLineClipper.cpp',
'../src/core/SkMallocPixelRef.cpp',
'../src/core/SkMask.cpp',
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h
index e7f781d733..b180c89fa8 100644
--- a/include/config/SkUserConfig.h
+++ b/include/config/SkUserConfig.h
@@ -65,6 +65,12 @@
//#define SK_DEBUG
//#define SK_RELEASE
+/* To assist debugging, Skia provides an instance counting utility in
+ include/core/SkInstCount.h. This flag turns on and off that utility to
+ allow instance count tracking in either debug or release builds. By
+ default it is enabled in debug but disabled in release.
+ */
+//#define SK_ENABLE_INST_COUNT
/* If, in debugging mode, Skia needs to stop (presumably to invoke a debugger)
it will call SK_CRASH(). If this is not defined it, it is defined in
diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h
index ff9a19f252..18ea9bb75a 100644
--- a/include/core/SkInstCnt.h
+++ b/include/core/SkInstCnt.h
@@ -18,9 +18,11 @@
* At the end of an application a call to all the "root" objects'
* CheckInstanceCount methods should be made
*/
-#ifdef SK_DEBUG
+#ifdef SK_ENABLE_INST_COUNT
#include "SkTArray.h"
+extern bool gPrintInstCount;
+
#define SK_DECLARE_INST_COUNT(className) \
SK_DECLARE_INST_COUNT_INTERNAL(className, \
INHERITED::AddInstChild(CheckInstanceCount);)
@@ -58,7 +60,7 @@
} \
\
static int CheckInstanceCount(int level = 0) { \
- if (0 != SkInstanceCountHelper::gInstanceCount) { \
+ if (gPrintInstCount && 0 != SkInstanceCountHelper::gInstanceCount) {\
SkDebugf("%*c Leaked %s: %d\n", \
4*level, ' ', #className, \
SkInstanceCountHelper::gInstanceCount); \
@@ -69,7 +71,7 @@
count -= (*SkInstanceCountHelper::gChildren[i])(level+1); \
} \
SkASSERT(count >= 0); \
- if (childCount > 0 && count > 0) { \
+ if (gPrintInstCount && childCount > 0 && count > 0) { \
SkDebugf("%*c Leaked ???: %d\n", 4*(level + 1), ' ', count); \
} \
return SkInstanceCountHelper::gInstanceCount; \
diff --git a/src/core/SkInstCnt.cpp b/src/core/SkInstCnt.cpp
new file mode 100644
index 0000000000..d22639ee50
--- /dev/null
+++ b/src/core/SkInstCnt.cpp
@@ -0,0 +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.
+ */
+
+#include "SkInstCnt.h"
+
+#ifdef SK_ENABLE_INST_COUNT
+bool gPrintInstCount = false;
+#endif
diff --git a/tests/GrMemoryPoolTest.cpp b/tests/GrMemoryPoolTest.cpp
index f5527e9b35..0426944527 100644
--- a/tests/GrMemoryPoolTest.cpp
+++ b/tests/GrMemoryPoolTest.cpp
@@ -48,13 +48,17 @@ public:
static A* Create(SkRandom* r);
static void SetAllocator(size_t preallocSize, size_t minAllocSize) {
+#ifdef SK_ENABLE_INST_COUNT
SkASSERT(0 == GetInstanceCount());
+#endif
GrMemoryPool* pool = new GrMemoryPool(preallocSize, minAllocSize);
gPool.reset(pool);
}
static void ResetAllocator() {
+#ifdef SK_ENABLE_INST_COUNT
SkASSERT(0 == GetInstanceCount());
+#endif
gPool.reset(NULL);
}