From d97c2034f7d0aa88fbe176d0a2d0d7ed33ce4f99 Mon Sep 17 00:00:00 2001 From: Chris Lord Date: Fri, 3 Oct 2014 13:22:32 +1300 Subject: [PATCH] Bug 1006797 - Only apply the window render offset when actually rendering to the window. r=nical --- gfx/layers/opengl/CompositingRenderTargetOGL.cpp | 3 ++- gfx/layers/opengl/CompositingRenderTargetOGL.h | 4 +++- gfx/layers/opengl/CompositorOGL.cpp | 14 +++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gfx/layers/opengl/CompositingRenderTargetOGL.cpp b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp index f56881cb2693..2f75e6649baa 100644 --- a/gfx/layers/opengl/CompositingRenderTargetOGL.cpp +++ b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp @@ -92,6 +92,8 @@ CompositingRenderTargetOGL::InitializeImpl() NS_ERROR(msg.get()); } + mInitParams.mStatus = InitParams::INITIALIZED; + mCompositor->PrepareViewport(mInitParams.mSize); mGL->fScissor(0, 0, mInitParams.mSize.width, mInitParams.mSize.height); if (mInitParams.mInit == INIT_MODE_CLEAR) { @@ -99,7 +101,6 @@ CompositingRenderTargetOGL::InitializeImpl() mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT); } - mInitParams.mStatus = InitParams::INITIALIZED; } } diff --git a/gfx/layers/opengl/CompositingRenderTargetOGL.h b/gfx/layers/opengl/CompositingRenderTargetOGL.h index a08066ff4140..76186da9c7ce 100644 --- a/gfx/layers/opengl/CompositingRenderTargetOGL.h +++ b/gfx/layers/opengl/CompositingRenderTargetOGL.h @@ -84,7 +84,7 @@ public: const gfx::IntSize& aSize) { RefPtr result - = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(0, 0), 0, 0); + = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(), 0, 0); result->mInitParams = InitParams(aSize, 0, INIT_MODE_NONE); result->mInitParams.mStatus = InitParams::INITIALIZED; return result.forget(); @@ -112,6 +112,8 @@ public: */ void BindRenderTarget(); + bool IsWindow() { return GetFBO() == 0; } + GLuint GetFBO() const { MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp index 8202261bc626..6c4c09b04ee8 100644 --- a/gfx/layers/opengl/CompositorOGL.cpp +++ b/gfx/layers/opengl/CompositorOGL.cpp @@ -593,7 +593,10 @@ CompositorOGL::PrepareViewport(const gfx::IntSize& aSize) viewMatrix.PreScale(1.0f, -1.0f); } - if (!mTarget) { + MOZ_ASSERT(mCurrentRenderTarget, "No destination"); + // If we're drawing directly to the window then we want to offset + // drawing by the render offset. + if (!mTarget && mCurrentRenderTarget->IsWindow()) { viewMatrix.PreTranslate(mRenderOffset.x, mRenderOffset.y); } @@ -660,8 +663,8 @@ CompositorOGL::SetRenderTarget(CompositingRenderTarget *aSurface) CompositingRenderTargetOGL* surface = static_cast(aSurface); if (mCurrentRenderTarget != surface) { - surface->BindRenderTarget(); mCurrentRenderTarget = surface; + surface->BindRenderTarget(); } } @@ -1019,9 +1022,14 @@ CompositorOGL::DrawQuad(const Rect& aRect, js::ProfileEntry::Category::GRAPHICS); MOZ_ASSERT(mFrameInProgress, "frame not started"); + MOZ_ASSERT(mCurrentRenderTarget, "No destination"); Rect clipRect = aClipRect; - if (!mTarget) { + // aClipRect is in destination coordinate space (after all + // transforms and offsets have been applied) so if our + // drawing is going to be shifted by mRenderOffset then we need + // to shift the clip rect by the same amount. + if (!mTarget && mCurrentRenderTarget->IsWindow()) { clipRect.MoveBy(mRenderOffset.x, mRenderOffset.y); } IntRect intClipRect;