Bug 1359842 - Do some cleanup of GetWrClipRect. r? draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 26 Apr 2017 12:45:41 -0400
changeset 568833 9dcc152b2e5f0a15c30a3c3c94bd84967c6392c0
parent 568832 81864f98bc0cab66422d0a610e4be446b9f51956
child 568834 a11de355757e0a38ea6a953d5e9275c9eb877772
push id55994
push userkgupta@mozilla.com
push dateWed, 26 Apr 2017 16:46:17 +0000
bugs1359842
milestone55.0a1
Bug 1359842 - Do some cleanup of GetWrClipRect. r? This extracts a strongly-typed ClipRect() function from GetWrClipRect. GetWrClipRect is left as a weakly-typed wrapper for existing call sites, and also does the necessary reference point conversions. MozReview-Commit-ID: EuyzYIYLR6S
gfx/layers/wr/WebRenderLayer.cpp
gfx/layers/wr/WebRenderLayer.h
--- a/gfx/layers/wr/WebRenderLayer.cpp
+++ b/gfx/layers/wr/WebRenderLayer.cpp
@@ -126,28 +126,21 @@ WebRenderLayer::GetWrBoundsRect()
 {
   LayerIntRect bounds = GetLayer()->GetVisibleRegion().GetBounds();
   return Rect(0, 0, bounds.width, bounds.height);
 }
 
 gfx::Rect
 WebRenderLayer::GetWrClipRect(gfx::Rect& aRect)
 {
-  gfx::Rect clip;
-  Layer* layer = GetLayer();
-  Matrix4x4 transform = layer->GetTransform();
-  if (layer->GetClipRect().isSome()) {
-    clip = RelativeToVisible(transform.Inverse().TransformBounds(
-             IntRectToRect(layer->GetClipRect().ref().ToUnknownRect()))
-           );
-  } else {
-    clip = aRect;
+  Maybe<LayerRect> clip = ClipRect();
+  if (clip) {
+    return RelativeToVisible(clip.ref().ToUnknownRect());
   }
-
-  return clip;
+  return aRect;
 }
 
 LayerRect
 WebRenderLayer::Bounds()
 {
   return LayerRect(GetLayer()->GetVisibleRegion().GetBounds());
 }
 
@@ -169,16 +162,28 @@ WebRenderLayer::BoundsForStackingContext
   if (!transform.IsIdentity()) {
     // WR will only apply the 'translate' of the transform, so we need to do the scale/rotation manually.
     bounds.MoveTo(transform.TransformPoint(bounds.TopLeft()));
   }
 
   return bounds;
 }
 
+Maybe<LayerRect>
+WebRenderLayer::ClipRect()
+{
+  Layer* layer = GetLayer();
+  if (!layer->GetClipRect()) {
+    return Nothing();
+  }
+  ParentLayerRect clip(layer->GetClipRect().ref());
+  LayerToParentLayerMatrix4x4 transform = layer->GetLocalTransformTyped();
+  return Some(transform.Inverse().TransformBounds(clip));
+}
+
 gfx::Rect
 WebRenderLayer::GetWrRelBounds()
 {
   return RelativeToParent(BoundsForStackingContext().ToUnknownRect());
 }
 
 Maybe<wr::ImageKey>
 WebRenderLayer::UpdateImageKey(ImageClientSingle* aImageClient,
--- a/gfx/layers/wr/WebRenderLayer.h
+++ b/gfx/layers/wr/WebRenderLayer.h
@@ -52,16 +52,17 @@ public:
   gfx::Rect RelativeToParent(gfx::Rect aRect);
   gfx::Rect VisibleBoundsRelativeToParent();
   gfx::Point GetOffsetToParent();
   gfx::Rect TransformedVisibleBoundsRelativeToParent();
 protected:
   LayerRect Bounds();
   BoundsTransformMatrix BoundsTransform();
   LayerRect BoundsForStackingContext();
+  Maybe<LayerRect> ClipRect();
 
   gfx::Rect GetWrBoundsRect();
   gfx::Rect GetWrRelBounds();
   gfx::Rect GetWrClipRect(gfx::Rect& aRect);
   void DumpLayerInfo(const char* aLayerType, gfx::Rect& aRect);
   Maybe<WrImageMask> BuildWrMaskLayer(bool aUnapplyLayerTransform);
 };