From ddfb4b19264f91ae9f7daad17f265ac6225d2f70 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 4 Dec 2011 14:15:43 -0500 Subject: [PATCH] Bug 705904 - [5/6] - Kill nsRefPtrHashtables of WebGL objects, allow unreferenced objects to be freed, fix about:memory reporting of deleted objects - r=jgilbert This patch takes care of WebGLRenderbuffer. --- content/canvas/src/WebGLContext.cpp | 5 ++-- content/canvas/src/WebGLContext.h | 28 ++++++++------------- content/canvas/src/WebGLContextGL.cpp | 2 -- content/canvas/src/WebGLContextValidate.cpp | 1 - 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/content/canvas/src/WebGLContext.cpp b/content/canvas/src/WebGLContext.cpp index 16b2a959ebb..19486a96bc5 100644 --- a/content/canvas/src/WebGLContext.cpp +++ b/content/canvas/src/WebGLContext.cpp @@ -237,7 +237,6 @@ WebGLContext::WebGLContext() mShaderValidation = true; mMapFramebuffers.Init(); - mMapRenderbuffers.Init(); mBlackTexturesAreInitialized = false; mFakeBlackStatus = DoNotNeedFakeBlack; @@ -348,9 +347,9 @@ WebGLContext::DestroyResourcesAndContext() mTextures.Last()->DeleteOnce(); while (mBuffers.Length()) mBuffers.Last()->DeleteOnce(); - DeleteWebGLObjectsHashTable(mMapRenderbuffers); + while (mRenderbuffers.Length()) + mRenderbuffers.Last()->DeleteOnce(); DeleteWebGLObjectsHashTable(mMapFramebuffers); - DeleteWebGLObjectsHashTable(mMapShaders); while (mShaders.Length()) mShaders.Last()->DeleteOnce(); while (mPrograms.Length()) diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 58c403b036e..3093cd11610 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -829,7 +829,7 @@ protected: WebGLFastArray mPrograms; WebGLFastArray mShaders; nsRefPtrHashtable mMapFramebuffers; - nsRefPtrHashtable mMapRenderbuffers; + WebGLFastArray mRenderbuffers; // PixelStore parameters PRUint32 mPixelStorePackAlignment, mPixelStoreUnpackAlignment, mPixelStoreColorspaceConversion; @@ -1782,6 +1782,7 @@ public: mContext->MakeContextCurrent(); mContext->gl->fGenRenderbuffers(1, &mGLName); + mMonotonicHandle = mContext->mRenderbuffers.AppendElement(this); } ~WebGLRenderbuffer() { @@ -1791,6 +1792,7 @@ public: void Delete() { mContext->MakeContextCurrent(); mContext->gl->fDeleteRenderbuffers(1, &mGLName); + mContext->mRenderbuffers.RemoveElement(mMonotonicHandle); } bool HasEverBeenBound() { return mHasEverBeenBound; } @@ -1837,7 +1839,7 @@ protected: WebGLuint mGLName; WebGLenum mInternalFormat; WebGLenum mInternalFormatForGL; - + WebGLMonotonicHandle mMonotonicHandle; bool mHasEverBeenBound; bool mInitialized; @@ -2521,30 +2523,20 @@ class WebGLMemoryReporter return result; } - static PLDHashOperator RenderbufferMemoryUsageFunction(const PRUint32&, WebGLRenderbuffer *aValue, void *aData) - { - PRInt64 *result = (PRInt64*) aData; - *result += aValue->MemoryUsage(); - return PL_DHASH_NEXT; - } - static PRInt64 GetRenderbufferMemoryUsed() { const ContextsArrayType & contexts = Contexts(); PRInt64 result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - PRInt64 bufferMemoryUsageForThisContext = 0; - contexts[i]->mMapRenderbuffers.EnumerateRead(RenderbufferMemoryUsageFunction, &bufferMemoryUsageForThisContext); - result += bufferMemoryUsageForThisContext; - } + for(size_t i = 0; i < contexts.Length(); ++i) + for (size_t r = 0; r < contexts[i]->mRenderbuffers.Length(); ++r) + result += contexts[i]->mRenderbuffers[r]->MemoryUsage(); return result; } - + static PRInt64 GetRenderbufferCount() { const ContextsArrayType & contexts = Contexts(); PRInt64 result = 0; - for(size_t i = 0; i < contexts.Length(); ++i) { - result += contexts[i]->mMapRenderbuffers.Count(); - } + for(size_t i = 0; i < contexts.Length(); ++i) + result += contexts[i]->mRenderbuffers.Length(); return result; } diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index 07b14283c06..059ececc204 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -1199,7 +1199,6 @@ WebGLContext::DeleteRenderbuffer(nsIWebGLRenderbuffer *rbobj) BindRenderbuffer(LOCAL_GL_RENDERBUFFER, nsnull); rbuf->RequestDelete(); - mMapRenderbuffers.Remove(rbufname); return NS_OK; } @@ -4324,7 +4323,6 @@ WebGLContext::CreateRenderbuffer(nsIWebGLRenderbuffer **retval) WebGLRenderbuffer *globj = new WebGLRenderbuffer(this); NS_ADDREF(*retval = globj); - mMapRenderbuffers.Put(globj->GLName(), globj); return NS_OK; } diff --git a/content/canvas/src/WebGLContextValidate.cpp b/content/canvas/src/WebGLContextValidate.cpp index e393448b199..f7a9efb51b9 100644 --- a/content/canvas/src/WebGLContextValidate.cpp +++ b/content/canvas/src/WebGLContextValidate.cpp @@ -526,7 +526,6 @@ WebGLContext::InitAndValidateGL() mBoundRenderbuffer = nsnull; mMapFramebuffers.Clear(); - mMapRenderbuffers.Clear(); MakeContextCurrent();