diff --git a/content/canvas/src/WebGLContext.cpp b/content/canvas/src/WebGLContext.cpp index 922e8168801..e23251b5e2c 100644 --- a/content/canvas/src/WebGLContext.cpp +++ b/content/canvas/src/WebGLContext.cpp @@ -156,6 +156,11 @@ WebGLContext::WebGLContext() mStencilWriteMaskFront = 0xffffffff; mStencilWriteMaskBack = 0xffffffff; + mViewportX = 0; + mViewportY = 0; + mViewportWidth = 0; + mViewportHeight = 0; + mScissorTestEnabled = 0; mDitherEnabled = 1; mRasterizerDiscardEnabled = 0; // OpenGL ES 3.0 spec p244 @@ -193,6 +198,7 @@ WebGLContext::WebGLContext() mAlreadyGeneratedWarnings = 0; mAlreadyWarnedAboutFakeVertexAttrib0 = false; + mAlreadyWarnedAboutViewportLargerThanDest = false; mMaxWarnings = Preferences::GetInt("webgl.max-warnings-per-context", 32); if (mMaxWarnings < -1) { @@ -573,6 +579,8 @@ WebGLContext::SetDimensions(int32_t width, int32_t height) mWidth = width; mHeight = height; + mViewportWidth = width; + mViewportHeight = height; mResetLayer = true; mOptionsFrozen = true; diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index e7830532ca0..a6120b04402 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -1136,6 +1136,12 @@ protected: GLint mStencilClearValue; GLfloat mDepthClearValue; + GLint mViewportX; + GLint mViewportY; + GLsizei mViewportWidth; + GLsizei mViewportHeight; + bool mAlreadyWarnedAboutViewportLargerThanDest; + nsCOMPtr mContextRestorer; bool mAllowRestore; bool mContextLossTimerRunning; diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index c8eacad7de1..b3e3cac6eed 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -53,7 +53,7 @@ using namespace mozilla::gfx; static bool BaseTypeAndSizeFromUniformType(GLenum uType, GLenum *baseType, GLint *unitSize); static GLenum InternalFormatForFormatAndType(GLenum format, GLenum type, bool isGLES2); -inline const WebGLRectangleObject *WebGLContext::FramebufferRectangleObject() const { +const WebGLRectangleObject *WebGLContext::FramebufferRectangleObject() const { return mBoundFramebuffer ? mBoundFramebuffer->RectangleObject() : static_cast(this); } @@ -3067,6 +3067,11 @@ WebGLContext::Viewport(GLint x, GLint y, GLsizei width, GLsizei height) MakeContextCurrent(); gl->fViewport(x, y, width, height); + + mViewportX = x; + mViewportY = y; + mViewportWidth = width; + mViewportHeight = height; } void diff --git a/content/canvas/src/WebGLContextVertices.cpp b/content/canvas/src/WebGLContextVertices.cpp index 421037cea81..5b453ac7254 100644 --- a/content/canvas/src/WebGLContextVertices.cpp +++ b/content/canvas/src/WebGLContextVertices.cpp @@ -733,6 +733,20 @@ void WebGLContext::Draw_cleanup() } } } + + // Let's check the viewport + const WebGLRectangleObject* rect = FramebufferRectangleObject(); + if (rect) { + if (mViewportWidth > rect->Width() || + mViewportHeight > rect->Height()) + { + if (!mAlreadyWarnedAboutViewportLargerThanDest) { + GenerateWarning("Drawing to a destination rect smaller than the viewport rect. " + "(This warning will only be given once)"); + mAlreadyWarnedAboutViewportLargerThanDest = true; + } + } + } } /*