Bug 924189 - Use MOZ_BEGIN_ENUM_CLASS for the WebGL VertexAttrib0 enum - r=jgilbert
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 11 Oct 2013 09:16:43 -0400
changeset 165233 110789fb8722a8fe2988bcba2f55cfb272aea01f
parent 165232 1632bbff03ad552628cee3b1d4ce86b18938f12f
child 165234 32cd027a960db4acfc1357818974aab2c530506d
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs924189
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 924189 - Use MOZ_BEGIN_ENUM_CLASS for the WebGL VertexAttrib0 enum - r=jgilbert
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextGL.cpp
content/canvas/src/WebGLTypes.h
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -128,17 +128,17 @@ WebGLContext::WebGLContext()
     mVertexAttrib0Vector[2] = 0;
     mVertexAttrib0Vector[3] = 1;
     mFakeVertexAttrib0BufferObjectVector[0] = 0;
     mFakeVertexAttrib0BufferObjectVector[1] = 0;
     mFakeVertexAttrib0BufferObjectVector[2] = 0;
     mFakeVertexAttrib0BufferObjectVector[3] = 1;
     mFakeVertexAttrib0BufferObjectSize = 0;
     mFakeVertexAttrib0BufferObject = 0;
-    mFakeVertexAttrib0BufferStatus = VertexAttrib0Status::Default;
+    mFakeVertexAttrib0BufferStatus = WebGLVertexAttrib0Status::Default;
 
     // these are de default values, see 6.2 State tables in the OpenGL ES 2.0.25 spec
     mColorWriteMask[0] = 1;
     mColorWriteMask[1] = 1;
     mColorWriteMask[2] = 1;
     mColorWriteMask[3] = 1;
     mDepthWriteMask = 1;
     mColorClearValue[0] = 0.f;
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -804,17 +804,17 @@ protected:
     }
     // Returns the current fake-black-status, except if it was Unknown,
     // in which case this function resolves it first, so it never returns Unknown.
     WebGLContextFakeBlackStatus ResolvedFakeBlackStatus();
 
     void BindFakeBlackTextures();
     void UnbindFakeBlackTextures();
 
-    int WhatDoesVertexAttrib0Need();
+    WebGLVertexAttrib0Status WhatDoesVertexAttrib0Need();
     bool DoFakeVertexAttrib0(GLuint vertexCount);
     void UndoFakeVertexAttrib0();
     void InvalidateFakeVertexAttrib0();
 
     static CheckedUint32 GetImageSize(GLsizei height, 
                                       GLsizei width, 
                                       uint32_t pixelSize,
                                       uint32_t alignment);
@@ -1116,17 +1116,17 @@ protected:
         const nsTArray<WebGLRefPtr<WebGLTexture> >& boundTexturesArray,
         ScopedDeletePtr<FakeBlackTexture> & opaqueTextureScopedPtr,
         ScopedDeletePtr<FakeBlackTexture> & transparentTextureScopedPtr);
 
     GLfloat mVertexAttrib0Vector[4];
     GLfloat mFakeVertexAttrib0BufferObjectVector[4];
     size_t mFakeVertexAttrib0BufferObjectSize;
     GLuint mFakeVertexAttrib0BufferObject;
-    int mFakeVertexAttrib0BufferStatus;
+    WebGLVertexAttrib0Status mFakeVertexAttrib0BufferStatus;
 
     GLint mStencilRefFront, mStencilRefBack;
     GLuint mStencilValueMaskFront, mStencilValueMaskBack,
               mStencilWriteMaskFront, mStencilWriteMaskBack;
     realGLboolean mColorWriteMask[4];
     realGLboolean mDepthWriteMask;
     GLfloat mColorClearValue[4];
     GLint mStencilClearValue;
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -864,42 +864,42 @@ WebGLContext::DepthRange(GLfloat zNear, 
 
     if (zNear > zFar)
         return ErrorInvalidOperation("depthRange: the near value is greater than the far value!");
 
     MakeContextCurrent();
     gl->fDepthRange(zNear, zFar);
 }
 
-int
+WebGLVertexAttrib0Status
 WebGLContext::WhatDoesVertexAttrib0Need()
 {
   // here we may assume that mCurrentProgram != null
 
     // work around Mac OSX crash, see bug 631420
 #ifdef XP_MACOSX
     if (gl->WorkAroundDriverBugs() &&
         mBoundVertexArray->mAttribBuffers[0].enabled &&
         !mCurrentProgram->IsAttribInUse(0))
     {
-        return VertexAttrib0Status::EmulatedUninitializedArray;
+        return WebGLVertexAttrib0Status::EmulatedUninitializedArray;
     }
 #endif
 
-    return (gl->IsGLES2() || mBoundVertexArray->mAttribBuffers[0].enabled) ? VertexAttrib0Status::Default
-         : mCurrentProgram->IsAttribInUse(0)            ? VertexAttrib0Status::EmulatedInitializedArray
-                                                        : VertexAttrib0Status::EmulatedUninitializedArray;
+    return (gl->IsGLES2() || mBoundVertexArray->mAttribBuffers[0].enabled) ? WebGLVertexAttrib0Status::Default
+         : mCurrentProgram->IsAttribInUse(0) ? WebGLVertexAttrib0Status::EmulatedInitializedArray
+                                             : WebGLVertexAttrib0Status::EmulatedUninitializedArray;
 }
 
 bool
 WebGLContext::DoFakeVertexAttrib0(GLuint vertexCount)
 {
-    int whatDoesAttrib0Need = WhatDoesVertexAttrib0Need();
-
-    if (whatDoesAttrib0Need == VertexAttrib0Status::Default)
+    WebGLVertexAttrib0Status whatDoesAttrib0Need = WhatDoesVertexAttrib0Need();
+
+    if (whatDoesAttrib0Need == WebGLVertexAttrib0Status::Default)
         return true;
 
     if (!mAlreadyWarnedAboutFakeVertexAttrib0) {
         GenerateWarning("Drawing without vertex attrib 0 array enabled forces the browser "
                         "to do expensive emulation work when running on desktop OpenGL "
                         "platforms, for example on Mac. It is preferable to always draw "
                         "with vertex attrib 0 array enabled, by using bindAttribLocation "
                         "to bind some always-used attribute to location 0.");
@@ -919,18 +919,18 @@ WebGLContext::DoFakeVertexAttrib0(GLuint
     if (!mFakeVertexAttrib0BufferObject) {
         gl->fGenBuffers(1, &mFakeVertexAttrib0BufferObject);
     }
 
     // if the VBO status is already exactly what we need, or if the only difference is that it's initialized and
     // we don't need it to be, then consider it OK
     bool vertexAttrib0BufferStatusOK =
         mFakeVertexAttrib0BufferStatus == whatDoesAttrib0Need ||
-        (mFakeVertexAttrib0BufferStatus == VertexAttrib0Status::EmulatedInitializedArray &&
-         whatDoesAttrib0Need == VertexAttrib0Status::EmulatedUninitializedArray);
+        (mFakeVertexAttrib0BufferStatus == WebGLVertexAttrib0Status::EmulatedInitializedArray &&
+         whatDoesAttrib0Need == WebGLVertexAttrib0Status::EmulatedUninitializedArray);
 
     if (!vertexAttrib0BufferStatusOK ||
         mFakeVertexAttrib0BufferObjectSize < dataSize ||
         mFakeVertexAttrib0BufferObjectVector[0] != mVertexAttrib0Vector[0] ||
         mFakeVertexAttrib0BufferObjectVector[1] != mVertexAttrib0Vector[1] ||
         mFakeVertexAttrib0BufferObjectVector[2] != mVertexAttrib0Vector[2] ||
         mFakeVertexAttrib0BufferObjectVector[3] != mVertexAttrib0Vector[3])
     {
@@ -941,17 +941,17 @@ WebGLContext::DoFakeVertexAttrib0(GLuint
         mFakeVertexAttrib0BufferObjectVector[2] = mVertexAttrib0Vector[2];
         mFakeVertexAttrib0BufferObjectVector[3] = mVertexAttrib0Vector[3];
 
         gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mFakeVertexAttrib0BufferObject);
 
         GLenum error = LOCAL_GL_NO_ERROR;
         UpdateWebGLErrorAndClearGLError();
 
-        if (mFakeVertexAttrib0BufferStatus == VertexAttrib0Status::EmulatedInitializedArray) {
+        if (mFakeVertexAttrib0BufferStatus == WebGLVertexAttrib0Status::EmulatedInitializedArray) {
             nsAutoArrayPtr<GLfloat> array(new GLfloat[4 * vertexCount]);
             for(size_t i = 0; i < vertexCount; ++i) {
                 array[4 * i + 0] = mVertexAttrib0Vector[0];
                 array[4 * i + 1] = mVertexAttrib0Vector[1];
                 array[4 * i + 2] = mVertexAttrib0Vector[2];
                 array[4 * i + 3] = mVertexAttrib0Vector[3];
             }
             gl->fBufferData(LOCAL_GL_ARRAY_BUFFER, dataSize, array, LOCAL_GL_DYNAMIC_DRAW);
@@ -974,19 +974,19 @@ WebGLContext::DoFakeVertexAttrib0(GLuint
     gl->fVertexAttribPointer(0, 4, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0);
     
     return true;
 }
 
 void
 WebGLContext::UndoFakeVertexAttrib0()
 {
-    int whatDoesAttrib0Need = WhatDoesVertexAttrib0Need();
-
-    if (whatDoesAttrib0Need == VertexAttrib0Status::Default)
+    WebGLVertexAttrib0Status whatDoesAttrib0Need = WhatDoesVertexAttrib0Need();
+
+    if (whatDoesAttrib0Need == WebGLVertexAttrib0Status::Default)
         return;
 
     gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mBoundVertexArray->mAttribBuffers[0].buf ? mBoundVertexArray->mAttribBuffers[0].buf->GLName() : 0);
     gl->fVertexAttribPointer(0,
                              mBoundVertexArray->mAttribBuffers[0].size,
                              mBoundVertexArray->mAttribBuffers[0].type,
                              mBoundVertexArray->mAttribBuffers[0].normalized,
                              mBoundVertexArray->mAttribBuffers[0].stride,
--- a/content/canvas/src/WebGLTypes.h
+++ b/content/canvas/src/WebGLTypes.h
@@ -54,19 +54,27 @@ MOZ_END_ENUM_CLASS(WebGLContextFakeBlack
 
 MOZ_BEGIN_ENUM_CLASS(WebGLTextureFakeBlackStatus, int)
   Unknown,
   NotNeeded,
   IncompleteTexture,
   UninitializedImageData
 MOZ_END_ENUM_CLASS(WebGLTextureFakeBlackStatus)
 
-struct VertexAttrib0Status {
-    enum { Default, EmulatedUninitializedArray, EmulatedInitializedArray };
-};
+/*
+ * Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires
+ * emulating the vertex attrib 0 array when it's not enabled. Indeed,
+ * OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
+ * desktop OpenGL does not allow that.
+ */
+MOZ_BEGIN_ENUM_CLASS(WebGLVertexAttrib0Status, int)
+    Default, // default status - no emulation needed
+    EmulatedUninitializedArray, // need an artificial attrib 0 array, but contents may be left uninitialized
+    EmulatedInitializedArray // need an artificial attrib 0 array, and contents must be initialized
+MOZ_END_ENUM_CLASS(WebGLVertexAttrib0Status)
 
 /*
  * Enum to track the status of image data (renderbuffer or texture image) presence
  * and initialization.
  *
  * - NoImageData is the initial state before any image data is allocated.
  * - InitializedImageData is the state after image data is allocated and initialized.
  * - UninitializedImageData is an intermediate state where data is allocated but not