Bug 1509552 - MobileViewportManager::UpdateResolution cleanup, part 2. r=kats
authorBotond Ballo <botond@mozilla.com>
Fri, 30 Nov 2018 00:56:49 +0000
changeset 505341 8085138baf577e8f849155ab743a9376e5c9e2cd
parent 505340 3cdb29bf81f0e5074e3f4708158333c285299a59
child 505342 038125c617dca34532412d7d641306c73c011150
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1509552
milestone65.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 1509552 - MobileViewportManager::UpdateResolution cleanup, part 2. r=kats * Call SetResolutionAndScaleTo() in just one place * Call UpdateVisualViewportSize() in UpdateResolution() rather than requiring the caller to do it (and on non-first paints, only call it if the resolution has actually changed) Differential Revision: https://phabricator.services.mozilla.com/D13313
layout/base/MobileViewportManager.cpp
layout/base/MobileViewportManager.h
--- a/layout/base/MobileViewportManager.cpp
+++ b/layout/base/MobileViewportManager.cpp
@@ -234,26 +234,27 @@ static LayoutDeviceToLayerScale
 ZoomToResolution(CSSToScreenScale aZoom,
                  CSSToLayoutDeviceScale aCssToDev)
 {
   return ViewTargetAs<ParentLayerPixel>(aZoom,
       PixelCastJustification::ScreenIsParentLayerForRoot)
     / aCssToDev * ParentLayerToLayerScale(1);
 }
 
-CSSToScreenScale
+void
 MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
                                         const ScreenIntSize& aDisplaySize,
                                         const CSSSize& aViewport,
                                         const Maybe<float>& aDisplayWidthChangeRatio)
 {
   CSSToLayoutDeviceScale cssToDev =
       mPresShell->GetPresContext()->CSSToDevPixelScale();
   LayoutDeviceToLayerScale res(mPresShell->GetResolution());
   CSSToScreenScale zoom = ResolutionToZoom(res, cssToDev);
+  Maybe<CSSToScreenScale> newZoom;
 
   if (mIsFirstPaint) {
     ScreenIntSize compositionSize = GetCompositionSize(aDisplaySize);
 
     CSSToScreenScale defaultZoom;
     if (mRestoreResolution) {
       LayoutDeviceToLayerScale restoreResolution(mRestoreResolution.value());
       CSSToScreenScale restoreZoom = ResolutionToZoom(restoreResolution, cssToDev);
@@ -278,57 +279,60 @@ MobileViewportManager::UpdateResolution(
         defaultZoom = ComputeIntrinsicScale(aViewportInfo,
                                             compositionSize,
                                             aViewport);
       }
     }
     MOZ_ASSERT(aViewportInfo.GetMinZoom() <= defaultZoom &&
       defaultZoom <= aViewportInfo.GetMaxZoom());
 
-    zoom = defaultZoom;
+    // On first paint, we always consider the zoom to have changed.
+    newZoom = Some(defaultZoom);
+  } else {
+    // If this is not a first paint, then in some cases we want to update the pre-
+    // existing resolution so as to maintain how much actual content is visible
+    // within the display width. Note that "actual content" may be different with
+    // respect to CSS pixels because of the CSS viewport size changing.
+    //
+    // aDisplayWidthChangeRatio is non-empty if:
+    // (a) The meta-viewport tag information changes, and so the CSS viewport
+    //     might change as a result. If this happens after the content has been
+    //     painted, we want to adjust the zoom to compensate. OR
+    // (b) The display size changed from a nonzero value to another nonzero value.
+    //     This covers the case where e.g. the device was rotated, and again we
+    //     want to adjust the zoom to compensate.
+    // Note in particular that aDisplayWidthChangeRatio will be None if all that
+    // happened was a change in the full-zoom. In this case, we still want to
+    // compute a new CSS viewport, but we don't want to update the resolution.
+    //
+    // Given the above, the algorithm below accounts for all types of changes I
+    // can conceive of:
+    // 1. screen size changes, CSS viewport does not (pages with no meta viewport
+    //    or a fixed size viewport)
+    // 2. screen size changes, CSS viewport also does (pages with a device-width
+    //    viewport)
+    // 3. screen size remains constant, but CSS viewport changes (meta viewport
+    //    tag is added or removed)
+    // 4. neither screen size nor CSS viewport changes
+    if (aDisplayWidthChangeRatio) {
+      newZoom = Some(ScaleZoomWithDisplayWidth(zoom, aDisplayWidthChangeRatio.value(),
+        aViewport, mMobileViewportSize));
+    }
+  }
 
-    LayoutDeviceToLayerScale resolution = ZoomToResolution(zoom, cssToDev);
+  // If the zoom has changed, update the pres shell resolution and the
+  // visual viewport size accordingly.
+  if (newZoom) {
+    LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev);
     MVM_LOG("%p: setting resolution %f\n", this, resolution.scale);
     mPresShell->SetResolutionAndScaleTo(resolution.scale);
 
-    return zoom;
+    MVM_LOG("%p: New zoom is %f\n", this, newZoom->scale);
+    UpdateVisualViewportSize(aDisplaySize, *newZoom);
   }
-
-  // If this is not a first paint, then in some cases we want to update the pre-
-  // existing resolution so as to maintain how much actual content is visible
-  // within the display width. Note that "actual content" may be different with
-  // respect to CSS pixels because of the CSS viewport size changing.
-  //
-  // aDisplayWidthChangeRatio is non-empty if:
-  // (a) The meta-viewport tag information changes, and so the CSS viewport
-  //     might change as a result. If this happens after the content has been
-  //     painted, we want to adjust the zoom to compensate. OR
-  // (b) The display size changed from a nonzero value to another nonzero value.
-  //     This covers the case where e.g. the device was rotated, and again we
-  //     want to adjust the zoom to compensate.
-  // Note in particular that aDisplayWidthChangeRatio will be None if all that
-  // happened was a change in the full-zoom. In this case, we still want to
-  // compute a new CSS viewport, but we don't want to update the resolution.
-  //
-  // Given the above, the algorithm below accounts for all types of changes I
-  // can conceive of:
-  // 1. screen size changes, CSS viewport does not (pages with no meta viewport
-  //    or a fixed size viewport)
-  // 2. screen size changes, CSS viewport also does (pages with a device-width
-  //    viewport)
-  // 3. screen size remains constant, but CSS viewport changes (meta viewport
-  //    tag is added or removed)
-  // 4. neither screen size nor CSS viewport changes
-  if (aDisplayWidthChangeRatio) {
-    zoom = ScaleZoomWithDisplayWidth(zoom, aDisplayWidthChangeRatio.value(),
-      aViewport, mMobileViewportSize);
-    mPresShell->SetResolutionAndScaleTo(ZoomToResolution(zoom, cssToDev).scale);
-  }
-
-  return zoom;
 }
 
 
 ScreenIntSize
 MobileViewportManager::GetCompositionSize(const ScreenIntSize& aDisplaySize) const
 {
   ScreenIntSize compositionSize(aDisplaySize);
   ScreenMargin scrollbars =
@@ -458,20 +462,17 @@ MobileViewportManager::RefreshViewportSi
   }
 
   // If it's the first-paint or the viewport changed, we need to update
   // various APZ properties (the zoom and some things that might depend on it)
   MVM_LOG("%p: Updating properties because %d || %d\n", this,
     mIsFirstPaint, mMobileViewportSize != viewport);
 
   if (gfxPrefs::APZAllowZooming()) {
-    CSSToScreenScale zoom = UpdateResolution(viewportInfo, displaySize, viewport,
-      displayWidthChangeRatio);
-    MVM_LOG("%p: New zoom is %f\n", this, zoom.scale);
-    UpdateVisualViewportSize(displaySize, zoom);
+    UpdateResolution(viewportInfo, displaySize, viewport, displayWidthChangeRatio);
   }
   if (gfxPlatform::AsyncPanZoomEnabled()) {
     UpdateDisplayPortMargins();
   }
 
   CSSSize oldSize = mMobileViewportSize;
 
   // Update internal state.
@@ -512,15 +513,11 @@ MobileViewportManager::ShrinkToDisplaySi
 
   nsIScrollableFrame* rootScrollableFrame =
     mPresShell->GetRootScrollFrameAsScrollable();
   if (rootScrollableFrame) {
     nsRect scrollableRect =
       nsLayoutUtils::CalculateScrollableRectForFrame(rootScrollableFrame,
                                                      nullptr);
     CSSSize contentSize = CSSSize::FromAppUnits(scrollableRect.Size());
-    CSSToScreenScale zoom =
-      UpdateResolution(aViewportInfo, aDisplaySize, contentSize, Nothing());
-
-    MVM_LOG("%p: Adapted zoom is %f\n", this, zoom.scale);
-    UpdateVisualViewportSize(aDisplaySize, zoom);
+    UpdateResolution(aViewportInfo, aDisplaySize, contentSize, Nothing());
   }
 }
--- a/layout/base/MobileViewportManager.h
+++ b/layout/base/MobileViewportManager.h
@@ -88,21 +88,21 @@ public:
 
   /* Helper to update the given zoom according to changed display and viewport widths. */
   mozilla::CSSToScreenScale
   ScaleZoomWithDisplayWidth(const mozilla::CSSToScreenScale& aZoom,
                             const float& aDisplayWidthChangeRatio,
                             const mozilla::CSSSize& aNewViewport,
                             const mozilla::CSSSize& aOldViewport);
 
-  /* Updates the presShell resolution and returns the new zoom. */
-  mozilla::CSSToScreenScale UpdateResolution(const nsViewportInfo& aViewportInfo,
-                                             const mozilla::ScreenIntSize& aDisplaySize,
-                                             const mozilla::CSSSize& aViewport,
-                                             const mozilla::Maybe<float>& aDisplayWidthChangeRatio);
+  /* Updates the presShell resolution and the visual viewport size. */
+  void UpdateResolution(const nsViewportInfo& aViewportInfo,
+                        const mozilla::ScreenIntSize& aDisplaySize,
+                        const mozilla::CSSSize& aViewport,
+                        const mozilla::Maybe<float>& aDisplayWidthChangeRatio);
 
   void UpdateVisualViewportSize(const mozilla::ScreenIntSize& aDisplaySize,
                                 const mozilla::CSSToScreenScale& aZoom);
 
   /* Updates the displayport margins for the presShell's root scrollable frame */
   void UpdateDisplayPortMargins();
 
   /* Helper function for ComputeIntrinsicResolution(). */