Bug 1427668 - Special-case lazy glEnable caps. - r=daoshengmu draft
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 20 Dec 2017 17:58:27 -0800
changeset 716059 6db100ee45ef15813d7e98c419b56445f7bea1c5
parent 716058 fbf39a9ef3f4101680592b266aeb637af731b6f7
child 716060 07a88e32f508aa43187b5544d229f9e090badb7c
push id94316
push userbmo:jgilbert@mozilla.com
push dateFri, 05 Jan 2018 03:14:09 +0000
reviewersdaoshengmu
bugs1427668
milestone59.0a1
Bug 1427668 - Special-case lazy glEnable caps. - r=daoshengmu MozReview-Commit-ID: KD5N2y1U804
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextState.cpp
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -981,19 +981,21 @@ public:
     void GetQuery(JSContext* cx, GLenum target, GLenum pname,
                   JS::MutableHandleValue retval, const char* funcName = nullptr);
     void GetQueryParameter(JSContext* cx, const WebGLQuery& query, GLenum pname,
                            JS::MutableHandleValue retval, const char* funcName = nullptr);
 
 
 // -----------------------------------------------------------------------------
 // State and State Requests (WebGLContextState.cpp)
+private:
+    void SetEnabled(const char* funcName, GLenum cap, bool enabled);
 public:
-    void Disable(GLenum cap);
-    void Enable(GLenum cap);
+    void Disable(GLenum cap) { SetEnabled("disabled", cap, false); }
+    void Enable(GLenum cap) { SetEnabled("enabled", cap, true); }
     bool GetStencilBits(GLint* const out_stencilBits) const;
     bool GetChannelBits(const char* funcName, GLenum pname, GLint* const out_val);
     virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
 
     void GetParameter(JSContext* cx, GLenum pname,
                       JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
     {
         retval.set(GetParameter(cx, pname, rv));
--- a/dom/canvas/WebGLContextState.cpp
+++ b/dom/canvas/WebGLContextState.cpp
@@ -18,51 +18,39 @@
 #include "WebGLRenderbuffer.h"
 #include "WebGLShader.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 
 namespace mozilla {
 
 void
-WebGLContext::Disable(GLenum cap)
+WebGLContext::SetEnabled(const char* const funcName, const GLenum cap, const bool enabled)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateCapabilityEnum(cap, "disable"))
+    if (!ValidateCapabilityEnum(cap, funcName))
         return;
 
-    realGLboolean* trackingSlot = GetStateTrackingSlot(cap);
-
-    if (trackingSlot)
-    {
-        *trackingSlot = 0;
+    const auto& slot = GetStateTrackingSlot(cap);
+    if (slot) {
+        *slot = enabled;
     }
 
-    gl->fDisable(cap);
-}
-
-void
-WebGLContext::Enable(GLenum cap)
-{
-    if (IsContextLost())
-        return;
+    switch (cap) {
+    case LOCAL_GL_DEPTH_TEST:
+    case LOCAL_GL_STENCIL_TEST:
+        break; // Lazily applied, so don't tell GL yet or we will desync.
 
-    if (!ValidateCapabilityEnum(cap, "enable"))
-        return;
-
-    realGLboolean* trackingSlot = GetStateTrackingSlot(cap);
-
-    if (trackingSlot)
-    {
-        *trackingSlot = 1;
+    default:
+        // Non-lazy caps.
+        gl->SetEnabled(cap, enabled);
+        break;
     }
-
-    gl->fEnable(cap);
 }
 
 bool
 WebGLContext::GetStencilBits(GLint* const out_stencilBits) const
 {
     *out_stencilBits = 0;
     if (mBoundDrawFramebuffer) {
         if (mBoundDrawFramebuffer->StencilAttachment().IsDefined() &&
@@ -659,16 +647,20 @@ bool
 WebGLContext::IsEnabled(GLenum cap)
 {
     if (IsContextLost())
         return false;
 
     if (!ValidateCapabilityEnum(cap, "isEnabled"))
         return false;
 
+    const auto& slot = GetStateTrackingSlot(cap);
+    if (slot)
+        return *slot;
+
     return gl->fIsEnabled(cap);
 }
 
 bool
 WebGLContext::ValidateCapabilityEnum(GLenum cap, const char* info)
 {
     switch (cap) {
         case LOCAL_GL_BLEND: