Bug 1544218 - part 1: Make mozilla::layers::GetPresShell() in APZCCallbackHelper.cpp return mozilla::PresShell directly r=kats
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 16 Apr 2019 04:32:34 +0000
changeset 469609 2a5c7852f148
parent 469608 c918588ff945
child 469610 06908f47b337
push id35876
push useropoprus@mozilla.com
push dateTue, 16 Apr 2019 09:47:48 +0000
treeherdermozilla-central@fe4a28a68cfc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1544218, 1543315
milestone68.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 1544218 - part 1: Make mozilla::layers::GetPresShell() in APZCCallbackHelper.cpp return mozilla::PresShell directly r=kats And this patch makes it return raw pointer. The safeness of the pointer should be managed by `MOZ_CAN_RUN_SCRIPT` since incrementing refcount in hot path is bad for performance. So, it should be followed by bug 1543315. Differential Revision: https://phabricator.services.mozilla.com/D27471
gfx/layers/apz/util/APZCCallbackHelper.cpp
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -66,22 +66,21 @@ ScreenMargin APZCCallbackHelper::AdjustD
 
 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;
 }
 
-static already_AddRefed<nsIPresShell> GetPresShell(const nsIContent* aContent) {
-  nsCOMPtr<nsIPresShell> result;
+static PresShell* GetPresShell(const nsIContent* aContent) {
   if (dom::Document* doc = aContent->GetComposedDoc()) {
-    result = doc->GetPresShell();
+    return doc->GetPresShell();
   }
-  return result.forget();
+  return nullptr;
 }
 
 static CSSPoint ScrollFrameTo(nsIScrollableFrame* aFrame,
                               const RepaintRequest& aRequest,
                               bool& aSuccessOut) {
   aSuccessOut = false;
   CSSPoint targetScrollPosition = aRequest.IsRootContent()
                                       ? aRequest.GetLayoutViewport().TopLeft()
@@ -170,20 +169,20 @@ static ScreenMargin ScrollFrame(nsIConte
   // Scroll the window to the desired spot
   nsIScrollableFrame* sf =
       nsLayoutUtils::FindScrollableFrameFor(aRequest.GetScrollId());
   if (sf) {
     sf->ResetScrollInfoIfGeneration(aRequest.GetScrollGeneration());
     sf->SetScrollableByAPZ(!aRequest.IsScrollInfoLayer());
     if (sf->IsRootScrollFrameOfDocument()) {
       if (!APZCCallbackHelper::IsScrollInProgress(sf)) {
-        if (nsCOMPtr<nsIPresShell> shell = GetPresShell(aContent)) {
-          if (shell->SetVisualViewportOffset(
+        if (RefPtr<PresShell> presShell = GetPresShell(aContent)) {
+          if (presShell->SetVisualViewportOffset(
                   CSSPoint::ToAppUnits(aRequest.GetScrollOffset()),
-                  shell->GetLayoutViewportOffset())) {
+                  presShell->GetLayoutViewportOffset())) {
             sf->MarkEverScrolled();
           }
         }
       }
     }
   }
   bool scrollUpdated = false;
   ScreenMargin displayPortMargins = aRequest.GetDisplayPortMargins();
@@ -298,91 +297,91 @@ void APZCCallbackHelper::UpdateRootFrame
   if (aRequest.GetScrollId() == ScrollableLayerGuid::NULL_SCROLL_ID) {
     return;
   }
   nsIContent* content = nsLayoutUtils::FindContentFor(aRequest.GetScrollId());
   if (!content) {
     return;
   }
 
-  nsCOMPtr<nsIPresShell> shell = GetPresShell(content);
-  if (!shell || aRequest.GetPresShellId() != shell->GetPresShellId()) {
+  RefPtr<PresShell> presShell = GetPresShell(content);
+  if (!presShell || aRequest.GetPresShellId() != presShell->GetPresShellId()) {
     return;
   }
 
-  if (nsLayoutUtils::AllowZoomingForDocument(shell->GetDocument()) &&
+  if (nsLayoutUtils::AllowZoomingForDocument(presShell->GetDocument()) &&
       aRequest.GetScrollOffsetUpdated()) {
     // If zooming is disabled then we don't really want to let APZ fiddle
     // with these things. In theory setting the resolution here should be a
     // no-op, but setting the visual viewport size is bad because it can cause a
     // stale value to be returned by window.innerWidth/innerHeight (see bug
     // 1187792).
     //
     // We also skip this codepath unless the metrics has a scroll offset update
     // type other eNone, because eNone just means that this repaint request
     // was triggered by APZ in response to a main-thread update. In this
     // scenario we don't want to update the main-thread resolution because
     // it can trigger unnecessary reflows.
 
-    float presShellResolution = shell->GetResolution();
+    float presShellResolution = presShell->GetResolution();
 
     // If the pres shell resolution has changed on the content side side
     // the time this repaint request was fired, consider this request out of
     // date and drop it; setting a zoom based on the out-of-date resolution can
     // have the effect of getting us stuck with the stale resolution.
     if (!FuzzyEqualsMultiplicative(presShellResolution,
                                    aRequest.GetPresShellResolution())) {
       return;
     }
 
     // The pres shell resolution is updated by the the async zoom since the
     // last paint.
     presShellResolution =
         aRequest.GetPresShellResolution() * aRequest.GetAsyncZoom().scale;
-    shell->SetResolutionAndScaleTo(presShellResolution,
+    presShell->SetResolutionAndScaleTo(presShellResolution,
                                    nsIPresShell::ChangeOrigin::eApz);
   }
 
   // Do this as late as possible since scrolling can flush layout. It also
   // adjusts the display port margins, so do it before we set those.
   ScreenMargin displayPortMargins = ScrollFrame(content, aRequest);
 
-  SetDisplayPortMargins(shell, content, displayPortMargins,
+  SetDisplayPortMargins(presShell, content, displayPortMargins,
                         aRequest.CalculateCompositedSizeInCssPixels());
   SetPaintRequestTime(content, aRequest.GetPaintRequestTime());
 }
 
 void APZCCallbackHelper::UpdateSubFrame(const RepaintRequest& aRequest) {
   if (aRequest.GetScrollId() == ScrollableLayerGuid::NULL_SCROLL_ID) {
     return;
   }
   nsIContent* content = nsLayoutUtils::FindContentFor(aRequest.GetScrollId());
   if (!content) {
     return;
   }
 
   // We don't currently support zooming for subframes, so nothing extra
   // needs to be done beyond the tasks common to this and UpdateRootFrame.
   ScreenMargin displayPortMargins = ScrollFrame(content, aRequest);
-  if (nsCOMPtr<nsIPresShell> shell = GetPresShell(content)) {
-    SetDisplayPortMargins(shell, content, displayPortMargins,
+  if (RefPtr<PresShell> presShell = GetPresShell(content)) {
+    SetDisplayPortMargins(presShell, content, displayPortMargins,
                           aRequest.CalculateCompositedSizeInCssPixels());
   }
   SetPaintRequestTime(content, aRequest.GetPaintRequestTime());
 }
 
 bool APZCCallbackHelper::GetOrCreateScrollIdentifiers(
     nsIContent* aContent, uint32_t* aPresShellIdOut,
     ScrollableLayerGuid::ViewID* aViewIdOut) {
   if (!aContent) {
     return false;
   }
   *aViewIdOut = nsLayoutUtils::FindOrCreateIDFor(aContent);
-  if (nsCOMPtr<nsIPresShell> shell = GetPresShell(aContent)) {
-    *aPresShellIdOut = shell->GetPresShellId();
+  if (PresShell* presShell = GetPresShell(aContent)) {
+    *aPresShellIdOut = presShell->GetPresShellId();
     return true;
   }
   return false;
 }
 
 void APZCCallbackHelper::InitializeRootDisplayport(nsIPresShell* aPresShell) {
   // Create a view-id and set a zero-margin displayport for the root element
   // of the root document in the chrome process. This ensures that the scroll