Remove Compositor::mRenderBounds. (bug 1243071 part 1, r=mattwoodrow)
authorDavid Anderson <danderson@mozilla.com>
Mon, 01 Feb 2016 16:27:38 -0800
changeset 282653 975654b9b3d80a11d881b0e2cc249791bf27b59c
parent 282652 b789994819cb5240309979ee4630529976c12b61
child 282654 53ddcd8fee2647d0fc447791ec35236d220c2924
push id17362
push usercbook@mozilla.com
push dateTue, 02 Feb 2016 10:54:53 +0000
treeherderfx-team@e5f1b4782e38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1243071
milestone47.0a1
Remove Compositor::mRenderBounds. (bug 1243071 part 1, r=mattwoodrow)
gfx/layers/Compositor.cpp
gfx/layers/Compositor.h
gfx/layers/opengl/CompositorOGL.cpp
--- a/gfx/layers/Compositor.cpp
+++ b/gfx/layers/Compositor.cpp
@@ -352,33 +352,47 @@ DecomposeIntoNoRepeatRects(const gfx::Re
            0.0f, 0.0f, br.x, br.y,
            flipped);
   return 4;
 }
 
 gfx::IntRect
 Compositor::ComputeBackdropCopyRect(const gfx::Rect& aRect,
                                     const gfx::Rect& aClipRect,
-                                    const gfx::Matrix4x4& aTransform)
+                                    const gfx::Matrix4x4& aTransform,
+                                    gfx::Matrix4x4* aOutTransform)
 {
-  gfx::Rect renderBounds = mRenderBounds;
+  // Compute the clip.
+  gfx::IntPoint rtOffset = GetCurrentRenderTarget()->GetOrigin();
+  gfx::IntSize rtSize = GetCurrentRenderTarget()->GetSize();
 
-  // Compute the clip.
-  gfx::IntPoint offset = GetCurrentRenderTarget()->GetOrigin();
+  gfx::Rect renderBounds(0, 0, rtSize.width, rtSize.height);
   renderBounds.IntersectRect(renderBounds, aClipRect);
-  renderBounds.MoveBy(offset);
+  renderBounds.MoveBy(rtOffset);
 
   // Apply the layer transform.
   gfx::Rect dest = aTransform.TransformAndClipBounds(aRect, renderBounds);
-  dest -= offset;
+  dest -= rtOffset;
+
+  // Ensure we don't round out to -1, which trips up Direct3D.
+  dest.IntersectRect(dest, gfx::Rect(0, 0, rtSize.width, rtSize.height));
 
   // Round out to integer.
   gfx::IntRect result;
   dest.RoundOut();
   dest.ToIntRect(&result);
+
+  // Create a transform from adjusted clip space to render target space,
+  // translate it for the backdrop rect, then transform it into the backdrop's
+  // uv-space.
+  gfx::Matrix4x4 transform;
+  transform.PostScale(rtSize.width, rtSize.height, 1.0);
+  transform.PostTranslate(-result.x, -result.y, 0.0);
+  transform.PostScale(1 / float(result.width), 1 / float(result.height), 1.0);
+  *aOutTransform = transform;
   return result;
 }
 
 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
 void
 Compositor::SetDispAcquireFence(Layer* aLayer, nsIWidget* aWidget)
 {
   // OpenGL does not provide ReleaseFence for rendering.
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -547,18 +547,16 @@ protected:
   size_t mPixelsPerFrame;
   size_t mPixelsFilled;
 
   ScreenRotation mScreenRotation;
 
   RefPtr<gfx::DrawTarget> mTarget;
   gfx::IntRect mTargetBounds;
 
-  gfx::Rect mRenderBounds;
-
 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
   FenceHandle mReleaseFenceHandle;
 #endif
 
 private:
   static LayersBackend sBackend;
 
 };
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -481,18 +481,16 @@ void
 CompositorOGL::PrepareViewport(CompositingRenderTargetOGL* aRenderTarget)
 {
   MOZ_ASSERT(aRenderTarget);
   const gfx::IntSize& size = aRenderTarget->mInitParams.mSize;
 
   // Set the viewport correctly.
   mGLContext->fViewport(0, 0, size.width, size.height);
 
-  mRenderBounds = Rect(0, 0, size.width, size.height);
-
   mViewportSize = size;
 
   if (!aRenderTarget->HasComplexProjection()) {
     // We flip the view matrix around so that everything is right-side up; we're
     // drawing directly into the window's back buffer, so this keeps things
     // looking correct.
     // XXX: We keep track of whether the window size changed, so we could skip
     // this update if it hadn't changed since the last call.
@@ -1002,31 +1000,34 @@ CompositorOGL::DrawQuad(const Rect& aRec
   MOZ_ASSERT(mCurrentRenderTarget, "No destination");
 
   if (aEffectChain.mPrimaryEffect->mType == EffectTypes::VR_DISTORTION) {
     DrawVRDistortion(aRect, aClipRect, aEffectChain, aOpacity, aTransform);
     return;
   }
 
   IntPoint offset = mCurrentRenderTarget->GetOrigin();
-  Rect renderBound = mRenderBounds;
+  IntSize size = mCurrentRenderTarget->GetSize();
+
+  Rect renderBound(0, 0, size.width, size.height);
   renderBound.IntersectRect(renderBound, aClipRect);
   renderBound.MoveBy(offset);
 
   Rect destRect = aTransform.TransformAndClipBounds(aRect, renderBound);
 
   // XXX: This doesn't handle 3D transforms. It also doesn't handled rotated
   //      quads. Fix me.
   mPixelsFilled += destRect.width * destRect.height;
 
   // Do a simple culling if this rect is out of target buffer.
   // Inflate a small size to avoid some numerical imprecision issue.
   destRect.Inflate(1, 1);
   destRect.MoveBy(-offset);
-  if (!mRenderBounds.Intersects(destRect)) {
+  renderBound = Rect(0, 0, size.width, size.height);
+  if (!renderBound.Intersects(destRect)) {
     return;
   }
 
   LayerScope::DrawBegin();
 
   Rect clipRect = aClipRect;
   // aClipRect is in destination coordinate space (after all
   // transforms and offsets have been applied) so if our