Bug 1320030 - Handle program and shader object deletion differently. - r=ethlin draft
authorJeff Gilbert <jdashg@gmail.com>
Wed, 30 Nov 2016 15:27:20 -0800
changeset 446133 bd8ed7d4eb6704bbf97e92f9d86c537fd53d7471
parent 446132 1c010a9b344e28f5f52ff2150c30fce711a6c164
child 538710 0cb414b038c1b122a1fac4993406dd2c073d44ed
push id37706
push userbmo:jgilbert@mozilla.com
push dateWed, 30 Nov 2016 23:28:37 +0000
reviewersethlin
bugs1320030
milestone53.0a1
Bug 1320030 - Handle program and shader object deletion differently. - r=ethlin MozReview-Commit-ID: 4wSZ81lFP6e
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextGL.cpp
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1641,31 +1641,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 {
 
+inline bool
+WebGLContext::ValidateObject(const char* funcName, const WebGLProgram& object)
+{
+    return ValidateObject(funcName, object, true);
+}
+
+inline 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
 //