From e2f8566e172de1e95eda5649fcac95891b5d30a5 Mon Sep 17 00:00:00 2001 From: Guillaume Abadie Date: Thu, 22 Aug 2013 20:11:27 -0400 Subject: [PATCH] bug 908232 - step 1 - Refactor the WebGL state tracking - r=jgilbert --- content/canvas/src/WebGLContext.h | 7 +++-- content/canvas/src/WebGLContextState.cpp | 37 +++++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index e80fc247185c..651a1497c159 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -780,7 +780,12 @@ public: bool IsEnabled(WebGLenum cap); private: + // State tracking slots + realGLboolean mDitherEnabled; + realGLboolean mScissorTestEnabled; + bool ValidateCapabilityEnum(WebGLenum cap, const char* info); + realGLboolean* GetStateTrackingSlot(WebGLenum cap); // ----------------------------------------------------------------------------- // Vertices Feature (WebGLContextVertices.cpp) @@ -1166,8 +1171,6 @@ protected: mStencilWriteMaskFront, mStencilWriteMaskBack; realGLboolean mColorWriteMask[4]; realGLboolean mDepthWriteMask; - realGLboolean mScissorTestEnabled; - realGLboolean mDitherEnabled; WebGLfloat mColorClearValue[4]; WebGLint mStencilClearValue; WebGLfloat mDepthClearValue; diff --git a/content/canvas/src/WebGLContextState.cpp b/content/canvas/src/WebGLContextState.cpp index af4a83f42927..49258af7fffd 100644 --- a/content/canvas/src/WebGLContextState.cpp +++ b/content/canvas/src/WebGLContextState.cpp @@ -25,13 +25,11 @@ WebGLContext::Disable(WebGLenum cap) if (!ValidateCapabilityEnum(cap, "disable")) return; - switch(cap) { - case LOCAL_GL_SCISSOR_TEST: - mScissorTestEnabled = 0; - break; - case LOCAL_GL_DITHER: - mDitherEnabled = 0; - break; + realGLboolean* trackingSlot = GetStateTrackingSlot(cap); + + if (trackingSlot) + { + *trackingSlot = 0; } MakeContextCurrent(); @@ -47,13 +45,11 @@ WebGLContext::Enable(WebGLenum cap) if (!ValidateCapabilityEnum(cap, "enable")) return; - switch(cap) { - case LOCAL_GL_SCISSOR_TEST: - mScissorTestEnabled = 1; - break; - case LOCAL_GL_DITHER: - mDitherEnabled = 1; - break; + realGLboolean* trackingSlot = GetStateTrackingSlot(cap); + + if (trackingSlot) + { + *trackingSlot = 1; } MakeContextCurrent(); @@ -547,3 +543,16 @@ WebGLContext::ValidateCapabilityEnum(WebGLenum cap, const char* info) return false; } } + +realGLboolean* +WebGLContext::GetStateTrackingSlot(WebGLenum cap) +{ + switch (cap) { + case LOCAL_GL_SCISSOR_TEST: + return &mScissorTestEnabled; + case LOCAL_GL_DITHER: + return &mDitherEnabled; + } + + return nullptr; +}