Bug 1350643 - Part 7: Remove sync GetDPI/DefaultScale/WidgetRounding. Use primary screen's value until RecvShow. r=kanru
authorSamael Wang <freesamael@gmail.com>
Fri, 19 May 2017 18:20:18 +0800
changeset 612398 b43d89d13360fcdbee0a034eebc308e67c71cf52
parent 612397 9fe134e61ce15c2c75a486e36ecfd43c60dd1f88
child 612399 327ab38679196ba30e6b5698beeeff3bada6d877
push id69481
push userbmo:emilio+bugs@crisal.io
push dateThu, 20 Jul 2017 17:15:44 +0000
reviewerskanru
bugs1350643
milestone56.0a1
Bug 1350643 - Part 7: Remove sync GetDPI/DefaultScale/WidgetRounding. Use primary screen's value until RecvShow. r=kanru MozReview-Commit-ID: GlDMNecWp3j
dom/base/nsFrameLoader.cpp
dom/ipc/ContentChild.cpp
dom/ipc/PBrowser.ipdl
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
gfx/src/nsDeviceContext.cpp
ipc/ipdl/sync-messages.ini
widget/PuppetWidget.cpp
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -2721,16 +2721,21 @@ nsFrameLoader::GetWindowDimensions(nsInt
 }
 
 NS_IMETHODIMP
 nsFrameLoader::UpdatePositionAndSize(nsSubDocumentFrame *aIFrame)
 {
   if (IsRemoteFrame()) {
     if (mRemoteBrowser) {
       ScreenIntSize size = aIFrame->GetSubdocumentSize();
+      // If we were not able to show remote frame before, we should probably
+      // retry now to send correct showInfo.
+      if (!mRemoteBrowserShown) {
+        ShowRemoteFrame(size, aIFrame);
+      }
       nsIntRect dimensions;
       NS_ENSURE_SUCCESS(GetWindowDimensions(dimensions), NS_ERROR_FAILURE);
       mLazySize = size;
       mRemoteBrowser->UpdateDimensions(dimensions, size);
     }
     return NS_OK;
   }
   UpdateBaseWindowPositionAndSize(aIFrame);
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -1015,18 +1015,19 @@ ContentChild::ProvideWindowCommon(TabChi
 
   ShowInfo showInfo(EmptyString(), false, false, true, false, 0, 0, 0);
   auto* opener = nsPIDOMWindowOuter::From(aParent);
   nsIDocShell* openerShell;
   if (opener && (openerShell = opener->GetDocShell())) {
     nsCOMPtr<nsILoadContext> context = do_QueryInterface(openerShell);
     showInfo = ShowInfo(EmptyString(), false,
                         context->UsePrivateBrowsing(), true, false,
-                        aTabOpener->mDPI, aTabOpener->mRounding,
-                        aTabOpener->mDefaultScale);
+                        aTabOpener->WebWidget()->GetDPI(),
+                        aTabOpener->WebWidget()->RoundsWidgetCoordinatesTo(),
+                        aTabOpener->WebWidget()->GetDefaultScale().scale);
   }
 
   newChild->SetMaxTouchPoints(maxTouchPoints);
 
   // Set the opener window for this window before we start loading the document
   // inside of it. We have to do this before loading the remote scripts, because
   // they can poke at the document and cause the nsDocument to be created before
   // the openerwindow
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -355,31 +355,16 @@ parent:
                                               nsString inputmode,
                                               nsString actionHint,
                                               int32_t cause,
                                               int32_t focusChange);
 
     sync IsParentWindowMainWidgetVisible() returns (bool visible);
 
     /**
-     * Gets the DPI of the screen corresponding to this browser.
-     */
-    sync GetDPI() returns (float value);
-
-    /**
-     * Gets the default scaling factor of the screen corresponding to this browser.
-     */
-    sync GetDefaultScale() returns (double value);
-
-    /**
-     * Gets the rounding of coordinates in the widget.
-     */
-    sync GetWidgetRounding() returns (int32_t value);
-
-    /**
      * Set the native cursor.
      * @param value
      *   The widget cursor to set.
      * @param force
      *   Invalidate any locally cached cursor settings and force an
      *   update.
      */
     async SetCursor(uint32_t value, bool force);
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -385,19 +385,16 @@ TabChild::TabChild(nsIContentChild* aMan
   , mDidFakeShow(false)
   , mNotified(false)
   , mTriedBrowserInit(false)
   , mOrientation(eScreenOrientation_PortraitPrimary)
   , mIgnoreKeyPressEvent(false)
   , mHasValidInnerSize(false)
   , mDestroyed(false)
   , mUniqueId(aTabId)
-  , mDPI(0)
-  , mRounding(0)
-  , mDefaultScale(0)
   , mIsTransparent(false)
   , mIPCOpen(false)
   , mParentIsActive(false)
   , mDidSetRealShowInfo(false)
   , mDidLoadURLInit(false)
   , mAwaitingLA(false)
   , mSkipKeyPress(false)
   , mLayerObserverEpoch(0)
@@ -1130,16 +1127,25 @@ TabChild::DoFakeShow(const TextureFactor
   InitRenderingState(aTextureFactoryIdentifier, aLayersId, aCompositorOptions, aRenderFrame);
   RecvShow(ScreenIntSize(0, 0), aShowInfo, mParentIsActive, nsSizeMode_Normal);
   mDidFakeShow = true;
 }
 
 void
 TabChild::ApplyShowInfo(const ShowInfo& aInfo)
 {
+  // Even if we already set real show info, the dpi / rounding & scale may still
+  // be invalid (if TabParent wasn't able to get widget it would just send 0).
+  // So better to always set up-to-date values here.
+  if (aInfo.dpi() > 0) {
+    mPuppetWidget->UpdateBackingScaleCache(aInfo.dpi(),
+                                           aInfo.widgetRounding(),
+                                           aInfo.defaultScale());
+  }
+
   if (mDidSetRealShowInfo) {
     return;
   }
 
   if (!aInfo.fakeShowInfo()) {
     // Once we've got one ShowInfo from parent, no need to update the values
     // anymore.
     mDidSetRealShowInfo = true;
@@ -1170,19 +1176,16 @@ TabChild::ApplyShowInfo(const ShowInfo& 
         } else {
           OriginAttributes attrs(nsDocShell::Cast(docShell)->GetOriginAttributes());
           attrs.SyncAttributesWithPrivateBrowsing(true);
           nsDocShell::Cast(docShell)->SetOriginAttributes(attrs);
         }
       }
     }
   }
-  mDPI = aInfo.dpi();
-  mRounding = aInfo.widgetRounding();
-  mDefaultScale = aInfo.defaultScale();
   mIsTransparent = aInfo.isTransparent();
 }
 
 mozilla::ipc::IPCResult
 TabChild::RecvShow(const ScreenIntSize& aSize,
                    const ShowInfo& aInfo,
                    const bool& aParentIsActive,
                    const nsSizeMode& aSizeMode)
@@ -2687,66 +2690,16 @@ TabChild::InitAPZState()
   APZChild* apzChild = new APZChild(contentController);
   cbc->SetEventTargetForActor(
     apzChild, TabGroup()->EventTargetFor(TaskCategory::Other));
   MOZ_ASSERT(apzChild->GetActorEventTarget());
   cbc->SendPAPZConstructor(apzChild, mLayersId);
 }
 
 void
-TabChild::GetDPI(float* aDPI)
-{
-    *aDPI = -1.0;
-    if (!(mDidFakeShow || mDidSetRealShowInfo)) {
-        return;
-    }
-
-    if (mDPI > 0) {
-      *aDPI = mDPI;
-      return;
-    }
-
-    // Fallback to a sync call if needed.
-    SendGetDPI(aDPI);
-}
-
-void
-TabChild::GetDefaultScale(double* aScale)
-{
-    *aScale = -1.0;
-    if (!(mDidFakeShow || mDidSetRealShowInfo)) {
-        return;
-    }
-
-    if (mDefaultScale > 0) {
-      *aScale = mDefaultScale;
-      return;
-    }
-
-    // Fallback to a sync call if needed.
-    SendGetDefaultScale(aScale);
-}
-
-void
-TabChild::GetWidgetRounding(int32_t* aRounding)
-{
-  *aRounding = 1;
-  if (!(mDidFakeShow || mDidSetRealShowInfo)) {
-    return;
-  }
-  if (mRounding > 0) {
-    *aRounding = mRounding;
-    return;
-  }
-
-  // Fallback to a sync call if needed.
-  SendGetWidgetRounding(aRounding);
-}
-
-void
 TabChild::NotifyPainted()
 {
     if (!mNotified) {
         mRemoteFrame->SendNotifyCompositorTransaction();
         mNotified = true;
     }
 }
 
@@ -3133,20 +3086,19 @@ TabChild::RecvRequestNotifyAfterRemotePa
 }
 
 mozilla::ipc::IPCResult
 TabChild::RecvUIResolutionChanged(const float& aDpi,
                                   const int32_t& aRounding,
                                   const double& aScale)
 {
   ScreenIntSize oldScreenSize = GetInnerSize();
-  mDPI = 0;
-  mRounding = 0;
-  mDefaultScale = 0;
-  static_cast<PuppetWidget*>(mPuppetWidget.get())->UpdateBackingScaleCache(aDpi, aRounding, aScale);
+  if (aDpi > 0) {
+    mPuppetWidget->UpdateBackingScaleCache(aDpi, aRounding, aScale);
+  }
   nsCOMPtr<nsIDocument> document(GetDocument());
   nsCOMPtr<nsIPresShell> presShell = document->GetShell();
   if (presShell) {
     RefPtr<nsPresContext> presContext = presShell->GetPresContext();
     if (presContext) {
       presContext->UIResolutionChangedSync();
     }
   }
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -497,23 +497,16 @@ public:
 
   virtual nsIWebNavigation* WebNavigation() const override
   {
     return mWebNav;
   }
 
   virtual PuppetWidget* WebWidget() override { return mPuppetWidget; }
 
-  /** Return the DPI of the widget this TabChild draws to. */
-  void GetDPI(float* aDPI);
-
-  void GetDefaultScale(double *aScale);
-
-  void GetWidgetRounding(int32_t* aRounding);
-
   bool IsTransparent() const { return mIsTransparent; }
 
   void GetMaxTouchPoints(uint32_t* aTouchPoints)
   {
     *aTouchPoints = mMaxTouchPoints;
   }
 
   void SetMaxTouchPoints(uint32_t aMaxTouchPoints)
@@ -850,19 +843,16 @@ private:
   LayoutDeviceIntPoint mChromeDisp;
   TabId mUniqueId;
 
   // Holds the compositor options for the compositor rendering this tab,
   // once we find out which compositor that is.
   Maybe<mozilla::layers::CompositorOptions> mCompositorOptions;
 
   friend class ContentChild;
-  float mDPI;
-  int32_t mRounding;
-  double mDefaultScale;
 
   bool mIsTransparent;
 
   bool mIPCOpen;
   bool mParentIsActive;
   CSSSize mUnscaledInnerSize;
   bool mDidSetRealShowInfo;
   bool mDidLoadURLInit;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -2344,49 +2344,16 @@ TabParent::RecvIsParentWindowMainWidgetV
     do_QueryInterface(frame->OwnerDoc()->GetWindow());
   nsresult rv = windowUtils->GetIsParentWindowMainWidgetVisible(aIsVisible);
   if (NS_FAILED(rv)) {
     return IPC_FAIL_NO_REASON(this);
   }
   return IPC_OK();
 }
 
-mozilla::ipc::IPCResult
-TabParent::RecvGetDPI(float* aValue)
-{
-  TryCacheDPIAndScale();
-
-  MOZ_ASSERT(mDPI > 0 || mFrameElement,
-             "Must not ask for DPI before OwnerElement is received!");
-  *aValue = mDPI;
-  return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
-TabParent::RecvGetDefaultScale(double* aValue)
-{
-  TryCacheDPIAndScale();
-
-  MOZ_ASSERT(mDefaultScale.scale > 0 || mFrameElement,
-             "Must not ask for scale before OwnerElement is received!");
-  *aValue = mDefaultScale.scale;
-  return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
-TabParent::RecvGetWidgetRounding(int32_t* aValue)
-{
-  TryCacheDPIAndScale();
-
-  MOZ_ASSERT(mRounding > 0 || mFrameElement,
-             "Must not ask for rounding before OwnerElement is received!");
-  *aValue = mRounding;
-  return IPC_OK();
-}
-
 already_AddRefed<nsIWidget>
 TabParent::GetTopLevelWidget()
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(mFrameElement);
   if (content) {
     nsIPresShell* shell = content->OwnerDoc()->GetShell();
     if (shell) {
       nsViewManager* vm = shell->GetViewManager();
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -294,21 +294,16 @@ public:
 
   virtual mozilla::ipc::IPCResult RecvShowTooltip(const uint32_t& aX,
                                                   const uint32_t& aY,
                                                   const nsString& aTooltip,
                                                   const nsString& aDirection) override;
 
   virtual mozilla::ipc::IPCResult RecvHideTooltip() override;
 
-  virtual mozilla::ipc::IPCResult RecvGetDPI(float* aValue) override;
-
-  virtual mozilla::ipc::IPCResult RecvGetDefaultScale(double* aValue) override;
-
-  virtual mozilla::ipc::IPCResult RecvGetWidgetRounding(int32_t* aValue) override;
 
   virtual mozilla::ipc::IPCResult RecvSetNativeChildOfShareableWindow(const uintptr_t& childWindow) override;
 
   virtual mozilla::ipc::IPCResult RecvDispatchFocusToTopLevelWindow() override;
 
   virtual mozilla::ipc::IPCResult RecvRespondStartSwipeEvent(const uint64_t& aInputBlockId,
                                                              const bool& aStartSwipe) override;
 
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -274,27 +274,37 @@ nsDeviceContext::SetDPI(double* aScale)
 
     // Use the printing DC to determine DPI values, if we have one.
     if (mDeviceContextSpec) {
         dpi = mDeviceContextSpec->GetDPI();
         mPrintingScale = mDeviceContextSpec->GetPrintingScale();
         mAppUnitsPerDevPixelAtUnitFullZoom =
             NS_lround((AppUnitsPerCSSPixel() * 96) / dpi);
     } else {
+        nsCOMPtr<nsIScreen> primaryScreen;
+        ScreenManager& screenManager = ScreenManager::GetSingleton();
+        screenManager.GetPrimaryScreen(getter_AddRefs(primaryScreen));
+        MOZ_ASSERT(primaryScreen);
+
         // A value of -1 means use the maximum of 96 and the system DPI.
         // A value of 0 means use the system DPI. A positive value is used as the DPI.
         // This sets the physical size of a device pixel and thus controls the
         // interpretation of physical units.
         int32_t prefDPI = Preferences::GetInt("layout.css.dpi", -1);
 
         if (prefDPI > 0) {
             dpi = prefDPI;
         } else if (mWidget) {
+            // PuppetWidget could return -1 if the value's not available yet.
             dpi = mWidget->GetDPI();
-
+            // In case that the widget returns -1, use the primary screen's
+            // value as default.
+            if (dpi < 0) {
+                primaryScreen->GetDpi(&dpi);
+            }
             if (prefDPI < 0) {
                 dpi = std::max(96.0f, dpi);
             }
         } else {
             dpi = 96.0f;
         }
 
         double devPixelsPerCSSPixel;
@@ -303,16 +313,21 @@ nsDeviceContext::SetDPI(double* aScale)
             devPixelsPerCSSPixel = *aScale;
         } else {
             // otherwise get from the widget, and return it in aScale for
             // the caller to pass to child contexts if needed
             CSSToLayoutDeviceScale scale =
                 mWidget ? mWidget->GetDefaultScale()
                         : CSSToLayoutDeviceScale(1.0);
             devPixelsPerCSSPixel = scale.scale;
+            // In case that the widget returns -1, use the primary screen's
+            // value as default.
+            if (devPixelsPerCSSPixel < 0) {
+                primaryScreen->GetDefaultCSSScaleFactor(&devPixelsPerCSSPixel);
+            }
             if (aScale) {
                 *aScale = devPixelsPerCSSPixel;
             }
         }
 
         mAppUnitsPerDevPixelAtUnitFullZoom =
             std::max(1, NS_lround(AppUnitsPerCSSPixel() / devPixelsPerCSSPixel));
     }
--- a/ipc/ipdl/sync-messages.ini
+++ b/ipc/ipdl/sync-messages.ini
@@ -828,21 +828,16 @@ description =
 [PBrowser::RequestIMEToCommitComposition]
 description =
 [PBrowser::StartPluginIME]
 description =
 [PBrowser::GetInputContext]
 description =
 [PBrowser::IsParentWindowMainWidgetVisible]
 description =
-[PBrowser::GetDPI]
-description =
-[PBrowser::GetDefaultScale]
-description =
-[PBrowser::GetWidgetRounding]
 description =
 [PBrowser::RequestNativeKeyBindings]
 description =
 [PBrowser::GetTabCount]
 description =
 [PBrowser::DispatchWheelEvent]
 description =
 [PBrowser::DispatchMouseEvent]
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -83,17 +83,17 @@ static bool gRemoteDesktopBehaviorInitia
 
 NS_IMPL_ISUPPORTS_INHERITED(PuppetWidget, nsBaseWidget
                                         , TextEventDispatcherListener)
 
 PuppetWidget::PuppetWidget(TabChild* aTabChild)
   : mTabChild(aTabChild)
   , mMemoryPressureObserver(nullptr)
   , mDPI(-1)
-  , mRounding(-1)
+  , mRounding(1)
   , mDefaultScale(-1)
   , mCursorHotspotX(0)
   , mCursorHotspotY(0)
 {
   // Setting 'Unknown' means "not yet cached".
   mInputContext.mIMEState.mEnabled = IMEState::UNKNOWN;
 
   if (!gRemoteDesktopBehaviorInitialized) {
@@ -1147,52 +1147,28 @@ PuppetWidget::NeedsPaint()
   }
 
   return mVisible;
 }
 
 float
 PuppetWidget::GetDPI()
 {
-  if (mDPI < 0) {
-    if (mTabChild) {
-      mTabChild->GetDPI(&mDPI);
-    } else {
-      mDPI = 96.0;
-    }
-  }
-
   return mDPI;
 }
 
 double
 PuppetWidget::GetDefaultScaleInternal()
 {
-  if (mDefaultScale < 0) {
-    if (mTabChild) {
-      mTabChild->GetDefaultScale(&mDefaultScale);
-    } else {
-      mDefaultScale = 1;
-    }
-  }
-
   return mDefaultScale;
 }
 
 int32_t
 PuppetWidget::RoundsWidgetCoordinatesTo()
 {
-  if (mRounding < 0) {
-    if (mTabChild) {
-      mTabChild->GetWidgetRounding(&mRounding);
-    } else {
-      mRounding = 1;
-    }
-  }
-
   return mRounding;
 }
 
 void*
 PuppetWidget::GetNativeData(uint32_t aDataType)
 {
   switch (aDataType) {
   case NS_NATIVE_SHAREABLE_WINDOW: {