Bug 1372912 - Extract a PushLayerClip helper method. r?jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 15 Jun 2017 17:02:12 -0400
changeset 594983 a9ea6675c59642476587c1275a0bcaf6f60f704e
parent 594944 75be6742abb94d79f3bcb731ab7fafa3d42ac4da
child 594984 37386a6d16f51351a0ab60a8c7ce0734b5ecf48b
push id64210
push userkgupta@mozilla.com
push dateThu, 15 Jun 2017 21:03:35 +0000
reviewersjrmuizel
bugs1372912
milestone56.0a1
Bug 1372912 - Extract a PushLayerClip helper method. r?jrmuizel No functional changes. We'll want to reuse this code in a future patch. MozReview-Commit-ID: LEuP38yXBHI
gfx/layers/wr/ScrollingLayersHelper.cpp
gfx/layers/wr/ScrollingLayersHelper.h
--- a/gfx/layers/wr/ScrollingLayersHelper.cpp
+++ b/gfx/layers/wr/ScrollingLayersHelper.cpp
@@ -54,29 +54,18 @@ ScrollingLayersHelper::ScrollingLayersHe
         aStackingContext.ToRelativeWrRect(contentRect),
         aStackingContext.ToRelativeWrRect(clipBounds));
   }
 
   // The scrolled clip on the layer is "inside" all of the scrollable metadatas
   // on that layer. That is, the clip scrolls along with the content in
   // child layers. So we need to apply this after pushing all the scroll layers,
   // which we do above.
-  if (Maybe<LayerClip> scrolledClip = layer->GetScrolledClip()) {
-    LayerRect clipRect = IntRectToRect(ViewAs<LayerPixel>(
-        scrolledClip->GetClipRect(),
-        PixelCastJustification::MovingDownToChildren));
-    Maybe<WrImageMask> mask;
-    if (Maybe<size_t> maskLayerIndex = scrolledClip->GetMaskLayerIndex()) {
-      Layer* maskLayer = layer->GetAncestorMaskLayerAt(maskLayerIndex.value());
-      WebRenderLayer* maskWrLayer = WebRenderLayer::ToWebRenderLayer(maskLayer);
-      // TODO: check this transform is correct in all cases
-      mask = maskWrLayer->RenderMaskLayer(aStackingContext, maskLayer->GetTransform());
-    }
-    mBuilder->PushClip(aStackingContext.ToRelativeWrRect(clipRect),
-        mask.ptrOr(nullptr));
+  if (const Maybe<LayerClip>& scrolledClip = layer->GetScrolledClip()) {
+    PushLayerClip(scrolledClip.ref(), aStackingContext);
   }
 
   // If the layer is marked as fixed-position, it is fixed relative to something
   // (the scroll layer referred to by GetFixedPositionScrollContainerId, hereafter
   // referred to as the "scroll container"). What this really means is that we
   // don't want this content to scroll with any scroll layer on the stack up to
   // and including the scroll container, but we do want it to scroll with any
   // ancestor scroll layers. So we do a PushClipAndScrollInfo that maintains
@@ -109,16 +98,32 @@ ScrollingLayersHelper::PushLayerLocalCli
     Maybe<WrImageMask> mask = mLayer->BuildWrMaskLayer(aStackingContext);
     LayerRect clipRect = ViewAs<LayerPixel>(clip.ref(),
         PixelCastJustification::MovingDownToChildren);
     mBuilder->PushClip(aStackingContext.ToRelativeWrRect(clipRect), mask.ptrOr(nullptr));
     mPushedLayerLocalClip = true;
   }
 }
 
+void
+ScrollingLayersHelper::PushLayerClip(const LayerClip& aClip,
+                                     const StackingContextHelper& aSc)
+{
+  LayerRect clipRect = IntRectToRect(ViewAs<LayerPixel>(aClip.GetClipRect(),
+        PixelCastJustification::MovingDownToChildren));
+  Maybe<WrImageMask> mask;
+  if (Maybe<size_t> maskLayerIndex = aClip.GetMaskLayerIndex()) {
+    Layer* maskLayer = mLayer->GetLayer()->GetAncestorMaskLayerAt(maskLayerIndex.value());
+    WebRenderLayer* maskWrLayer = WebRenderLayer::ToWebRenderLayer(maskLayer);
+    // TODO: check this transform is correct in all cases
+    mask = maskWrLayer->RenderMaskLayer(aSc, maskLayer->GetTransform());
+  }
+  mBuilder->PushClip(aSc.ToRelativeWrRect(clipRect), mask.ptrOr(nullptr));
+}
+
 ScrollingLayersHelper::~ScrollingLayersHelper()
 {
   Layer* layer = mLayer->GetLayer();
   if (mPushedLayerLocalClip) {
     mBuilder->PopClip();
   }
   if (!mLayer->WrManager()->AsyncPanZoomEnabled()) {
     return;
--- a/gfx/layers/wr/ScrollingLayersHelper.h
+++ b/gfx/layers/wr/ScrollingLayersHelper.h
@@ -11,29 +11,32 @@
 namespace mozilla {
 
 namespace wr {
 class DisplayListBuilder;
 }
 
 namespace layers {
 
+struct LayerClip;
 class StackingContextHelper;
 class WebRenderLayer;
 
 class MOZ_RAII ScrollingLayersHelper
 {
 public:
   ScrollingLayersHelper(WebRenderLayer* aLayer,
                         wr::DisplayListBuilder& aBuilder,
                         const StackingContextHelper& aSc);
   ~ScrollingLayersHelper();
 
 private:
   void PushLayerLocalClip(const StackingContextHelper& aStackingContext);
+  void PushLayerClip(const LayerClip& aClip,
+                     const StackingContextHelper& aSc);
 
   WebRenderLayer* mLayer;
   wr::DisplayListBuilder* mBuilder;
   bool mPushedLayerLocalClip;
 };
 
 } // namespace layers
 } // namespace mozilla