Bug 1389138 - Extract a helper PushScrollLayer method. r=mstange draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 17 Aug 2017 11:06:12 -0400
changeset 648482 99f77b7629ab39e78316fc890ea3253ce51f8732
parent 648384 e365137fa61bfd729617ba1ebf9f1ed79facd1f2
child 648483 f2f80e89a400d5b9982d138b29e534701b247072
push id74768
push userkgupta@mozilla.com
push dateThu, 17 Aug 2017 20:14:33 +0000
reviewersmstange
bugs1389138
milestone57.0a1
Bug 1389138 - Extract a helper PushScrollLayer method. r=mstange MozReview-Commit-ID: CqKOvxWCWZE
gfx/layers/wr/ScrollingLayersHelper.cpp
gfx/layers/wr/ScrollingLayersHelper.h
--- a/gfx/layers/wr/ScrollingLayersHelper.cpp
+++ b/gfx/layers/wr/ScrollingLayersHelper.cpp
@@ -46,39 +46,17 @@ ScrollingLayersHelper::ScrollingLayersHe
     if (layer->GetIsFixedPosition() &&
         layer->GetFixedPositionScrollContainerId() == fm.GetScrollId()) {
       // If the layer contents are fixed for this metadata onwards, we need
       // to insert the layer's local clip at this point in the clip tree,
       // as a child of whatever's on the stack.
       PushLayerLocalClip(aStackingContext);
     }
 
-    if (!fm.IsScrollable()) {
-      continue;
-    }
-    LayerRect contentRect = ViewAs<LayerPixel>(
-        fm.GetExpandedScrollableRect() * fm.GetDevPixelsPerCSSPixel(),
-        PixelCastJustification::WebRenderHasUnitResolution);
-    // TODO: check coordinate systems are sane here
-    LayerRect clipBounds = ViewAs<LayerPixel>(
-        fm.GetCompositionBounds(),
-        PixelCastJustification::MovingDownToChildren);
-    // The content rect that we hand to PushScrollLayer should be relative to
-    // the same origin as the clipBounds that we hand to PushScrollLayer - that
-    // is, both of them should be relative to the stacking context `aStackingContext`.
-    // However, when we get the scrollable rect from the FrameMetrics, the origin
-    // has nothing to do with the position of the frame but instead represents
-    // the minimum allowed scroll offset of the scrollable content. While APZ
-    // uses this to clamp the scroll position, we don't need to send this to
-    // WebRender at all. Instead, we take the position from the composition
-    // bounds.
-    contentRect.MoveTo(clipBounds.TopLeft());
-    mBuilder->PushScrollLayer(fm.GetScrollId(),
-        aStackingContext.ToRelativeLayoutRect(contentRect),
-        aStackingContext.ToRelativeLayoutRect(clipBounds));
+    PushScrollLayer(fm, aStackingContext);
   }
 
   // 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 (const Maybe<LayerClip>& scrolledClip = layer->GetScrolledClip()) {
     PushLayerClip(scrolledClip.ref(), aStackingContext);
@@ -158,16 +136,46 @@ ScrollingLayersHelper::DefineAndPushChai
     aCache[aChain] = clipId.value();
   }
   // Finally, push the clip onto the WR stack
   MOZ_ASSERT(clipId);
   aBuilder.PushClip(clipId.value());
   mClipsPushed++;
 }
 
+bool
+ScrollingLayersHelper::PushScrollLayer(const FrameMetrics& aMetrics,
+                                       const StackingContextHelper& aStackingContext)
+{
+  if (!aMetrics.IsScrollable()) {
+    return false;
+  }
+  LayerRect contentRect = ViewAs<LayerPixel>(
+      aMetrics.GetExpandedScrollableRect() * aMetrics.GetDevPixelsPerCSSPixel(),
+      PixelCastJustification::WebRenderHasUnitResolution);
+  // TODO: check coordinate systems are sane here
+  LayerRect clipBounds = ViewAs<LayerPixel>(
+      aMetrics.GetCompositionBounds(),
+      PixelCastJustification::MovingDownToChildren);
+  // The content rect that we hand to PushScrollLayer should be relative to
+  // the same origin as the clipBounds that we hand to PushScrollLayer - that
+  // is, both of them should be relative to the stacking context `aStackingContext`.
+  // However, when we get the scrollable rect from the FrameMetrics, the origin
+  // has nothing to do with the position of the frame but instead represents
+  // the minimum allowed scroll offset of the scrollable content. While APZ
+  // uses this to clamp the scroll position, we don't need to send this to
+  // WebRender at all. Instead, we take the position from the composition
+  // bounds.
+  contentRect.MoveTo(clipBounds.TopLeft());
+  mBuilder->PushScrollLayer(aMetrics.GetScrollId(),
+      aStackingContext.ToRelativeLayoutRect(contentRect),
+      aStackingContext.ToRelativeLayoutRect(clipBounds));
+  return true;
+}
+
 void
 ScrollingLayersHelper::PushLayerLocalClip(const StackingContextHelper& aStackingContext)
 {
   Layer* layer = mLayer->GetLayer();
   Maybe<ParentLayerRect> clip;
   if (const Maybe<ParentLayerIntRect>& rect = layer->GetClipRect()) {
     clip = Some(IntRectToRect(rect.ref()));
   } else if (layer->GetMaskLayer()) {
--- a/gfx/layers/wr/ScrollingLayersHelper.h
+++ b/gfx/layers/wr/ScrollingLayersHelper.h
@@ -14,16 +14,17 @@ namespace mozilla {
 struct DisplayItemClipChain;
 
 namespace wr {
 class DisplayListBuilder;
 }
 
 namespace layers {
 
+struct FrameMetrics;
 struct LayerClip;
 class StackingContextHelper;
 class WebRenderLayer;
 
 class MOZ_RAII ScrollingLayersHelper
 {
 public:
   ScrollingLayersHelper(WebRenderLayer* aLayer,
@@ -36,16 +37,18 @@ public:
   ~ScrollingLayersHelper();
 
 private:
   void DefineAndPushChain(const DisplayItemClipChain* aChain,
                           wr::DisplayListBuilder& aBuilder,
                           const StackingContextHelper& aStackingContext,
                           int32_t aAppUnitsPerDevPixel,
                           WebRenderLayerManager::ClipIdMap& aCache);
+  bool PushScrollLayer(const FrameMetrics& aMetrics,
+                       const StackingContextHelper& aStackingContext);
   void PushLayerLocalClip(const StackingContextHelper& aStackingContext);
   void PushLayerClip(const LayerClip& aClip,
                      const StackingContextHelper& aSc);
 
   WebRenderLayer* mLayer;
   wr::DisplayListBuilder* mBuilder;
   bool mPushedLayerLocalClip;
   int mClipsPushed;