Bug 1320030 - Handle program and shader object deletion differently. - r=ethlin a=gchang
☠☠ backed out by 0da2d0158f98 ☠ ☠
authorJeff Gilbert <jdashg@gmail.com>
Wed, 30 Nov 2016 15:27:20 -0800
changeset 353002 ae0f7b513fa3c00ab62cfd3bbc01f5bc83a06104
parent 353001 e6d85e47e7bbeb7a9b7024c05a9ab420fe0c8388
child 353003 b810c31221c50838b2a8309030761a281b8bd838
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersethlin, gchang
bugs1320030
milestone52.0a2
Bug 1320030 - Handle program and shader object deletion differently. - r=ethlin a=gchang MozReview-Commit-ID: 4wSZ81lFP6e
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLObjectModel.h
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1632,31 +1632,57 @@ public:
                                   " generation of this one) passed as argument.",
                                   funcName);
             return false;
         }
 
         return true;
     }
 
-    bool ValidateObject(const char* funcName, const WebGLDeletableObject& object) {
+    bool ValidateObject(const char* funcName, const WebGLDeletableObject& object,
+                        bool isShaderOrProgram = false)
+    {
         if (!ValidateObjectAllowDeleted(funcName, object))
             return false;
 
-        if (object.IsDeleteRequested()) {
-            ErrorInvalidOperation("%s: Object argument cannot be marked for deletion.",
+        if (isShaderOrProgram) {
+            /* GLES 3.0.5 p45:
+             * "Commands that accept shader or program object names will generate the
+             *  error INVALID_VALUE if the provided name is not the name of either a
+             *  shader or program object[.]"
+             * Further, shaders and programs appear to be different from other objects,
+             * in that their lifetimes are better defined. However, they also appear to
+             * allow use of objects marked for deletion, and only reject
+             * actually-destroyed objects.
+             */
+            if (object.IsDeleted()) {
+                ErrorInvalidValue("%s: Shader or program object argument cannot have been"
+                                  " deleted.",
                                   funcName);
-            return false;
+                return false;
+            }
+        } else {
+            if (object.IsDeleteRequested()) {
+                ErrorInvalidOperation("%s: Object argument cannot have been marked for"
+                                      " deletion.",
+                                      funcName);
+                return false;
+            }
         }
 
         return true;
     }
 
     ////
 
+    bool ValidateObject(const char* funcName, const WebGLProgram& object);
+    bool ValidateObject(const char* funcName, const WebGLShader& object);
+
+    ////
+
     bool ValidateIsObject(const char* funcName,
                           const WebGLDeletableObject* object) const
     {
         if (IsContextLost())
             return false;
 
         if (!object)
             return false;
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -52,16 +52,28 @@
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 
 namespace mozilla {
 
+bool
+WebGLContext::ValidateObject(const char* funcName, const WebGLProgram& object)
+{
+    return ValidateObject(funcName, object, true);
+}
+
+bool
+WebGLContext::ValidateObject(const char* funcName, const WebGLShader& object)
+{
+    return ValidateObject(funcName, object, true);
+}
+
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 
 //
 //  WebGL API
 //
 
--- a/dom/canvas/WebGLObjectModel.h
+++ b/dom/canvas/WebGLObjectModel.h
@@ -44,17 +44,17 @@ private:
 
     DeletionStatus mDeletionStatus;
 
     ////
 
     explicit WebGLDeletableObject(WebGLContext* webgl)
       : WebGLContextBoundObject(webgl)
       , mDeletionStatus(Default)
-    {}
+    { }
 
     ~WebGLDeletableObject() {
         MOZ_ASSERT(mDeletionStatus == Deleted,
                    "Derived class destructor must call DeleteOnce().");
     }
 
 public:
     bool IsDeleted() const { return mDeletionStatus == Deleted; }
@@ -144,17 +144,17 @@ class WebGLRefCountedObject : public Web
 {
     friend class WebGLContext;
     template<typename T> friend void ClearLinkedList(LinkedList<T>& list);
 
 private:
     nsAutoRefCnt mWebGLRefCnt;
 
 public:
-    WebGLRefCountedObject(WebGLContext* webgl)
+    explicit WebGLRefCountedObject(WebGLContext* webgl)
         : WebGLDeletableObject(webgl)
     { }
 
     ~WebGLRefCountedObject() {
         MOZ_ASSERT(mWebGLRefCnt == 0,
                    "Destroying WebGL object still referenced by other WebGL"
                    " objects.");
     }