Bug 1465618 draft
authorKashav Madan <kmadan@mozilla.com>
Fri, 20 Jul 2018 15:10:49 -0400
changeset 821024 1f825b24db51f58ab06d74a461ad88b8234a70e8
parent 821023 cd8671232fd851520c6e7a5619b65b420984cfa7
child 821025 9418aed138d11aaab9ff9fd2105648a536bda125
push id116994
push userbmo:kmadan@mozilla.com
push dateFri, 20 Jul 2018 19:32:49 +0000
bugs1465618
milestone63.0a1
Bug 1465618
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -3807,23 +3807,24 @@ AsyncTransform
 AsyncPanZoomController::GetCurrentAsyncTransform(AsyncTransformConsumer aMode) const
 {
   RecursiveMutexAutoLock lock(mRecursiveMutex);
 
   if (aMode == eForCompositing && mScrollMetadata.IsApzForceDisabled()) {
     return AsyncTransform();
   }
 
+  // TODO: use AutoAsyncPanZoomController here
+
   CSSPoint lastPaintScrollOffset;
   if (mLastContentPaintMetrics.IsScrollable()) {
     lastPaintScrollOffset = mLastContentPaintMetrics.GetScrollOffset();
   }
 
-  CSSPoint currentScrollOffset = GetEffectiveScrollOffset(aMode) +
-    mTestAsyncScrollOffset;
+  CSSPoint currentScrollOffset = GetEffectiveScrollOffset(aMode);
 
   // If checkerboarding has been disallowed, clamp the scroll position to stay
   // within rendered content.
   if (!gfxPrefs::APZAllowCheckerboarding() &&
       !mLastContentPaintMetrics.GetDisplayPort().IsEmpty()) {
     CSSSize compositedSize = mLastContentPaintMetrics.CalculateCompositedSizeInCssPixels();
     CSSPoint maxScrollOffset = lastPaintScrollOffset +
       CSSPoint(mLastContentPaintMetrics.GetDisplayPort().XMost() - compositedSize.width,
@@ -3834,25 +3835,22 @@ AsyncPanZoomController::GetCurrentAsyncT
       currentScrollOffset.x = clamped(currentScrollOffset.x, minScrollOffset.x, maxScrollOffset.x);
     }
     if (minScrollOffset.y < maxScrollOffset.y) {
       currentScrollOffset.y = clamped(currentScrollOffset.y, minScrollOffset.y, maxScrollOffset.y);
     }
   }
 
   CSSToParentLayerScale2D effectiveZoom = GetEffectiveZoom(aMode);
-
-  ParentLayerPoint translation = (currentScrollOffset - lastPaintScrollOffset)
-                               * effectiveZoom * mTestAsyncZoom.scale;
-
+  ParentLayerPoint translation =
+    (currentScrollOffset - lastPaintScrollOffset) * effectiveZoom;
   LayerToParentLayerScale compositedAsyncZoom =
-      (effectiveZoom / mFrameMetrics.LayersPixelsPerCSSPixel()).ToScaleFactor();
-  return AsyncTransform(
-    LayerToParentLayerScale(compositedAsyncZoom.scale * mTestAsyncZoom.scale),
-    -translation);
+    (effectiveZoom / mFrameMetrics.LayersPixelsPerCSSPixel()).ToScaleFactor();
+
+  return AsyncTransform(compositedAsyncZoom, -translation);
 }
 
 CSSRect
 AsyncPanZoomController::GetEffectiveLayoutViewport(AsyncTransformConsumer aMode) const
 {
   if (gfxPrefs::APZFrameDelayEnabled() && aMode == eForCompositing) {
     return mCompositedLayoutViewport;
   }
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -512,16 +512,47 @@ public:
    */
   CSSCoord ConvertScrollbarPoint(const ParentLayerPoint& aScrollbarPoint,
                                  const ScrollbarData& aThumbData) const;
 
   void NotifyMozMouseScrollEvent(const nsString& aString) const;
 
   bool OverscrollBehaviorAllowsSwipe() const;
 
+  class AutoAsyncPanZoomController {
+  public:
+    AutoAsyncPanZoomController(AsyncPanZoomController *aApzc)
+      : mApzc(aApzc)
+      , mPrevFrameMetrics(aApzc->mFrameMetrics)
+      , mPrevCompositedLayoutViewport(aApzc->mCompositedLayoutViewport)
+      , mPrevCompositedScrollOffset(aApzc->mCompositedScrollOffset)
+      , mPrevCompositedZoom(aApzc->mCompositedZoom) {
+      if (aApzc->mTestAsyncScrollOffset == CSSPoint() &&
+          aApzc->mTestAsyncZoom == LayerToParentLayerScale()) {
+        // XXX: what do we do here?
+      }
+      mApzc->mFrameMetrics.ScrollBy(aApzc->mTestAsyncScrollOffset);
+      mApzc->mFrameMetrics.ZoomBy(aApzc->mTestAsyncZoom.scale);
+      mApzc->mFrameMetrics.RecalculateViewportOffset();
+      mApzc->SampleCompositedAsyncTransform();
+    }
+    ~AutoAsyncPanZoomController() {
+      mApzc->mFrameMetrics = mPrevFrameMetrics;
+      mApzc->mCompositedLayoutViewport = mPrevCompositedLayoutViewport;
+      mApzc->mCompositedScrollOffset = mPrevCompositedScrollOffset;
+      mApzc->mCompositedZoom = mPrevCompositedZoom;
+    }
+  private:
+    AsyncPanZoomController* mApzc;
+    FrameMetrics mPrevFrameMetrics;
+    CSSRect mPrevCompositedLayoutViewport;
+    CSSPoint mPrevCompositedScrollOffset;
+    CSSToParentLayerScale2D mPrevCompositedZoom;
+  };
+
 private:
   // Get whether the horizontal content of the honoured target of auto-dir
   // scrolling starts from right to left. If you don't know of auto-dir
   // scrolling or what a honoured target means,
   // @see mozilla::WheelDeltaAdjustmentStrategy
   bool IsContentOfHonouredTargetRightToLeft(bool aHonoursRoot) const;
 
 protected: