Bug 1288643 - Delete on Detach. - r=jerry draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 21 Jul 2016 23:38:31 -0700
changeset 391215 36673ebb956b1e54d5ddac6b650fe81a34863315
parent 391214 2daec738be0ec28df1503a2b637606f9ebb76dcd
child 391216 17a88ce695956d75c290afa35f6e30c37fbfd491
push id23845
push userbmo:jgilbert@mozilla.com
push dateFri, 22 Jul 2016 08:40:49 +0000
reviewersjerry
bugs1288643
milestone50.0a1
Bug 1288643 - Delete on Detach. - r=jerry MozReview-Commit-ID: 7nI0SYFqf1
dom/canvas/WebGLBuffer.cpp
dom/canvas/WebGLFramebuffer.h
dom/canvas/WebGLObjectModel.h
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLQuery.h
dom/canvas/WebGLRenderbuffer.h
dom/canvas/WebGLSampler.cpp
dom/canvas/WebGLShader.cpp
dom/canvas/WebGLShaderPrecisionFormat.h
dom/canvas/WebGLSync.cpp
dom/canvas/WebGLTexture.h
dom/canvas/WebGLTimerQuery.cpp
dom/canvas/WebGLTransformFeedback.cpp
dom/canvas/WebGLUniformLocation.h
dom/canvas/WebGLVertexArrayFake.h
dom/canvas/WebGLVertexArrayGL.cpp
dom/canvas/WebGLVertexArrayObject.h
--- a/dom/canvas/WebGLBuffer.cpp
+++ b/dom/canvas/WebGLBuffer.cpp
@@ -18,17 +18,17 @@ WebGLBuffer::WebGLBuffer(WebGLContext* w
     , mContent(Kind::Undefined)
     , mByteLength(0)
 {
     mContext->mBuffers.insertBack(this);
 }
 
 WebGLBuffer::~WebGLBuffer()
 {
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLBuffer::BindTo(GLenum target)
 {
     switch (target) {
     case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
         mContent = Kind::ElementArray;
--- a/dom/canvas/WebGLFramebuffer.h
+++ b/dom/canvas/WebGLFramebuffer.h
@@ -205,17 +205,17 @@ private:
     bool mIsFB;
 #endif
 
 public:
     WebGLFramebuffer(WebGLContext* webgl, GLuint fbo);
 
 private:
     ~WebGLFramebuffer() {
-        DeleteOnce();
+        DetachOnce();
     }
 
     const WebGLRectangleObject& GetAnyRectObject() const;
 
 public:
     void Delete();
 
     void FramebufferRenderbuffer(GLenum attachment, RBTarget rbtarget,
--- a/dom/canvas/WebGLObjectModel.h
+++ b/dom/canvas/WebGLObjectModel.h
@@ -148,16 +148,20 @@ private:
     void MaybeDelete() {
         if (mWebGLRefCnt == 0 &&
             mDeletionStatus == DeleteRequested)
         {
             DeleteOnce();
         }
     }
 
+    virtual void DetachImpl() override {
+        DeleteOnce();
+    }
+
 protected:
     nsAutoRefCnt mWebGLRefCnt;
     DeletionStatus mDeletionStatus;
 };
 
 /* This WebGLRefPtr class is meant to be used for references between WebGL
  * objects. For example, a WebGLProgram holds WebGLRefPtr's to the WebGLShader's
  * attached to it.
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -434,17 +434,17 @@ WebGLProgram::WebGLProgram(WebGLContext*
     , mGLName(CreateProgram(webgl->GL()))
     , mTransformFeedbackBufferMode(LOCAL_GL_NONE)
 {
     mContext->mPrograms.insertBack(this);
 }
 
 WebGLProgram::~WebGLProgram()
 {
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLProgram::Delete()
 {
     gl::GLContext* gl = mContext->GL();
 
     gl->MakeCurrent();
--- a/dom/canvas/WebGLQuery.h
+++ b/dom/canvas/WebGLQuery.h
@@ -56,17 +56,17 @@ public:
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLQuery)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLQuery)
 
     // Track whether the event loop has spun
     bool mCanBeAvailable;
 
 private:
     ~WebGLQuery() {
-        DeleteOnce();
+        DetachOnce();
     };
 
     GLuint mGLName;
     GLenum mType;
 
     friend class WebGL2Context;
 };
 
--- a/dom/canvas/WebGLRenderbuffer.h
+++ b/dom/canvas/WebGLRenderbuffer.h
@@ -77,17 +77,17 @@ public:
                              GLenum internalFormat, uint32_t width, uint32_t height);
     // Only handles a subset of `pname`s.
     GLint GetRenderbufferParameter(RBTarget target, RBParam pname) const;
 
     virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
 protected:
     ~WebGLRenderbuffer() {
-        DeleteOnce();
+        DetachOnce();
     }
 
     void DoFramebufferRenderbuffer(GLenum attachment) const;
     GLenum DoRenderbufferStorage(uint32_t samples, const webgl::FormatUsageInfo* format,
                                  uint32_t width, uint32_t height);
 };
 
 } // namespace mozilla
--- a/dom/canvas/WebGLSampler.cpp
+++ b/dom/canvas/WebGLSampler.cpp
@@ -24,17 +24,17 @@ WebGLSampler::WebGLSampler(WebGLContext*
     , mCompareMode(LOCAL_GL_NONE)
     , mCompareFunc(LOCAL_GL_LEQUAL)
 {
     mContext->mSamplers.insertBack(this);
 }
 
 WebGLSampler::~WebGLSampler()
 {
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLSampler::Delete()
 {
     mContext->MakeContextCurrent();
     mContext->gl->fDeleteSamplers(1, &mGLName);
 
--- a/dom/canvas/WebGLShader.cpp
+++ b/dom/canvas/WebGLShader.cpp
@@ -147,17 +147,17 @@ WebGLShader::WebGLShader(WebGLContext* w
     , mTranslationSuccessful(false)
     , mCompilationSuccessful(false)
 {
     mContext->mShaders.insertBack(this);
 }
 
 WebGLShader::~WebGLShader()
 {
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLShader::ShaderSource(const nsAString& source)
 {
     StripComments stripComments(source);
     const nsAString& cleanSource = Substring(stripComments.result().Elements(),
                                              stripComments.length());
--- a/dom/canvas/WebGLShaderPrecisionFormat.h
+++ b/dom/canvas/WebGLShaderPrecisionFormat.h
@@ -38,16 +38,18 @@ public:
     }
 
     NS_INLINE_DECL_REFCOUNTING(WebGLShaderPrecisionFormat)
 
 private:
     // Private destructor, to discourage deletion outside of Release():
     ~WebGLShaderPrecisionFormat() { }
 
+    virtual void DetachImpl() override { }
+
     GLint mRangeMin;
     GLint mRangeMax;
     GLint mPrecision;
 };
 
 } // namespace mozilla
 
 #endif // WEBGL_SHADER_PRECISION_FORMAT_H_
--- a/dom/canvas/WebGLSync.cpp
+++ b/dom/canvas/WebGLSync.cpp
@@ -15,17 +15,17 @@ WebGLSync::WebGLSync(WebGLContext* webgl
     : WebGLContextBoundObject(webgl)
 {
    mContext->mSyncs.insertBack(this);
    mGLName = mContext->gl->fFenceSync(condition, flags);
 }
 
 WebGLSync::~WebGLSync()
 {
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLSync::Delete()
 {
     mContext->MakeContextCurrent();
     mContext->gl->fDeleteSync(mGLName);
     mGLName = 0;
--- a/dom/canvas/WebGLTexture.h
+++ b/dom/canvas/WebGLTexture.h
@@ -200,17 +200,17 @@ public:
     WebGLContext* GetParentObject() const {
         return mContext;
     }
 
     virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
 protected:
     ~WebGLTexture() {
-        DeleteOnce();
+        DetachOnce();
     }
 
 public:
     ////////////////////////////////////
     // GL calls
     bool BindTexture(TexTarget texTarget);
     void GenerateMipmap(TexTarget texTarget);
     JS::Value GetTexParameter(TexTarget texTarget, GLenum pname);
--- a/dom/canvas/WebGLTimerQuery.cpp
+++ b/dom/canvas/WebGLTimerQuery.cpp
@@ -26,17 +26,17 @@ WebGLTimerQuery::WebGLTimerQuery(WebGLCo
   , mTarget(LOCAL_GL_NONE)
   , mCanBeAvailable(false)
 {
   mContext->mTimerQueries.insertBack(this);
 }
 
 WebGLTimerQuery::~WebGLTimerQuery()
 {
-  DeleteOnce();
+  DetachOnce();
 }
 
 WebGLTimerQuery*
 WebGLTimerQuery::Create(WebGLContext* webgl)
 {
   GLuint name = 0;
   webgl->MakeContextCurrent();
   webgl->gl->fGenQueries(1, &name);
--- a/dom/canvas/WebGLTransformFeedback.cpp
+++ b/dom/canvas/WebGLTransformFeedback.cpp
@@ -22,17 +22,17 @@ WebGLTransformFeedback::WebGLTransformFe
     mContext->mTransformFeedbacks.insertBack(this);
 }
 
 WebGLTransformFeedback::~WebGLTransformFeedback()
 {
     mMode = LOCAL_GL_NONE;
     mIsActive = false;
     mIsPaused = false;
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLTransformFeedback::Delete()
 {
     mContext->MakeContextCurrent();
     mContext->gl->fDeleteTransformFeedbacks(1, &mGLName);
     removeFrom(mContext->mTransformFeedbacks);
--- a/dom/canvas/WebGLUniformLocation.h
+++ b/dom/canvas/WebGLUniformLocation.h
@@ -60,13 +60,16 @@ public:
     JS::Value GetUniform(JSContext* js) const;
 
     // Needed for certain helper functions like ValidateObject.
     // `WebGLUniformLocation`s can't be 'Deleted' in the WebGL sense.
     bool IsDeleted() const { return false; }
 
 protected:
     ~WebGLUniformLocation();
+
+private:
+    virtual void DetachImpl() override { }
 };
 
 } // namespace mozilla
 
 #endif // WEBGL_UNIFORM_LOCATION_H_
--- a/dom/canvas/WebGLVertexArrayFake.h
+++ b/dom/canvas/WebGLVertexArrayFake.h
@@ -20,17 +20,17 @@ protected:
     virtual void DeleteImpl() override;
     virtual void GenVertexArray() override {};
     virtual bool IsVertexArrayImpl() override;
 
 private:
     explicit WebGLVertexArrayFake(WebGLContext* webgl);
 
     ~WebGLVertexArrayFake() {
-        DeleteOnce();
+        DetachOnce();
     }
 
     bool mIsVAO;
 };
 
 } // namespace mozilla
 
 #endif // WEBGL_VERTEX_ARRAY_FAKE_H_
--- a/dom/canvas/WebGLVertexArrayGL.cpp
+++ b/dom/canvas/WebGLVertexArrayGL.cpp
@@ -12,17 +12,17 @@ namespace mozilla {
 
 WebGLVertexArrayGL::WebGLVertexArrayGL(WebGLContext* webgl)
     : WebGLVertexArray(webgl)
     , mIsVAO(false)
 { }
 
 WebGLVertexArrayGL::~WebGLVertexArrayGL()
 {
-    DeleteOnce();
+    DetachOnce();
 }
 
 void
 WebGLVertexArrayGL::DeleteImpl()
 {
     mElementArrayBuffer = nullptr;
 
     mContext->MakeContextCurrent();
--- a/dom/canvas/WebGLVertexArrayObject.h
+++ b/dom/canvas/WebGLVertexArrayObject.h
@@ -27,16 +27,16 @@ public:
   virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
 private:
   explicit WebGLVertexArrayObject(WebGLContext* webgl)
     : WebGLVertexArrayGL(webgl)
   { }
 
   ~WebGLVertexArrayObject() {
-    DeleteOnce();
+    DetachOnce();
   }
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // !mozilla_dom_WebGLVertexArrayObject_h