Expanded distribution of instance counting

http://codereview.appspot.com/6300114/



git-svn-id: http://skia.googlecode.com/svn/trunk@4291 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkAdvancedTypefaceMetrics.h b/include/core/SkAdvancedTypefaceMetrics.h
index 5ffdb45..d326379 100755
--- a/include/core/SkAdvancedTypefaceMetrics.h
+++ b/include/core/SkAdvancedTypefaceMetrics.h
@@ -26,6 +26,8 @@
 
 class SkAdvancedTypefaceMetrics : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkAdvancedTypefaceMetrics)
+
     SkString fFontName;
 
     enum FontType {
@@ -112,6 +114,9 @@
     // The mapping from glyph to Unicode, only populated if
     // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics.
     SkTDArray<SkUnichar> fGlyphToUnicode;
+
+private:
+    typedef SkRefCnt INHERITED;
 };
 
 namespace skia_advanced_typeface_metrics_utils {
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 514357f..8515b46 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -558,6 +558,8 @@
 
     class Allocator : public SkRefCnt {
     public:
+        SK_DECLARE_INST_COUNT(Allocator)
+
         /** Allocate the pixel memory for the bitmap, given its dimensions and
             config. Return true on success, where success means either setPixels
             or setPixelRef was called. The pixels need not be locked when this
@@ -566,6 +568,8 @@
             colortable should be left unchanged.
         */
         virtual bool allocPixelRef(SkBitmap*, SkColorTable*) = 0;
+    private:
+        typedef SkRefCnt INHERITED;
     };
 
     /** Subclass of Allocator that returns a pixelref that allocates its pixel
diff --git a/include/core/SkBounder.h b/include/core/SkBounder.h
index 5bac358..08cef2d 100644
--- a/include/core/SkBounder.h
+++ b/include/core/SkBounder.h
@@ -84,6 +84,8 @@
     friend class SkDrawIter;
     friend struct Draw1Glyph;
     friend class SkMaskFilter;
+
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index d942783..fc95f9a 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -44,6 +44,8 @@
 */
 class SK_API SkCanvas : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkCanvas)
+
     SkCanvas();
 
     /** Construct a canvas with the specified device to draw into.
@@ -1058,6 +1060,8 @@
 #else
     void validateClip() const {}
 #endif
+
+    typedef SkRefCnt INHERITED;
 };
 
 /** Stack helper class to automatically call restoreToCount() on the canvas
diff --git a/include/core/SkData.h b/include/core/SkData.h
index 76b4457..8bbe3c8 100644
--- a/include/core/SkData.h
+++ b/include/core/SkData.h
@@ -20,6 +20,8 @@
  */
 class SkData : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkData)
+
     /**
      *  Returns the number of bytes stored.
      */
@@ -91,6 +93,8 @@
 
     SkData(const void* ptr, size_t size, ReleaseProc, void* context);
     ~SkData();
+
+    typedef SkRefCnt INHERITED;
 };
 
 /**
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index b4d44bf..688ce8e 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -27,6 +27,8 @@
 
 class SK_API SkDevice : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkDevice)
+
     /**
      *  Construct a new device with the specified bitmap as its backend. It is
      *  valid for the bitmap to have no pixels associated with it. In that case,
@@ -387,6 +389,8 @@
     SkBitmap    fBitmap;
     SkIPoint    fOrigin;
     SkMetaData* fMetaData;
+
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/core/SkDeviceProfile.h b/include/core/SkDeviceProfile.h
index 46b9781..49214c5 100644
--- a/include/core/SkDeviceProfile.h
+++ b/include/core/SkDeviceProfile.h
@@ -12,6 +12,8 @@
 
 class SkDeviceProfile : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkDeviceProfile)
+
     enum LCDConfig {
         kNone_LCDConfig,   // disables LCD text rendering, uses A8 instead
         kRGB_Horizontal_LCDConfig,
@@ -89,6 +91,8 @@
     float           fContrastScale;
     LCDConfig       fLCDConfig;
     FontHintLevel   fFontHintLevel;
+
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/core/SkDrawFilter.h b/include/core/SkDrawFilter.h
index 303b80e..39b1717 100644
--- a/include/core/SkDrawFilter.h
+++ b/include/core/SkDrawFilter.h
@@ -38,6 +38,9 @@
      *  The implementation may modify the paint as they wish.
      */
     virtual void filter(SkPaint*, Type) = 0;
+
+private:
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 5701967..e6c56a3 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -68,6 +68,8 @@
  */
 class SK_API SkFlattenable : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkFlattenable)
+
     typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&);
     
     SkFlattenable() {}
@@ -104,6 +106,8 @@
 
     friend class SkGraphics;
     friend class SkFlattenableWriteBuffer;
+
+    typedef SkRefCnt INHERITED;
 };
 
 // helpers for matrix and region
diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h
index e5c44db..087d5a7 100644
--- a/include/core/SkInstCnt.h
+++ b/include/core/SkInstCnt.h
@@ -31,7 +31,7 @@
 #define SK_DECLARE_INST_COUNT_INTERNAL(className, initStep)                 \
     class SkInstanceCountHelper {                                           \
     public:                                                                 \
-        typedef void (*PFCheckInstCnt)();                                   \
+        typedef void (*PFCheckInstCnt)(int level);                          \
         SkInstanceCountHelper() {                                           \
             if (!gInited) {                                                 \
                 initStep                                                    \
@@ -57,13 +57,14 @@
         return SkInstanceCountHelper::gInstanceCount;                       \
     }                                                                       \
                                                                             \
-    static void CheckInstanceCount() {                                      \
+    static void CheckInstanceCount(int level = 0) {                         \
         if (0 != SkInstanceCountHelper::gInstanceCount) {                   \
-            SkDebugf("Leaked %s objects: %d\n", #className,                 \
+            SkDebugf("%*c Leaked %s objects: %d\n",                         \
+                     4*level, ' ', #className,                              \
                      SkInstanceCountHelper::gInstanceCount);                \
         }                                                                   \
-        for (int i = 0; i < SkInstanceCountHelper::gChildren.count(); ++i) { \
-            (*SkInstanceCountHelper::gChildren[i])();                       \
+        for (int i = 0; i < SkInstanceCountHelper::gChildren.count(); ++i) {\
+            (*SkInstanceCountHelper::gChildren[i])(level+1);                \
         }                                                                   \
     }                                                                       \
                                                                             \
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 21a4fcc..51ed0d7 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -26,6 +26,8 @@
 */
 class SK_API SkPicture : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkPicture)
+
     /** The constructor prepares the picture to record.
         @param width the width of the virtual device the picture records.
         @param height the height of the virtual device the picture records.
@@ -130,6 +132,8 @@
 
     friend class SkFlatPicture;
     friend class SkPicturePlayback;
+
+    typedef SkRefCnt INHERITED;
 };
 
 class SkAutoPictureRecord : SkNoncopyable {
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h
index 2df84b2..360471f 100644
--- a/include/core/SkPtrRecorder.h
+++ b/include/core/SkPtrRecorder.h
@@ -21,6 +21,8 @@
  */
 class SkPtrSet : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkPtrSet)
+
     /**
      *  Search for the specified ptr in the set. If it is found, return its
      *  32bit ID [1..N], or if not found, return 0. Always returns 0 for NULL.
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index 67512d7..58f5443 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -17,6 +17,8 @@
 
 class SK_API SkStream : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkStream)
+
     virtual ~SkStream();
     /** Called to rewind to the beginning of the stream. If this cannot be
         done, return false.
@@ -63,6 +65,9 @@
     bool     readBool() { return this->readU8() != 0; }
     SkScalar readScalar();
     size_t   readPackedUInt();
+
+private:
+    typedef SkRefCnt INHERITED;
 };
 
 class SK_API SkWStream : SkNoncopyable {
diff --git a/include/core/SkWeakRefCnt.h b/include/core/SkWeakRefCnt.h
index 50760e2..a407623 100644
--- a/include/core/SkWeakRefCnt.h
+++ b/include/core/SkWeakRefCnt.h
@@ -150,6 +150,8 @@
 
     /* Invariant: fWeakCnt = #weak + (fRefCnt > 0 ? 1 : 0) */
     mutable int32_t fWeakCnt;
+
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/gpu/GrCustomStage.h b/include/gpu/GrCustomStage.h
index 5eea9f4..1c2cc9f 100644
--- a/include/gpu/GrCustomStage.h
+++ b/include/gpu/GrCustomStage.h
@@ -22,6 +22,8 @@
 class GrCustomStage : public GrRefCnt {
 
 public:
+    SK_DECLARE_INST_COUNT(GrCustomStage)
+
     typedef GrProgramStageFactory::StageKey StageKey;
 
     GrCustomStage();
diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h
index 1827dc2..c627b90 100644
--- a/include/gpu/gl/GrGLInterface.h
+++ b/include/gpu/gl/GrGLInterface.h
@@ -119,7 +119,11 @@
         FNPTR_TYPE fPtr;
     };
 
+    typedef GrRefCnt INHERITED;
+
 public:
+    SK_DECLARE_INST_COUNT(GrGLInterface)
+
     GrGLInterface();
 
     // Validates that the GrGLInterface supports a binding. This means that
diff --git a/include/gpu/gl/SkGLContext.h b/include/gpu/gl/SkGLContext.h
index e2ac7e0..b8b6b6e 100644
--- a/include/gpu/gl/SkGLContext.h
+++ b/include/gpu/gl/SkGLContext.h
@@ -18,6 +18,8 @@
 
 class SkGLContext : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkGLContext)
+
     SkGLContext();
     virtual ~SkGLContext();
 
@@ -54,6 +56,8 @@
     GrGLuint fColorBufferID;
     GrGLuint fDepthStencilBufferID;
     const GrGLInterface* fGL;
+
+    typedef SkRefCnt INHERITED;
 };
 
 /**
diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h
index d0c4d21..a8ec1c6 100644
--- a/include/images/SkImageDecoder.h
+++ b/include/images/SkImageDecoder.h
@@ -56,10 +56,14 @@
     */
     class Peeker : public SkRefCnt {
     public:
+        SK_DECLARE_INST_COUNT(Peeker)
+
         /** Return true to continue decoding, or false to indicate an error, which
             will cause the decoder to not return the image.
         */
         virtual bool peek(const char tag[], const void* data, size_t length) = 0;
+    private:
+        typedef SkRefCnt INHERITED;
     };
 
     Peeker* getPeeker() const { return fPeeker; }
@@ -72,11 +76,16 @@
     */
     class Chooser : public SkRefCnt {
     public:
+        SK_DECLARE_INST_COUNT(Chooser)
+
         virtual void begin(int count) {}
         virtual void inspect(int index, SkBitmap::Config config, int width, int height) {}
         /** Return the index of the subimage you want, or -1 to choose none of them.
         */
         virtual int choose() = 0;
+
+    private:
+        typedef SkRefCnt INHERITED;
     };
 
     Chooser* getChooser() const { return fChooser; }
@@ -321,7 +330,12 @@
  */
 class SkImageDecoderFactory : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkImageDecoderFactory)
+
     virtual SkImageDecoder* newDecoder(SkStream*) = 0;
+
+private:
+    typedef SkRefCnt INHERITED;
 };
 
 class SkDefaultImageDecoderFactory : SkImageDecoderFactory {
diff --git a/include/images/SkMovie.h b/include/images/SkMovie.h
index f52a786..cecad29 100644
--- a/include/images/SkMovie.h
+++ b/include/images/SkMovie.h
@@ -17,6 +17,8 @@
 
 class SkMovie : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkMovie)
+
     /** Try to create a movie from the stream. If the stream format is not
         supported, return NULL.
     */
@@ -71,6 +73,8 @@
     bool        fNeedBitmap;
     
     void ensureInfo();
+
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/text/SkTextLayout.h b/include/text/SkTextLayout.h
index e1e3e56..3b12334 100644
--- a/include/text/SkTextLayout.h
+++ b/include/text/SkTextLayout.h
@@ -13,6 +13,8 @@
 
 class SkTextStyle : public SkRefCnt {
 public:
+    SK_DECLARE_INST_COUNT(SkTextStyle)
+
     SkTextStyle();
     SkTextStyle(const SkTextStyle&);
     explicit SkTextStyle(const SkPaint&);
@@ -25,6 +27,8 @@
 
 private:
     SkPaint fPaint;
+
+    typedef SkRefCnt INHERITED;
 };
 
 class SkTextLayout {