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;
}
/*
* 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
*/
class SK_API SkRefCnt : SkNoncopyable {
public:
- DECLARE_INST_COUNT
+ SK_DECLARE_INST_COUNT_ROOT(SkRefCnt)
/** Default construct, initializing the reference count to 1.
*/
friend class SkWeakRefCnt;
mutable int32_t fRefCnt;
+
+ typedef SkNoncopyable INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
*/
class GrAARectRenderer : public GrRefCnt {
public:
- DECLARE_INST_COUNT
+ SK_DECLARE_INST_COUNT(GrAARectRenderer)
GrAARectRenderer()
: fAAFillRectIndexBuffer(NULL)
static int aaStrokeRectIndexCount();
GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu);
+
+ typedef GrRefCnt INHERITED;
};
#endif // GrAARectRenderer_DEFINED
*/
class GrRenderTarget : public GrResource {
public:
+ SK_DECLARE_INST_COUNT(GrRenderTarget)
/**
* @return the width of the rendertarget
*/
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
class GrTexture : public GrResource {
public:
+ SK_DECLARE_INST_COUNT(GrTexture)
+
/**
* Retrieves the width of the texture.
*
#include "SkFlattenable.h"
#include <new>
+SK_DEFINE_INST_COUNT(SkPathHeap)
+
#define kPathCount 64
SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
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.
SkChunkAlloc fHeap;
// we just store ptrs into fHeap here
SkTDArray<SkPath*> fPaths;
+
+ typedef SkRefCnt INHERITED;
};
#endif
-/*\r
- * Copyright 2012 Google Inc.\r
- *\r
- * Use of this source code is governed by a BSD-style license that can be\r
- * found in the LICENSE file.\r
+/*
+ * 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)
#include "GrRefCnt.h"
#include "GrGpu.h"
-DEFINE_INST_COUNT(GrAARectRenderer)
+SK_DEFINE_INST_COUNT(GrAARectRenderer)
namespace {
#include "GrDefaultPathRenderer.h"
#include "GrGpu.h"
+SK_DEFINE_INST_COUNT(GrPathRendererChain)
+
GrPathRendererChain::GrPathRendererChain(GrContext* context, UsageFlags flags)
: fInit(false)
, fOwner(context)
*/
class GrPathRendererChain : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(GrPathRendererChain)
enum UsageFlags {
kNone_UsageFlag = 0,
GrContext* fOwner;
UsageFlags fFlags;
SkSTArray<kPreAllocCount, GrPathRenderer*, true> fChain;
+
+ typedef SkRefCnt INHERITED;
};
GR_MAKE_BITFIELD_OPS(GrPathRendererChain::UsageFlags)
#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) {
#include "GrResource.h"
#include "GrGpu.h"
-DEFINE_INST_COUNT(GrResource)
+SK_DEFINE_INST_COUNT(GrResource)
GrResource::GrResource(GrGpu* gpu) {
fGpu = gpu;
#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) {
#define SNPRINTF snprintf
#endif
+SK_DEFINE_INST_COUNT(SkPDFObject)
+
SkPDFObject::SkPDFObject() {}
SkPDFObject::~SkPDFObject() {}
*/
class SkPDFObject : public SkRefCnt {
public:
+ SK_DECLARE_INST_COUNT(SkPDFObject)
+
/** Create a PDF object.
*/
SkPDFObject();
*/
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) = 0;
+
+ typedef SkRefCnt INHERITED;
};
/** \class SkPDFObjRef