Bug 1359842 - Do some cleanup of GetWrClipRect. r=nical
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 27 Apr 2017 12:04:12 -0400
changeset 355193 b80b628fc84df643068842f246856b668c19a696
parent 355192 69e23059260ef8a43bcbb97cc958f9502a5ffd31
child 355194 3d7c750e62c7f376b10c27c07c21512d3158de24
push id31723
push userkwierso@gmail.com
push dateThu, 27 Apr 2017 18:22:49 +0000
treeherdermozilla-central@c5c2b95e9d7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1359842
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359842 - Do some cleanup of GetWrClipRect. r=nical 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);
 };