Bug 795186 - Declare refptrs between WebGL objects to the CC even if there is no cycle at C++ level - r=opettay
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 22 Oct 2012 17:17:42 -0400
changeset 111083 48502b61a63e9c17df6914429101cf8a6b2253cf
parent 111082 c4aecf0cb060ed245ff88447fd8d181109c82cf7
child 111084 a1170e62ccd519d89585fd1e50bb50145a302f84
push id16862
push userbjacob@mozilla.com
push dateMon, 22 Oct 2012 21:18:10 +0000
treeherdermozilla-inbound@48502b61a63e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersopettay
bugs795186
milestone19.0a1
first release with
nightly linux32
48502b61a63e / 19.0a1 / 20121023030553 / files
nightly linux64
48502b61a63e / 19.0a1 / 20121023030553 / files
nightly mac
48502b61a63e / 19.0a1 / 20121023030553 / files
nightly win32
48502b61a63e / 19.0a1 / 20121023030553 / files
nightly win64
48502b61a63e / 19.0a1 / 20121023030553 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 795186 - Declare refptrs between WebGL objects to the CC even if there is no cycle at C++ level - r=opettay
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLFramebuffer.cpp
content/canvas/src/WebGLProgram.cpp
content/canvas/src/WebGLUniformLocation.cpp
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -1368,30 +1368,43 @@ WebGLContext::GetSupportedExtensions(JSC
 //
 // XPCOM goop
 //
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLContext)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLContext)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLContext)
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(WebGLContext)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
+NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(WebGLContext)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLContext)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCanvasElement)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mExtensions)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mBound2DTextures)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mBoundCubeMapTextures)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBoundArrayBuffer)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBoundElementArrayBuffer)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentProgram)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBoundFramebuffer)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBoundRenderbuffer)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mAttribBuffers)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WebGLContext)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCanvasElement, nsINode)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mExtensions)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mBound2DTextures)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mBoundCubeMapTextures)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBoundArrayBuffer)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBoundElementArrayBuffer)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentProgram)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBoundFramebuffer)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBoundRenderbuffer)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mAttribBuffers)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLContext)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIDOMWebGLRenderingContext)
   NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -1517,16 +1517,21 @@ struct WebGLVertexAttribData {
                 return 0;
         }
     }
 
     GLuint actualStride() const {
         if (stride) return stride;
         return size * componentSize();
     }
+
+    // for cycle collection
+    WebGLBuffer* get() {
+        return buf.get();
+    }
 };
 
 class WebGLBuffer MOZ_FINAL
     : public nsISupports
     , public WebGLRefCountedObject<WebGLBuffer>
     , public LinkedListElement<WebGLBuffer>
     , public WebGLContextBoundObject
     , public nsWrapperCache
@@ -2638,16 +2643,18 @@ class WebGLFramebufferAttachment
 {
     // deleting a texture or renderbuffer immediately detaches it
     WebGLRefPtr<WebGLTexture> mTexturePtr;
     WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
     WebGLenum mAttachmentPoint;
     WebGLint mTextureLevel;
     WebGLenum mTextureCubeMapFace;
 
+    friend class WebGLFramebuffer;
+
 public:
     WebGLFramebufferAttachment(WebGLenum aAttachmentPoint)
         : mAttachmentPoint(aAttachmentPoint)
     {}
 
     bool IsDefined() const {
         return Texture() || Renderbuffer();
     }
@@ -3100,17 +3107,19 @@ public:
 
     WebGLProgram *Program() const { return mProgram; }
     GLint Location() const { return mLocation; }
     uint32_t ProgramGeneration() const { return mProgramGeneration; }
     int ElementSize() const { return mElementSize; }
 
     virtual JSObject* WrapObject(JSContext *cx, JSObject *scope);
 
-    NS_DECL_ISUPPORTS
+    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+    NS_DECL_CYCLE_COLLECTION_CLASS(WebGLUniformLocation)
+
 protected:
     // nsRefPtr, not WebGLRefPtr, so that we don't prevent the program from being explicitly deleted.
     // we just want to avoid having a dangling pointer.
     nsRefPtr<WebGLProgram> mProgram;
 
     uint32_t mProgramGeneration;
     GLint mLocation;
     WebGLUniformInfo mInfo;
--- a/content/canvas/src/WebGLFramebuffer.cpp
+++ b/content/canvas/src/WebGLFramebuffer.cpp
@@ -7,18 +7,42 @@
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 
 using namespace mozilla;
 
 JSObject*
 WebGLFramebuffer::WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap) {
     return dom::WebGLFramebufferBinding::Wrap(cx, scope, this, triedToWrap);
 }
+NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLFramebuffer)
+NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(WebGLFramebuffer)
 
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLFramebuffer)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLFramebuffer)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mColorAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mColorAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDepthAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDepthAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mStencilAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mStencilAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDepthStencilAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDepthStencilAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WebGLFramebuffer)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mColorAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mColorAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDepthAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDepthAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStencilAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStencilAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDepthStencilAttachment.mTexturePtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDepthStencilAttachment.mRenderbufferPtr)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLFramebuffer)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLFramebuffer)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLFramebuffer)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
--- a/content/canvas/src/WebGLProgram.cpp
+++ b/content/canvas/src/WebGLProgram.cpp
@@ -8,17 +8,28 @@
 
 using namespace mozilla;
 
 JSObject*
 WebGLProgram::WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap) {
     return dom::WebGLProgramBinding::Wrap(cx, scope, this, triedToWrap);
 }
 
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLProgram)
+NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLProgram)
+NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(WebGLProgram)
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLProgram)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mAttachedShaders)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WebGLProgram)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mAttachedShaders)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLProgram)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLProgram)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLProgram)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
--- a/content/canvas/src/WebGLUniformLocation.cpp
+++ b/content/canvas/src/WebGLUniformLocation.cpp
@@ -3,20 +3,30 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 
 using namespace mozilla;
 
-NS_IMPL_ADDREF(WebGLUniformLocation)
-NS_IMPL_RELEASE(WebGLUniformLocation)
-
-NS_INTERFACE_MAP_BEGIN(WebGLUniformLocation)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
 JSObject*
 WebGLUniformLocation::WrapObject(JSContext *cx, JSObject *scope)
 {
     return dom::WebGLUniformLocationBinding::Wrap(cx, scope, this);
 }
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLUniformLocation)
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLUniformLocation)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProgram)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WebGLUniformLocation)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mProgram)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLUniformLocation)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLUniformLocation)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLUniformLocation)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END