Bug 1639825 - Some minor code reorganization. r=tnikkel
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 22 May 2020 14:37:06 +0000
changeset 531624 cd4b7928b25c5ffe59863139e5e440fbc31f084a
parent 531623 dcf166da7a8bad96946df5d46b9f4beff8ce46f9
child 531625 3d89891d5670bbc1b25a60d2f70d2e0ccf017c77
push id37441
push userapavel@mozilla.com
push dateFri, 22 May 2020 21:38:53 +0000
treeherdermozilla-central@d6abd35b54ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1639825
milestone78.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 1639825 - Some minor code reorganization. r=tnikkel This makes it more obvious that we are using the same scrollDelta for adjusting the displayport as we are for populating the callback transform. Instead of computing the same value inside a helper, we just provide the helper with the already-computed delta that is used for the callback transform too. Differential Revision: https://phabricator.services.mozilla.com/D76297
gfx/layers/apz/util/APZCCallbackHelper.cpp
gfx/layers/apz/util/APZCCallbackHelper.h
layout/base/nsLayoutUtils.cpp
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -42,26 +42,22 @@ namespace mozilla {
 namespace layers {
 
 using dom::BrowserParent;
 
 uint64_t APZCCallbackHelper::sLastTargetAPZCNotificationInputBlock =
     uint64_t(-1);
 
 ScreenMargin APZCCallbackHelper::AdjustDisplayPortForScrollDelta(
-    const RepaintRequest& aRequest, const CSSPoint& aActualScrollOffset) {
-  // Correct the display-port by the difference between the requested scroll
-  // offset and the resulting scroll offset after setting the requested value.
-  ScreenPoint shift = (aRequest.GetScrollOffset() - aActualScrollOffset) *
-                      aRequest.DisplayportPixelsPerCSSPixel();
-  ScreenMargin margins = aRequest.GetDisplayPortMargins();
-  margins.left -= shift.x;
-  margins.right += shift.x;
-  margins.top -= shift.y;
-  margins.bottom += shift.y;
+    ScreenMargin aMargins, ScreenPoint aScrollDelta) {
+  ScreenMargin margins = aMargins;
+  margins.left -= aScrollDelta.x;
+  margins.right += aScrollDelta.x;
+  margins.top -= aScrollDelta.y;
+  margins.bottom += aScrollDelta.y;
   return margins;
 }
 
 static ScreenMargin RecenterDisplayPort(const ScreenMargin& aDisplayPort) {
   ScreenMargin margins = aDisplayPort;
   margins.right = margins.left = margins.LeftRight() / 2;
   margins.top = margins.bottom = margins.TopBottom() / 2;
   return margins;
@@ -179,46 +175,48 @@ static ScreenMargin ScrollFrame(nsIConte
         }
       }
     }
   }
   bool scrollUpdated = false;
   ScreenMargin displayPortMargins = aRequest.GetDisplayPortMargins();
   CSSPoint apzScrollOffset = aRequest.GetScrollOffset();
   CSSPoint actualScrollOffset = ScrollFrameTo(sf, aRequest, scrollUpdated);
+  CSSPoint scrollDelta = apzScrollOffset - actualScrollOffset;
 
   if (scrollUpdated) {
     if (aRequest.IsScrollInfoLayer()) {
       // In cases where the APZ scroll offset is different from the content
       // scroll offset, we want to interpret the margins as relative to the APZ
       // scroll offset except when the frame is not scrollable by APZ.
       // Therefore, if the layer is a scroll info layer, we leave the margins
       // as-is and they will be interpreted as relative to the content scroll
       // offset.
       if (nsIFrame* frame = aContent->GetPrimaryFrame()) {
         frame->SchedulePaint();
       }
     } else {
-      // Correct the display port due to the difference between mScrollOffset
-      // and the actual scroll offset.
+      // Correct the display port due to the difference between the requested
+      // and actual scroll offsets.
       displayPortMargins = APZCCallbackHelper::AdjustDisplayPortForScrollDelta(
-          aRequest, actualScrollOffset);
+          aRequest.GetDisplayPortMargins(),
+          scrollDelta * aRequest.DisplayportPixelsPerCSSPixel());
     }
   } else if (aRequest.IsRootContent() &&
-             aRequest.GetScrollOffset() !=
-                 aRequest.GetLayoutViewport().TopLeft()) {
+             apzScrollOffset != aRequest.GetLayoutViewport().TopLeft()) {
     // APZ uses the visual viewport's offset to calculate where to place the
     // display port, so the display port is misplaced when a pinch zoom occurs.
     //
     // We need to force a display port adjustment in the following paint to
-    // account for a difference between mScrollOffset and the actual scroll
-    // offset in repaints requested by
+    // account for a difference between the requested and actual scroll
+    // offsets in repaints requested by
     // AsyncPanZoomController::NotifyLayersUpdated.
     displayPortMargins = APZCCallbackHelper::AdjustDisplayPortForScrollDelta(
-        aRequest, actualScrollOffset);
+        aRequest.GetDisplayPortMargins(),
+        scrollDelta * aRequest.DisplayportPixelsPerCSSPixel());
   } else {
     // For whatever reason we couldn't update the scroll offset on the scroll
     // frame, which means the data APZ used for its displayport calculation is
     // stale. Fall back to a sane default behaviour. Note that we don't
     // tile-align the recentered displayport because tile-alignment depends on
     // the scroll position, and the scroll position here is out of our control.
     // See bug 966507 comment 21 for a more detailed explanation.
     displayPortMargins = RecenterDisplayPort(aRequest.GetDisplayPortMargins());
@@ -233,17 +231,16 @@ static ScreenMargin ScrollFrame(nsIConte
   // input events by a large amount. It is also going to be transient, because
   // any main-thread scroll position change will be synced to APZ and we will
   // get another repaint request when APZ confirms. In the interval while this
   // is happening we can just leave the callback transform as it was.
   bool mainThreadScrollChanged =
       sf && sf->CurrentScrollGeneration() != aRequest.GetScrollGeneration() &&
       nsLayoutUtils::CanScrollOriginClobberApz(sf->LastScrollOrigin());
   if (aContent && !mainThreadScrollChanged) {
-    CSSPoint scrollDelta = apzScrollOffset - actualScrollOffset;
     aContent->SetProperty(nsGkAtoms::apzCallbackTransform,
                           new CSSPoint(scrollDelta),
                           nsINode::DeleteProperty<CSSPoint>);
   }
 
   return displayPortMargins;
 }
 
--- a/gfx/layers/apz/util/APZCCallbackHelper.h
+++ b/gfx/layers/apz/util/APZCCallbackHelper.h
@@ -167,18 +167,21 @@ class APZCCallbackHelper {
       ScrollDirection aDirection);
   static void NotifyAsyncScrollbarDragRejected(
       const ScrollableLayerGuid::ViewID& aScrollId);
   static void NotifyAsyncAutoscrollRejected(
       const ScrollableLayerGuid::ViewID& aScrollId);
 
   static void CancelAutoscroll(const ScrollableLayerGuid::ViewID& aScrollId);
 
-  static ScreenMargin AdjustDisplayPortForScrollDelta(
-      const RepaintRequest& aRequest, const CSSPoint& aActualScrollOffset);
+  /* Adjust the display-port margins by the difference between the requested
+   * scroll offset and the resulting scroll offset after setting the requested
+   * value. */
+  static ScreenMargin AdjustDisplayPortForScrollDelta(ScreenMargin aMargins,
+                                                      ScreenPoint aScrollDelta);
 
   /*
    * Check if the scrollable frame is currently in the middle of an async
    * or smooth scroll. We want to discard certain scroll input if this is
    * true to prevent clobbering higher priority origins.
    */
   static bool IsScrollInProgress(nsIScrollableFrame* aFrame);
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9690,19 +9690,21 @@ static void UpdateDisplayPortMarginsForP
       static_cast<DisplayPortMarginsPropertyData*>(
           content->GetProperty(nsGkAtoms::DisplayPortMargins));
   if (!currentData) {
     return;
   }
 
   CSSPoint frameScrollOffset =
       CSSPoint::FromAppUnits(frame->GetScrollPosition());
+  CSSPoint scrollDelta = aMetrics.GetScrollOffset() - frameScrollOffset;
   ScreenMargin displayPortMargins =
-      APZCCallbackHelper::AdjustDisplayPortForScrollDelta(aMetrics,
-                                                          frameScrollOffset);
+      APZCCallbackHelper::AdjustDisplayPortForScrollDelta(
+          aMetrics.GetDisplayPortMargins(),
+          scrollDelta * aMetrics.DisplayportPixelsPerCSSPixel());
 
   nsLayoutUtils::SetDisplayPortMargins(content, presShell, displayPortMargins,
                                        0);
 }
 
 /* static */
 void nsLayoutUtils::UpdateDisplayPortMarginsFromPendingMessages() {
   if (XRE_IsContentProcess() && mozilla::layers::CompositorBridgeChild::Get() &&