Bug 1318507 - Update sampler entrypoints to be non-nullable, and drop trivial WebGLContextUnchecked usages. - r=ethlin a=gchang
☠☠ backed out by 0da2d0158f98 ☠ ☠
authorJeff Gilbert (:jgilbert) <jgilbert@mozilla.com>
Thu, 17 Nov 2016 15:01:28 -0800
changeset 352990 11dc44b794665b2417acc5463b9e790af9b4cdea
parent 352989 b2aaaf37994ec64a8de15f0637fd8b856af02df9
child 352991 b5d390d820b03c007954bd627a4d84f2deb6728f
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
bugs1318507
milestone52.0a2
Bug 1318507 - Update sampler entrypoints to be non-nullable, and drop trivial WebGLContextUnchecked usages. - r=ethlin a=gchang MozReview-Commit-ID: 2dWKDFbAK6a
dom/canvas/WebGL2ContextSamplers.cpp
dom/canvas/WebGLContextUnchecked.cpp
dom/canvas/WebGLContextUnchecked.h
--- a/dom/canvas/WebGL2ContextSamplers.cpp
+++ b/dom/canvas/WebGL2ContextSamplers.cpp
@@ -75,163 +75,91 @@ WebGL2Context::BindSampler(GLuint unit, 
         return;
 
     if (GLint(unit) >= mGLMaxTextureUnits)
         return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits);
 
     if (sampler && sampler->IsDeleted())
         return ErrorInvalidOperation("bindSampler: binding deleted sampler");
 
-    WebGLContextUnchecked::BindSampler(unit, sampler);
+    ////
+
+    gl->MakeCurrent();
+    gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
+
     InvalidateResolveCacheForTextureWithTexUnit(unit);
-
     mBoundSamplers[unit] = sampler;
 }
 
 void
-WebGL2Context::SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param)
+WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint paramInt)
 {
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameteri: invalid sampler");
-
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameteri"))
-        return;
-
-    sampler->SamplerParameter1i(pname, param);
-    WebGLContextUnchecked::SamplerParameteri(sampler, pname, param);
-}
-
-void
-WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Int32Array& param)
-{
+    const char funcName[] = "samplerParameteri";
     if (IsContextLost())
         return;
 
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
-
-    param.ComputeLengthAndData();
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param.Data()[0]), "samplerParameteriv"))
+    if (!ValidateObjectRef(funcName, sampler))
         return;
 
-    sampler->SamplerParameter1i(pname, param.Data()[0]);
-    WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Data());
-}
-
-void
-WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLint>& param)
-{
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
-
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param[0]), "samplerParameteriv"))
-        return;
-
-    sampler->SamplerParameter1i(pname, param[0]);
-    WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Elements());
+    sampler.SamplerParameter(funcName, pname, paramInt);
 }
 
 void
-WebGL2Context::SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param)
+WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat paramFloat)
 {
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameterf: invalid sampler");
-
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameterf"))
-        return;
-
-    sampler->SamplerParameter1f(pname, param);
-    WebGLContextUnchecked::SamplerParameterf(sampler, pname, param);
-}
-
-void
-WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Float32Array& param)
-{
+    const char funcName[] = "samplerParameterf";
     if (IsContextLost())
         return;
 
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
-
-    param.ComputeLengthAndData();
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param.Data()[0]), "samplerParameterfv"))
+    if (!ValidateObjectRef(funcName, sampler))
         return;
 
-    sampler->SamplerParameter1f(pname, param.Data()[0]);
-    WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Data());
+    sampler.SamplerParameter(funcName, pname, WebGLIntOrFloat(paramFloat).AsInt());
 }
 
 void
-WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLfloat>& param)
+WebGL2Context::GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLenum pname,
+                                   JS::MutableHandleValue retval)
 {
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
-
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param[0]), "samplerParameterfv"))
-        return;
-
-    sampler->SamplerParameter1f(pname, param[0]);
-    WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Elements());
-}
-
-void
-WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval)
-{
+    const char funcName[] = "getSamplerParameter";
     retval.setNull();
 
     if (IsContextLost())
         return;
 
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("getSamplerParameter: invalid sampler");
+    if (!ValidateObjectRef(funcName, sampler))
+        return;
 
-    if (!ValidateSamplerParameterName(pname, "getSamplerParameter"))
-        return;
+    ////
+
+    gl->MakeCurrent();
 
     switch (pname) {
     case LOCAL_GL_TEXTURE_MIN_FILTER:
     case LOCAL_GL_TEXTURE_MAG_FILTER:
     case LOCAL_GL_TEXTURE_WRAP_S:
     case LOCAL_GL_TEXTURE_WRAP_T:
     case LOCAL_GL_TEXTURE_WRAP_R:
     case LOCAL_GL_TEXTURE_COMPARE_MODE:
     case LOCAL_GL_TEXTURE_COMPARE_FUNC:
-        retval.set(JS::Int32Value(
-            WebGLContextUnchecked::GetSamplerParameteriv(sampler, pname)));
+        {
+            GLint param = 0;
+            gl->fGetSamplerParameteriv(sampler.mGLName, pname, &param);
+            retval.set(JS::Int32Value(param));
+        }
         return;
 
     case LOCAL_GL_TEXTURE_MIN_LOD:
     case LOCAL_GL_TEXTURE_MAX_LOD:
-        retval.set(JS::Float32Value(
-            WebGLContextUnchecked::GetSamplerParameterfv(sampler, pname)));
+        {
+            GLfloat param = 0;
+            gl->fGetSamplerParameterfv(sampler.mGLName, pname, &param);
+            retval.set(JS::Float32Value(param));
+        }
+        return;
+
+    default:
+        ErrorInvalidEnum("%s: invalid pname: %s", funcName, EnumName(pname));
         return;
     }
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGLContextUnchecked.cpp
+++ b/dom/canvas/WebGLContextUnchecked.cpp
@@ -11,84 +11,9 @@
 
 namespace mozilla {
 
 WebGLContextUnchecked::WebGLContextUnchecked(gl::GLContext* _gl)
     : mGL_OnlyClearInDestroyResourcesAndContext(_gl)
     , gl(mGL_OnlyClearInDestroyResourcesAndContext) // const reference
 { }
 
-// -----------------------------------------------------------------------------
-// Sampler Objects
-
-void
-WebGLContextUnchecked::BindSampler(GLuint unit, WebGLSampler* sampler)
-{
-    gl->MakeCurrent();
-    gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
-}
-
-GLint
-WebGLContextUnchecked::GetSamplerParameteriv(WebGLSampler* sampler,
-                                             GLenum pname)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-
-    GLint param = 0;
-    gl->MakeCurrent();
-    gl->fGetSamplerParameteriv(sampler->mGLName, pname, &param);
-
-    return param;
-}
-
-GLfloat
-WebGLContextUnchecked::GetSamplerParameterfv(WebGLSampler* sampler,
-                                             GLenum pname)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-
-    GLfloat param = 0.0f;
-    gl->MakeCurrent();
-    gl->fGetSamplerParameterfv(sampler->mGLName, pname, &param);
-    return param;
-}
-
-void
-WebGLContextUnchecked::SamplerParameteri(WebGLSampler* sampler,
-                                         GLenum pname,
-                                         GLint param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameteri(sampler->mGLName, pname, param);
-}
-
-void
-WebGLContextUnchecked::SamplerParameteriv(WebGLSampler* sampler,
-                                          GLenum pname,
-                                          const GLint* param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameteriv(sampler->mGLName, pname, param);
-}
-
-void
-WebGLContextUnchecked::SamplerParameterf(WebGLSampler* sampler,
-                                         GLenum pname,
-                                         GLfloat param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameterf(sampler->mGLName, pname, param);
-}
-
-void
-WebGLContextUnchecked::SamplerParameterfv(WebGLSampler* sampler,
-                                          GLenum pname,
-                                          const GLfloat* param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameterfv(sampler->mGLName, pname, param);
-}
-
 } // namespace mozilla
--- a/dom/canvas/WebGLContextUnchecked.h
+++ b/dom/canvas/WebGLContextUnchecked.h
@@ -15,28 +15,16 @@ namespace mozilla {
 class WebGLBuffer;
 class WebGLSampler;
 
 class WebGLContextUnchecked
 {
 public:
     explicit WebGLContextUnchecked(gl::GLContext* gl);
 
-    // -------------------------------------------------------------------------
-    // Sampler Objects
-    void BindSampler(GLuint unit, WebGLSampler* sampler);
-
-    GLint   GetSamplerParameteriv(WebGLSampler* sampler, GLenum pname);
-    GLfloat GetSamplerParameterfv(WebGLSampler* sampler, GLenum pname);
-
-    void SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param);
-    void SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const GLint* param);
-    void SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param);
-    void SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const GLfloat* param);
-
 protected:
     // We've had issues in the past with nulling `gl` without actually releasing
     // all of our resources. This construction ensures that we are aware that we
     // should only null `gl` in DestroyResourcesAndContext.
     RefPtr<gl::GLContext> mGL_OnlyClearInDestroyResourcesAndContext;
 public:
     // Grab a const reference so we can see changes, but can't make changes.
     const decltype(mGL_OnlyClearInDestroyResourcesAndContext)& gl;