Bug 978472 - Add support for leak checking in GenericRefCounted classes; r=bjacob

This commit is contained in:
Ehsan Akhgari 2014-03-09 14:40:49 -04:00
Родитель 8cd0c0f21d
Коммит 276e2d1e15
7 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -37,6 +37,11 @@ class GenericRefCountedBase
// mechanism, it is welcome to do so by overriding AddRef() and Release(). // mechanism, it is welcome to do so by overriding AddRef() and Release().
void ref() { AddRef(); } void ref() { AddRef(); }
void deref() { Release(); } void deref() { Release(); }
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
virtual const char* typeName() const = 0;
virtual size_t typeSize() const = 0;
#endif
}; };
namespace detail { namespace detail {
@ -55,11 +60,18 @@ class GenericRefCounted : public GenericRefCountedBase
virtual void AddRef() { virtual void AddRef() {
MOZ_ASSERT(int32_t(refCnt) >= 0); MOZ_ASSERT(int32_t(refCnt) >= 0);
++refCnt; ++refCnt;
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
detail::RefCountLogger::logAddRef(this, refCnt, typeName(), typeSize());
#endif
} }
virtual void Release() { virtual void Release() {
MOZ_ASSERT(int32_t(refCnt) > 0); MOZ_ASSERT(int32_t(refCnt) > 0);
if (0 == --refCnt) { --refCnt;
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
detail::RefCountLogger::logRelease(this, refCnt, typeName());
#endif
if (0 == refCnt) {
#ifdef DEBUG #ifdef DEBUG
refCnt = detail::DEAD; refCnt = detail::DEAD;
#endif #endif

Просмотреть файл

@ -27,6 +27,7 @@ class GLContextCGL : public GLContext
NSOpenGLContext *mContext; NSOpenGLContext *mContext;
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextCGL)
GLContextCGL(const SurfaceCaps& caps, GLContextCGL(const SurfaceCaps& caps,
GLContext *shareContext, GLContext *shareContext,
NSOpenGLContext *context, NSOpenGLContext *context,

Просмотреть файл

@ -29,6 +29,7 @@ class GLContextEGL : public GLContext
EGLSurface surface); EGLSurface surface);
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL)
GLContextEGL(const SurfaceCaps& caps, GLContextEGL(const SurfaceCaps& caps,
GLContext* shareContext, GLContext* shareContext,
bool isOffscreen, bool isOffscreen,

Просмотреть файл

@ -16,6 +16,7 @@ namespace gl {
class GLContextGLX : public GLContext class GLContextGLX : public GLContext
{ {
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextGLX)
static already_AddRefed<GLContextGLX> static already_AddRefed<GLContextGLX>
CreateGLContext(const SurfaceCaps& caps, CreateGLContext(const SurfaceCaps& caps,
GLContextGLX* shareContext, GLContextGLX* shareContext,

Просмотреть файл

@ -16,6 +16,7 @@ namespace gl {
class GLContextWGL : public GLContext class GLContextWGL : public GLContext
{ {
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextWGL)
// From Window: (possibly for offscreen!) // From Window: (possibly for offscreen!)
GLContextWGL(const SurfaceCaps& caps, GLContextWGL(const SurfaceCaps& caps,
GLContext* sharedContext, GLContext* sharedContext,

Просмотреть файл

@ -17,6 +17,7 @@ namespace gl {
class SkiaGLGlue : public GenericAtomicRefCounted class SkiaGLGlue : public GenericAtomicRefCounted
{ {
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SkiaGLGlue)
SkiaGLGlue(GLContext* context); SkiaGLGlue(GLContext* context);
GLContext* GetGLContext() const { return mGLContext.get(); } GLContext* GetGLContext() const { return mGLContext.get(); }
GrContext* GetGrContext() const { return mGrContext.get(); } GrContext* GetGrContext() const { return mGrContext.get(); }

Просмотреть файл

@ -28,6 +28,7 @@ class SurfaceFactory;
class SurfaceStream : public GenericAtomicRefCounted class SurfaceStream : public GenericAtomicRefCounted
{ {
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream)
typedef enum { typedef enum {
MainThread, MainThread,
OffMainThread OffMainThread
@ -145,6 +146,7 @@ protected:
SharedSurface* mConsumer; // Only present after resize-swap. SharedSurface* mConsumer; // Only present after resize-swap.
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_SingleBuffer)
SurfaceStream_SingleBuffer(SurfaceStream* prevStream); SurfaceStream_SingleBuffer(SurfaceStream* prevStream);
virtual ~SurfaceStream_SingleBuffer(); virtual ~SurfaceStream_SingleBuffer();
@ -169,6 +171,7 @@ protected:
SharedSurface* mConsumer; SharedSurface* mConsumer;
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer_Copy)
SurfaceStream_TripleBuffer_Copy(SurfaceStream* prevStream); SurfaceStream_TripleBuffer_Copy(SurfaceStream* prevStream);
virtual ~SurfaceStream_TripleBuffer_Copy(); virtual ~SurfaceStream_TripleBuffer_Copy();
@ -192,6 +195,7 @@ protected:
SurfaceStream_TripleBuffer(SurfaceStreamType type, SurfaceStream* prevStream); SurfaceStream_TripleBuffer(SurfaceStreamType type, SurfaceStream* prevStream);
public: public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SurfaceStream_TripleBuffer)
SurfaceStream_TripleBuffer(SurfaceStream* prevStream); SurfaceStream_TripleBuffer(SurfaceStream* prevStream);
virtual ~SurfaceStream_TripleBuffer(); virtual ~SurfaceStream_TripleBuffer();
virtual bool CopySurfaceToProducer(SharedSurface* src, SurfaceFactory* factory); virtual bool CopySurfaceToProducer(SharedSurface* src, SurfaceFactory* factory);