Bug 635666 - part 2/3 - WebGL crash [@mozilla::WebGLContext::CopyTexSubImage2D] - r=jrmuizel, a=joe
authorBenoit Jacob <bjacob@mozilla.com>
Thu, 24 Feb 2011 17:17:34 -0500
changeset 63068 d5de293a00d1b1e581712e43fb97f3a5ca451a30
parent 63067 f79c1f63133cc1b1b2ca9eff5c848889a0f439d1
child 63069 4654c0c956b29ec71151ecd21b421a3f0438a928
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersjrmuizel, joe
bugs635666
milestone2.0b13pre
Bug 635666 - part 2/3 - WebGL crash [@mozilla::WebGLContext::CopyTexSubImage2D] - r=jrmuizel, a=joe
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -877,16 +877,20 @@ public:
         // no need to check level as a wrong value would be caught by ElementAt().
         return mImageInfos.ElementAt(level * mFacesCount + face);
     }
 
     const ImageInfo& ImageInfoAt(size_t level, size_t face) const {
         return const_cast<WebGLTexture*>(this)->ImageInfoAt(level, face);
     }
 
+    static size_t FaceForTarget(WebGLenum target) {
+        return target == LOCAL_GL_TEXTURE_2D ? 0 : target - LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+    }
+
 protected:
 
     WebGLenum mTarget;
     WebGLenum mMinFilter, mMagFilter, mWrapS, mWrapT;
 
     size_t mFacesCount, mMaxLevelWithCustomImages;
     nsTArray<ImageInfo> mImageInfos;
 
@@ -967,24 +971,22 @@ public:
                 mContext->gl->fTexParameteri(mTarget, LOCAL_GL_TEXTURE_WRAP_R, LOCAL_GL_CLAMP_TO_EDGE);
         }
 
         mHasEverBeenBound = PR_TRUE;
     }
 
     void SetImageInfo(WebGLenum aTarget, WebGLint aLevel,
                       WebGLsizei aWidth, WebGLsizei aHeight,
-                      WebGLenum aFormat = 0, WebGLenum aType = 0) {
-        size_t face = 0;
-        if (aTarget == LOCAL_GL_TEXTURE_2D) {
-            if (mTarget != LOCAL_GL_TEXTURE_2D) return;
-        } else {
-            if (mTarget == LOCAL_GL_TEXTURE_2D) return;
-            face = aTarget - LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;
-        }
+                      WebGLenum aFormat = 0, WebGLenum aType = 0)
+    {
+        if ( (aTarget == LOCAL_GL_TEXTURE_2D) != (mTarget == LOCAL_GL_TEXTURE_2D) )
+            return;
+
+        size_t face = FaceForTarget(aTarget);
 
         EnsureMaxLevelWithCustomImagesAtLeast(aLevel);
 
         ImageInfo& imageInfo = ImageInfoAt(aLevel, face);
         imageInfo.mWidth  = aWidth;
         imageInfo.mHeight = aHeight;
         if (aFormat)
             imageInfo.mFormat = aFormat;
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -803,26 +803,27 @@ WebGLContext::CopyTexSubImage2D(WebGLenu
 
     if (xoffset < 0 || yoffset < 0)
         return ErrorInvalidValue("copyTexSubImage2D: xoffset and yoffset may not be negative");
 
     WebGLTexture *tex = activeBoundTextureForTarget(target);
     if (!tex)
         return ErrorInvalidOperation("copyTexSubImage2D: no texture bound to this target");
 
-    WebGLsizei texWidth = tex->ImageInfoAt(level,0).mWidth;
-    WebGLsizei texHeight = tex->ImageInfoAt(level,0).mHeight;
+    WebGLint face = WebGLTexture::FaceForTarget(target);
+    WebGLsizei texWidth = tex->ImageInfoAt(level, face).mWidth;
+    WebGLsizei texHeight = tex->ImageInfoAt(level, face).mHeight;
 
     if (xoffset + width > texWidth || xoffset + width < 0)
       return ErrorInvalidValue("copyTexSubImage2D: xoffset+width is too large");
 
     if (yoffset + height > texHeight || yoffset + height < 0)
       return ErrorInvalidValue("copyTexSubImage2D: yoffset+height is too large");
 
-    WebGLenum format = tex->ImageInfoAt(level,0).mFormat;
+    WebGLenum format = tex->ImageInfoAt(level, face).mFormat;
     PRBool texFormatRequiresAlpha = format == LOCAL_GL_RGBA ||
                                     format == LOCAL_GL_ALPHA ||
                                     format == LOCAL_GL_LUMINANCE_ALPHA;
     PRBool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment().HasAlpha()
                                                  : PRBool(gl->ActualFormat().alpha > 0);
 
     if (texFormatRequiresAlpha && !fboFormatHasAlpha)
         return ErrorInvalidOperation("copyTexSubImage2D: texture format requires an alpha channel "