Backed out changeset 1efb117b969c (bug 1004309) for build bustage on a CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Thu, 01 May 2014 14:49:41 -0700
changeset 181655 5cf5f00fc6ace7743f9e5d4737dac274ff04b86d
parent 181654 c788ef01538a25c8460cfb72c07c7d8139b4dae8
child 181656 705313e71606fbfa95c34d87a8ef282d2bedc667
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
bugs1004309
milestone32.0a1
backs out1efb117b969c1267463c1abf50b3fbc17b58be7e
Backed out changeset 1efb117b969c (bug 1004309) for build bustage on a CLOSED TREE
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextUtils.cpp
content/canvas/src/WebGLProgram.h
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -602,18 +602,16 @@ WebGLContext::SetDimensions(int32_t widt
 
     MOZ_ASSERT(gl->Caps().color == caps.color);
     MOZ_ASSERT(gl->Caps().alpha == caps.alpha);
     MOZ_ASSERT(gl->Caps().depth == caps.depth || !gl->Caps().depth);
     MOZ_ASSERT(gl->Caps().stencil == caps.stencil || !gl->Caps().stencil);
     MOZ_ASSERT(gl->Caps().antialias == caps.antialias || !gl->Caps().antialias);
     MOZ_ASSERT(gl->Caps().preserve == caps.preserve);
 
-    AssertCachedState();
-
     reporter.SetSuccessful();
     return NS_OK;
 }
 
 void
 WebGLContext::ClearBackbufferIfNeeded()
 {
     if (!mBackbufferNeedsClear)
@@ -969,31 +967,104 @@ WebGLContext::ClearScreen()
     if (mOptions.stencil)
         clearMask |= LOCAL_GL_STENCIL_BUFFER_BIT;
 
     colorAttachmentsMask[0] = true;
 
     ForceClearFramebufferWithDefaultValues(clearMask, colorAttachmentsMask);
 }
 
+#ifdef DEBUG
+// For NaNs, etc.
+static bool IsShadowCorrect(float shadow, float actual) {
+    if (IsNaN(shadow)) {
+        // GL is allowed to do anything it wants for NaNs, so if we're shadowing
+        // a NaN, then whatever `actual` is might be correct.
+        return true;
+    }
+
+    return shadow == actual;
+}
+#endif
+
 void
 WebGLContext::ForceClearFramebufferWithDefaultValues(GLbitfield mask, const bool colorAttachmentsMask[kMaxColorAttachments])
 {
     MakeContextCurrent();
 
     bool initializeColorBuffer = 0 != (mask & LOCAL_GL_COLOR_BUFFER_BIT);
     bool initializeDepthBuffer = 0 != (mask & LOCAL_GL_DEPTH_BUFFER_BIT);
     bool initializeStencilBuffer = 0 != (mask & LOCAL_GL_STENCIL_BUFFER_BIT);
     bool drawBuffersIsEnabled = IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers);
 
     GLenum currentDrawBuffers[WebGLContext::kMaxColorAttachments];
 
     // Fun GL fact: No need to worry about the viewport here, glViewport is just
     // setting up a coordinates transformation, it doesn't affect glClear at all.
-    AssertCachedState();
+
+#ifdef DEBUG
+    // Scope to hide our variables.
+    {
+        // Sanity-check that all our state is set properly. Otherwise, when we
+        // reset out state to what we *think* it is, we'll get it wrong.
+
+        // Dither shouldn't matter when we're clearing to {0,0,0,0}.
+        MOZ_ASSERT(gl->fIsEnabled(LOCAL_GL_SCISSOR_TEST) == mScissorTestEnabled);
+
+        if (initializeColorBuffer) {
+            realGLboolean colorWriteMask[4] = {2, 2, 2, 2};
+            GLfloat colorClearValue[4] = {-1.0f, -1.0f, -1.0f, -1.0f};
+
+            gl->fGetBooleanv(LOCAL_GL_COLOR_WRITEMASK, colorWriteMask);
+            gl->fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, colorClearValue);
+
+            MOZ_ASSERT(colorWriteMask[0] == mColorWriteMask[0] &&
+                       colorWriteMask[1] == mColorWriteMask[1] &&
+                       colorWriteMask[2] == mColorWriteMask[2] &&
+                       colorWriteMask[3] == mColorWriteMask[3]);
+            MOZ_ASSERT(IsShadowCorrect(mColorClearValue[0], colorClearValue[0]) &&
+                       IsShadowCorrect(mColorClearValue[1], colorClearValue[1]) &&
+                       IsShadowCorrect(mColorClearValue[2], colorClearValue[2]) &&
+                       IsShadowCorrect(mColorClearValue[3], colorClearValue[3]));
+        }
+
+        if (initializeDepthBuffer) {
+            realGLboolean depthWriteMask = 2;
+            GLfloat depthClearValue = -1.0f;
+
+
+            gl->fGetBooleanv(LOCAL_GL_DEPTH_WRITEMASK, &depthWriteMask);
+            gl->fGetFloatv(LOCAL_GL_DEPTH_CLEAR_VALUE, &depthClearValue);
+
+            MOZ_ASSERT(depthWriteMask == mDepthWriteMask);
+            MOZ_ASSERT(IsShadowCorrect(mDepthClearValue, depthClearValue));
+        }
+
+        if (initializeStencilBuffer) {
+            GLuint stencilWriteMaskFront = 0xdeadbad1;
+            GLuint stencilWriteMaskBack  = 0xdeadbad1;
+            GLuint stencilClearValue     = 0xdeadbad1;
+
+            gl->GetUIntegerv(LOCAL_GL_STENCIL_WRITEMASK,      &stencilWriteMaskFront);
+            gl->GetUIntegerv(LOCAL_GL_STENCIL_BACK_WRITEMASK, &stencilWriteMaskBack);
+            gl->GetUIntegerv(LOCAL_GL_STENCIL_CLEAR_VALUE,    &stencilClearValue);
+
+            GLuint stencilBits = 0;
+            gl->GetUIntegerv(LOCAL_GL_STENCIL_BITS, &stencilBits);
+            GLuint stencilMask = (GLuint(1) << stencilBits) - 1;
+
+            MOZ_ASSERT( ( stencilWriteMaskFront & stencilMask) ==
+                        (mStencilWriteMaskFront & stencilMask) );
+            MOZ_ASSERT( ( stencilWriteMaskBack & stencilMask) ==
+                        (mStencilWriteMaskBack & stencilMask) );
+            MOZ_ASSERT( ( stencilClearValue & stencilMask) ==
+                        (mStencilClearValue & stencilMask) );
+        }
+    }
+#endif
 
     // Prepare GL state for clearing.
     gl->fDisable(LOCAL_GL_SCISSOR_TEST);
 
     if (initializeColorBuffer) {
 
         if (drawBuffersIsEnabled) {
 
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -5,17 +5,16 @@
 
 #ifndef WEBGLCONTEXT_H_
 #define WEBGLCONTEXT_H_
 
 #include "mozilla/Attributes.h"
 #include "GLDefs.h"
 #include "WebGLActiveInfo.h"
 #include "WebGLObjectModel.h"
-#include "WebGLRenderbuffer.h"
 #include <stdarg.h>
 
 #include "nsTArray.h"
 #include "nsCycleCollectionNoteChild.h"
 
 #include "nsIDOMWebGLRenderingContext.h"
 #include "nsICanvasRenderingContextInternal.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
@@ -110,27 +109,16 @@ struct WebGLContextOptions {
     bool alpha;
     bool depth;
     bool stencil;
     bool premultipliedAlpha;
     bool antialias;
     bool preserveDrawingBuffer;
 };
 
-static bool
-IsTextureBinding(GLenum binding)
-{
-    switch (binding) {
-    case LOCAL_GL_TEXTURE_BINDING_2D:
-    case LOCAL_GL_TEXTURE_BINDING_CUBE_MAP:
-        return true;
-    }
-    return false;
-}
-
 class WebGLContext :
     public nsIDOMWebGLRenderingContext,
     public nsICanvasRenderingContextInternal,
     public nsSupportsWeakReference,
     public WebGLRectangleObject,
     public nsWrapperCache
 {
     friend class WebGLContextUserData;
@@ -211,18 +199,17 @@ public:
     void ErrorInvalidEnumInfo(const char *info, GLenum enumvalue);
     void ErrorOutOfMemory(const char *fmt = 0, ...);
 
     const char *ErrorName(GLenum error);
     bool IsTextureFormatCompressed(GLenum format);
 
     void DummyFramebufferOperation(const char *info);
 
-    WebGLTexture* activeBoundTextureForTarget(GLenum target) const {
-        MOZ_ASSERT(!IsTextureBinding(target));
+    WebGLTexture *activeBoundTextureForTarget(GLenum target) const {
         return target == LOCAL_GL_TEXTURE_2D ? mBound2DTextures[mActiveTexture]
                                              : mBoundCubeMapTextures[mActiveTexture];
     }
 
     already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                                                  CanvasLayer *aOldLayer,
                                                  LayerManager *aManager) MOZ_OVERRIDE;
 
@@ -257,18 +244,16 @@ public:
 
     bool MinCapabilityMode() const { return mMinCapability; }
 
     void RobustnessTimerCallback(nsITimer* timer);
     static void RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer);
     void SetupContextLossTimer();
     void TerminateContextLossTimer();
 
-    void AssertCachedState();
-
     // WebIDL WebGLRenderingContext API
     dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
     GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
     GLsizei DrawingBufferHeight() const { return IsContextLost() ? 0 : mHeight; }
 
     void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
     bool IsContextLost() const { return mContextStatus != ContextNotLost; }
     void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
--- a/content/canvas/src/WebGLContextUtils.cpp
+++ b/content/canvas/src/WebGLContextUtils.cpp
@@ -1,33 +1,32 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "WebGLContext.h"
-
 #include <stdarg.h>
 
+#include "WebGLContext.h"
 #include "GLContext.h"
+
+#include "prprf.h"
+
 #include "jsapi.h"
-#include "mozilla/Preferences.h"
-#include "nsCxPusher.h"
-#include "nsIDOMDataContainerEvent.h"
-#include "nsIDOMEvent.h"
 #include "nsIScriptSecurityManager.h"
+#include "nsServiceManagerUtils.h"
 #include "nsIVariant.h"
-#include "nsServiceManagerUtils.h"
-#include "prprf.h"
-#include "WebGLBuffer.h"
-#include "WebGLExtensions.h"
-#include "WebGLFramebuffer.h"
-#include "WebGLProgram.h"
-#include "WebGLTexture.h"
-#include "WebGLVertexArray.h"
+#include "nsCxPusher.h"
+
+#include "nsIDOMEvent.h"
+#include "nsIDOMDataContainerEvent.h"
+
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 namespace mozilla {
 
 bool
 IsGLDepthFormat(GLenum internalFormat)
 {
     return (internalFormat == LOCAL_GL_DEPTH_COMPONENT ||
             internalFormat == LOCAL_GL_DEPTH_COMPONENT16 ||
@@ -36,16 +35,18 @@ IsGLDepthFormat(GLenum internalFormat)
 
 bool
 IsGLDepthStencilFormat(GLenum internalFormat)
 {
     return (internalFormat == LOCAL_GL_DEPTH_STENCIL ||
             internalFormat == LOCAL_GL_DEPTH24_STENCIL8);
 }
 
+} // namespace mozilla
+
 void
 WebGLContext::GenerateWarning(const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
 
     GenerateWarning(fmt, ap);
 
@@ -239,136 +240,8 @@ WebGLContext::GetAndFlushUnderlyingGLErr
 
     // Only store in mUnderlyingGLError if is hasn't already recorded an
     // error.
     if (!mUnderlyingGLError)
         mUnderlyingGLError = error;
 
     return error;
 }
-
-#ifdef DEBUG
-// For NaNs, etc.
-static bool
-IsCacheCorrect(float cached, float actual)
-{
-    if (IsNaN(cached)) {
-        // GL is allowed to do anything it wants for NaNs, so if we're shadowing
-        // a NaN, then whatever `actual` is might be correct.
-        return true;
-    }
-
-    return cached == actual;
-}
-
-static void
-AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow)
-{
-    GLuint val = 0;
-    gl->GetUIntegerv(pname, &val);
-    MOZ_ASSERT(val == shadow);
-}
-#endif
-
-void
-WebGLContext::AssertCachedState()
-{
-#ifdef DEBUG
-    MakeContextCurrent();
-
-    GetAndFlushUnderlyingGLErrors();
-
-    // extensions
-    if (IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers)) {
-        AssertUintParamCorrect(gl, LOCAL_GL_MAX_COLOR_ATTACHMENTS, mGLMaxColorAttachments);
-        AssertUintParamCorrect(gl, LOCAL_GL_MAX_DRAW_BUFFERS, mGLMaxDrawBuffers);
-    }
-
-    if (IsExtensionEnabled(WebGLExtensionID::OES_vertex_array_object)) {
-        GLuint bound = mBoundVertexArray ? mBoundVertexArray->GLName() : 0;
-        AssertUintParamCorrect(gl, LOCAL_GL_VERTEX_ARRAY_BINDING, bound);
-    }
-
-    // Draw state
-    MOZ_ASSERT(gl->fIsEnabled(LOCAL_GL_SCISSOR_TEST) == mScissorTestEnabled);
-    MOZ_ASSERT(gl->fIsEnabled(LOCAL_GL_DITHER) == mDitherEnabled);
-    MOZ_ASSERT_IF(IsWebGL2(),
-                  gl->fIsEnabled(LOCAL_GL_RASTERIZER_DISCARD) == mRasterizerDiscardEnabled);
-
-
-    realGLboolean colorWriteMask[4] = {0, 0, 0, 0};
-    gl->fGetBooleanv(LOCAL_GL_COLOR_WRITEMASK, colorWriteMask);
-    MOZ_ASSERT(colorWriteMask[0] == mColorWriteMask[0] &&
-               colorWriteMask[1] == mColorWriteMask[1] &&
-               colorWriteMask[2] == mColorWriteMask[2] &&
-               colorWriteMask[3] == mColorWriteMask[3]);
-
-    GLfloat colorClearValue[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-    gl->fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, colorClearValue);
-    MOZ_ASSERT(IsCacheCorrect(mColorClearValue[0], colorClearValue[0]) &&
-               IsCacheCorrect(mColorClearValue[1], colorClearValue[1]) &&
-               IsCacheCorrect(mColorClearValue[2], colorClearValue[2]) &&
-               IsCacheCorrect(mColorClearValue[3], colorClearValue[3]));
-
-    realGLboolean depthWriteMask = 0;
-    gl->fGetBooleanv(LOCAL_GL_DEPTH_WRITEMASK, &depthWriteMask);
-    MOZ_ASSERT(depthWriteMask == mDepthWriteMask);
-
-    GLfloat depthClearValue = 0.0f;
-    gl->fGetFloatv(LOCAL_GL_DEPTH_CLEAR_VALUE, &depthClearValue);
-    MOZ_ASSERT(IsCacheCorrect(mDepthClearValue, depthClearValue));
-
-
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_CLEAR_VALUE, mStencilClearValue);
-
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_REF,      mStencilRefFront);
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_REF, mStencilRefBack);
-
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_VALUE_MASK,      mStencilValueMaskFront);
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_VALUE_MASK, mStencilValueMaskBack);
-
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_WRITEMASK,      mStencilWriteMaskFront);
-    AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_WRITEMASK, mStencilWriteMaskBack);
-
-    // Bound object state
-    GLuint bound = mBoundFramebuffer ? mBoundFramebuffer->GLName() : 0;
-    AssertUintParamCorrect(gl, LOCAL_GL_FRAMEBUFFER_BINDING, bound);
-
-    bound = mCurrentProgram ? mCurrentProgram->GLName() : 0;
-    AssertUintParamCorrect(gl, LOCAL_GL_CURRENT_PROGRAM, bound);
-
-    // Textures
-    GLenum activeTexture = mActiveTexture + LOCAL_GL_TEXTURE0;
-    AssertUintParamCorrect(gl, LOCAL_GL_ACTIVE_TEXTURE, activeTexture);
-
-    WebGLTexture* curTex = activeBoundTextureForTarget(LOCAL_GL_TEXTURE_2D);
-    bound = curTex ? curTex->GLName() : 0;
-    AssertUintParamCorrect(gl, LOCAL_GL_TEXTURE_BINDING_2D, bound);
-
-    curTex = activeBoundTextureForTarget(LOCAL_GL_TEXTURE_CUBE_MAP);
-    bound = curTex ? curTex->GLName() : 0;
-    AssertUintParamCorrect(gl, LOCAL_GL_TEXTURE_BINDING_CUBE_MAP, bound);
-
-    // Buffers
-    bound = mBoundArrayBuffer ? mBoundArrayBuffer->GLName() : 0;
-    AssertUintParamCorrect(gl, LOCAL_GL_ARRAY_BUFFER_BINDING, bound);
-
-    MOZ_ASSERT(mBoundVertexArray);
-    WebGLBuffer* curBuff = mBoundVertexArray->mBoundElementArrayBuffer;
-    bound = curBuff ? curBuff->GLName() : 0;
-    AssertUintParamCorrect(gl, LOCAL_GL_ELEMENT_ARRAY_BUFFER_BINDING, bound);
-
-    // Viewport
-    GLint int4[4] = {0, 0, 0, 0};
-    gl->fGetIntegerv(LOCAL_GL_VIEWPORT, int4);
-    MOZ_ASSERT(int4[0] == mViewportX &&
-               int4[1] == mViewportY &&
-               int4[2] == mViewportWidth &&
-               int4[3] == mViewportHeight);
-
-    AssertUintParamCorrect(gl, LOCAL_GL_PACK_ALIGNMENT, mPixelStorePackAlignment);
-    AssertUintParamCorrect(gl, LOCAL_GL_UNPACK_ALIGNMENT, mPixelStoreUnpackAlignment);
-
-    MOZ_ASSERT(!GetAndFlushUnderlyingGLErrors());
-#endif
-}
-
-} // namespace mozilla
--- a/content/canvas/src/WebGLProgram.h
+++ b/content/canvas/src/WebGLProgram.h
@@ -3,23 +3,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef WEBGLPROGRAM_H_
 #define WEBGLPROGRAM_H_
 
 #include "WebGLObjectModel.h"
 
-#include <map>
+#include "nsWrapperCache.h"
 
-#include "mozilla/CheckedInt.h"
 #include "mozilla/LinkedList.h"
-#include "nsWrapperCache.h"
-#include "WebGLShader.h"
-#include "WebGLUniformInfo.h"
+#include "mozilla/CheckedInt.h"
+#include <map>
 
 namespace mozilla {
 
 class WebGLShader;
 class WebGLUniformInfo;
 
 typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
 typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap;