diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 41058893e84..955f319e75d 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -885,7 +885,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(WebGLBuffer, WEBGLBUFFER_PRIVATE_IID) class WebGLTexture : public nsIWebGLTexture, public WebGLZeroingObject, - public WebGLRectangleObject, public WebGLContextBoundObject { public: @@ -1595,6 +1594,7 @@ protected: NS_DEFINE_STATIC_IID_ACCESSOR(WebGLRenderbuffer, WEBGLRENDERBUFFER_PRIVATE_IID) class WebGLFramebufferAttachment + : public WebGLRectangleObject { // deleting a texture or renderbuffer immediately detaches it WebGLObjectRefPtr mTexturePtr; @@ -1630,10 +1630,17 @@ public: mRenderbufferPtr = nsnull; mTextureLevel = level; mTextureCubeMapFace = face; + if (tex) { + const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(level, face); + setDimensions(imageInfo.mWidth, imageInfo.mHeight); + } else { + setDimensions(0, 0); + } } void SetRenderbuffer(WebGLRenderbuffer *rb) { mTexturePtr = nsnull; mRenderbufferPtr = rb; + setDimensions(rb); } WebGLTexture *Texture() const { return mTexturePtr.get(); @@ -1683,7 +1690,6 @@ public: class WebGLFramebuffer : public nsIWebGLFramebuffer, public WebGLZeroingObject, - public WebGLRectangleObject, public WebGLContextBoundObject { public: @@ -1708,6 +1714,9 @@ public: PRBool HasEverBeenBound() { return mHasEverBeenBound; } void SetHasEverBeenBound(PRBool x) { mHasEverBeenBound = x; } WebGLuint GLName() { return mName; } + + WebGLsizei width() { return mColorAttachment.width(); } + WebGLsizei height() { return mColorAttachment.height(); } nsresult FramebufferRenderbuffer(WebGLenum target, WebGLenum attachment, @@ -1744,11 +1753,7 @@ public: // finish checking that the 'attachment' parameter is among the allowed values if (attachment != LOCAL_GL_COLOR_ATTACHMENT0) return mContext->ErrorInvalidEnumInfo("framebufferRenderbuffer: attachment", attachment); - if (!isNull) { - // ReadPixels needs alpha and size information, but only - // for COLOR_ATTACHMENT0 - setDimensions(wrb); - } + mColorAttachment.SetRenderbuffer(wrb); break; } @@ -1783,15 +1788,15 @@ public: if (target != LOCAL_GL_FRAMEBUFFER) return mContext->ErrorInvalidEnumInfo("framebufferTexture2D: target", target); - if (!isNull && textarget != LOCAL_GL_TEXTURE_2D && + if (textarget != LOCAL_GL_TEXTURE_2D && (textarget < LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X || - textarget > LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)) + textarget > LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)) return mContext->ErrorInvalidEnumInfo("framebufferTexture2D: invalid texture target", textarget); - if (!isNull && level > 0) + if (level != 0) return mContext->ErrorInvalidValue("framebufferTexture2D: level must be 0"); - WebGLint face = (textarget == LOCAL_GL_TEXTURE_2D) ? 0 : textarget; + size_t face = WebGLTexture::FaceForTarget(textarget); switch (attachment) { case LOCAL_GL_DEPTH_ATTACHMENT: mDepthAttachment.SetTexture(wtex, level, face); @@ -1806,9 +1811,6 @@ public: if (attachment != LOCAL_GL_COLOR_ATTACHMENT0) return mContext->ErrorInvalidEnumInfo("framebufferTexture2D: attachment", attachment); - // keep data for readPixels, function only uses COLOR_ATTACHMENT0 - setDimensions(wtex); - mColorAttachment.SetTexture(wtex, level, face); break; } @@ -1851,13 +1853,15 @@ public: // some attachment is incompatible with its attachment point return PR_TRUE; } - else if (int(mDepthAttachment.IsNull()) + - int(mStencilAttachment.IsNull()) + - int(mDepthStencilAttachment.IsNull()) <= 1) + + if (int(mDepthAttachment.IsNull()) + + int(mStencilAttachment.IsNull()) + + int(mDepthStencilAttachment.IsNull()) <= 1) { // has at least two among Depth, Stencil, DepthStencil return PR_TRUE; } + else return PR_FALSE; } diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index 9a6ab3b87dd..9048f36ca12 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -4363,7 +4363,6 @@ WebGLContext::TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum intern } tex->SetImageInfo(target, level, width, height, format, type); - tex->setDimensions(width, height); return NS_OK; } @@ -4507,10 +4506,11 @@ WebGLContext::TexSubImage2D_base(WebGLenum target, WebGLint level, if (!tex) return ErrorInvalidOperation("texSubImage2D: no texture is bound to this target"); - if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height, tex->width(), tex->height())) + size_t face = WebGLTexture::FaceForTarget(target); + const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(level, face); + if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height, imageInfo.mWidth, imageInfo.mHeight)) return ErrorInvalidValue("texSubImage2D: subtexture rectangle out of bounds"); - MakeContextCurrent(); int dstFormat = GetWebGLTexelFormat(format, type);