aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/core/SkInstCnt.h51
-rw-r--r--include/core/SkRefCnt.h3
-rw-r--r--include/gpu/GrResource.h2
3 files changed, 56 insertions, 0 deletions
diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h
new file mode 100644
index 0000000000..889c098d77
--- /dev/null
+++ b/include/core/SkInstCnt.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkInstCnt_DEFINED
+#define SkInstCnt_DEFINED
+
+/*
+ * 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
+ */
+#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; \
+ }
+
+#define DEFINE_INST_COUNT(className) \
+ int32_t className::SkInstanceCountHelper::gInstanceCount = 0;
+
+#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)
+#endif
+
+#endif // SkInstCnt_DEFINED
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index b847596052..761546b12b 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -11,6 +11,7 @@
#define SkRefCnt_DEFINED
#include "SkThread.h"
+#include "SkInstCnt.h"
/** \class SkRefCnt
@@ -24,6 +25,8 @@
*/
class SK_API SkRefCnt : SkNoncopyable {
public:
+ DECLARE_INST_COUNT
+
/** Default construct, initializing the reference count to 1.
*/
SkRefCnt() : fRefCnt(1) {}
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h
index 8008f29e34..4c491c7369 100644
--- a/include/gpu/GrResource.h
+++ b/include/gpu/GrResource.h
@@ -20,6 +20,8 @@ class GrContext;
*/
class GrResource : public GrRefCnt {
public:
+ DECLARE_INST_COUNT
+
/**
* Frees the resource in the underlying 3D API. It must be safe to call this
* when the resource has been previously abandoned.