Bug 1361357 - Try fixing clip on WRDILayer. r?ethlin draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 02 May 2017 11:52:18 -0400
changeset 571428 83e2803c176356d0bb049f862e62a8b27fb4af31
parent 571427 04d2ecd0b0f7f097550c81b57b4756b84f16444c
child 626757 919ab03dd52286fb2f38f3645ae745e627574a0e
push id56785
push userkgupta@mozilla.com
push dateTue, 02 May 2017 15:52:31 +0000
reviewersethlin
bugs1361357
milestone55.0a1
Bug 1361357 - Try fixing clip on WRDILayer. r?ethlin This should fix some wrong-looking code that computes the clip for WebRenderDisplayItemLayer instances. As this code is not exercised very much it's hard to know if this change is actually correct. MozReview-Commit-ID: C8f4vEdIb33
gfx/layers/wr/WebRenderDisplayItemLayer.cpp
--- a/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
@@ -35,20 +35,34 @@ WebRenderDisplayItemLayer::RenderLayer(w
 {
   if (mVisibleRegion.IsEmpty()) {
     return;
   }
 
   Maybe<WrImageMask> mask = BuildWrMaskLayer(nullptr);
   WrImageMask* imageMask = mask.ptrOr(nullptr);
   if (imageMask) {
-    gfx::Rect rect = GetTransform().TransformBounds(Bounds().ToUnknownRect());
-    // XXX: this is probably not correct, see bug 1361357
-    gfx::Rect clip(0.0, 0.0, rect.width, rect.height);
-    aBuilder.PushClip(wr::ToWrRect(clip), imageMask);
+    ParentLayerRect clip = GetLocalTransformTyped().TransformBounds(Bounds());
+    // As with WebRenderTextLayer, I'm not 100% sure this is correct, but I
+    // think it is. Because we don't push a stacking context for this layer,
+    // WR doesn't know about the transform on this layer. The display items
+    // that we push as part of this layer already take the transform into
+    // account. When we set the clip rect we also need to explicitly apply
+    // the transform to make sure it gets taken into account.
+    // In a sense this is the opposite of what WebRenderLayer::ClipRect() does,
+    // because there we remove the transform from the clip rect to bring it
+    // into the coordinate space of the local stacking context, but here we
+    // need to apply the transform to the bounds to take it into the coordinate
+    // space of the enclosing stacking context.
+    // The conversion from ParentLayerPixel to LayerPixel below is a result of
+    // changing the reference layer from "this layer" to the "the layer that
+    // created aSc".
+    LayerRect clipInParentLayerSpace = ViewAs<LayerPixel>(clip,
+        PixelCastJustification::MovingDownToChildren);
+    aBuilder.PushClip(aSc.ToRelativeWrRect(clipInParentLayerSpace), imageMask);
   }
 
   if (mItem) {
     wr::DisplayListBuilder builder(WrBridge()->GetPipeline());
     // We might have recycled this layer. Throw away the old commands.
     mParentCommands.Clear();
     mItem->CreateWebRenderCommands(builder, aSc, mParentCommands, this);
     mBuiltDisplayList = builder.Finalize();