Bug 1320030 - Handle program and shader object deletion differently. - r=ethlin
authorJeff Gilbert <jdashg@gmail.com>
Wed, 30 Nov 2016 15:27:20 -0800
changeset 372622 6611438aed06382e2d5567e41d49938a8a9904a5
parent 372621 513dde2c67208df5c723f20c3fd46b78bbdb380a
child 372623 2d9cbc261fc0e4f09c0d7c240640c4e57bdd6d87
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersethlin
bugs1320030
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1320030 - Handle program and shader object deletion differently. - r=ethlin 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
@@ -1636,31 +1636,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.");
     }