Bug 941774 - Centralize various dpi related queries on Windows. r=bbondy a=lsblakk
authorJim Mathies <jmathies@mozilla.com>
Sat, 14 Dec 2013 14:40:55 -0600
changeset 175378 d4f6385acfff3804cf61a182c6321752dea8e426
parent 175377 6886eaa42cac2b13d99ee549f275d506cb71d0c0
child 175379 ff02fb4d847479e27014847a46330be035226ee6
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy, lsblakk
bugs941774
milestone28.0a2
Bug 941774 - Centralize various dpi related queries on Windows. r=bbondy a=lsblakk
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
widget/windows/WinUtils.cpp
widget/windows/WinUtils.h
widget/windows/nsNativeThemeWin.cpp
widget/windows/nsWindow.cpp
widget/windows/winrt/MetroInput.cpp
widget/windows/winrt/MetroUtils.cpp
widget/windows/winrt/MetroUtils.h
widget/windows/winrt/MetroWidget.cpp
widget/windows/winrt/UIABridge.cpp
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -28,33 +28,31 @@
 #include "gfxCrashReporterUtils.h"
 
 #include "gfxGDIFontList.h"
 #include "gfxGDIFont.h"
 
 #include "mozilla/layers/CompositorParent.h"   // for CompositorParent::IsInCompositorThread
 #include "DeviceManagerD3D9.h"
 
+#include "WinUtils.h"
+
 #ifdef CAIRO_HAS_DWRITE_FONT
 #include "gfxDWriteFontList.h"
 #include "gfxDWriteFonts.h"
 #include "gfxDWriteCommon.h"
 #include <dwrite.h>
 #endif
 
 #include "gfxUserFontSet.h"
 #include "nsWindowsHelpers.h"
 #include "gfx2DGlue.h"
 
 #include <string>
 
-using namespace mozilla;
-using namespace mozilla::gfx;
-using namespace mozilla::layers;
-
 #ifdef CAIRO_HAS_D2D_SURFACE
 #include "gfxD2DSurface.h"
 
 #include <d3d10_1.h>
 
 #include "mozilla/gfx/2D.h"
 
 #include "nsMemory.h"
@@ -62,16 +60,19 @@ using namespace mozilla::layers;
 
 #include <d3d11.h>
 
 #include "nsIMemoryReporter.h"
 #include <winternl.h>
 #include "d3dkmtQueryStatistics.h"
 
 using namespace mozilla;
+using namespace mozilla::gfx;
+using namespace mozilla::layers;
+using namespace mozilla::widget;
 
 #ifdef CAIRO_HAS_D2D_SURFACE
 
 static const char *kFeatureLevelPref =
   "gfx.direct3d.last_used_feature_level_idx";
 static const int kSupportedFeatureLevels[] =
   { D3D10_FEATURE_LEVEL_10_1, D3D10_FEATURE_LEVEL_10_0,
     D3D10_FEATURE_LEVEL_9_3 };
@@ -356,18 +357,16 @@ gfxWindowsPlatform::gfxWindowsPlatform()
 
     mUsingGDIFonts = false;
 
     /* 
      * Initialize COM 
      */ 
     CoInitialize(nullptr); 
 
-    mScreenDC = GetDC(nullptr);
-
 #ifdef CAIRO_HAS_D2D_SURFACE
     RegisterStrongMemoryReporter(new GfxD2DSurfaceCacheReporter());
     RegisterStrongMemoryReporter(new GfxD2DSurfaceVramReporter());
     mD2DDevice = nullptr;
 #endif
     RegisterStrongMemoryReporter(new GfxD2DVramDrawTargetReporter());
     RegisterStrongMemoryReporter(new GfxD2DVramSourceSurfaceReporter());
 
@@ -377,33 +376,38 @@ gfxWindowsPlatform::gfxWindowsPlatform()
     // bug 917496.
     //RegisterStrongMemoryReporter(new GPUAdapterReporter());
 }
 
 gfxWindowsPlatform::~gfxWindowsPlatform()
 {
     mDeviceManager = nullptr;
 
-    ::ReleaseDC(nullptr, mScreenDC);
     // not calling FT_Done_FreeType because cairo may still hold references to
     // these FT_Faces.  See bug 458169.
 #ifdef CAIRO_HAS_D2D_SURFACE
     if (mD2DDevice) {
         cairo_release_device(mD2DDevice);
     }
 #endif
 
     mozilla::gfx::Factory::D2DCleanup();
 
     /* 
      * Uninitialize COM 
      */ 
     CoUninitialize();
 }
 
+double
+gfxWindowsPlatform::GetDPIScale()
+{
+  return WinUtils::LogToPhysFactor();
+}
+
 void
 gfxWindowsPlatform::UpdateRenderMode()
 {
 /* Pick the default render mode for
  * desktop.
  */
     mRenderMode = RENDER_GDI;
 
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -170,26 +170,22 @@ public:
      * cairo device creation routines.
      */
     void VerifyD2DDevice(bool aAttemptForce);
 
 #ifdef CAIRO_HAS_D2D_SURFACE
     HRESULT CreateDevice(nsRefPtr<IDXGIAdapter1> &adapter1, int featureLevelIndex);
 #endif
 
-    HDC GetScreenDC() { return mScreenDC; }
-
     /**
      * Return the resolution scaling factor to convert between "logical" or
      * "screen" pixels as used by Windows (dependent on the DPI scaling option
      * in the Display control panel) and actual device pixels.
      */
-    double GetDPIScale() {
-        return GetDeviceCaps(mScreenDC, LOGPIXELSY) / 96.0;
-    }
+    double GetDPIScale();
 
     nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
 
     nsresult UpdateFontList();
 
     virtual void GetCommonFallbackFonts(const uint32_t aCh,
@@ -269,17 +265,16 @@ public:
 
     static bool IsOptimus();
 
 protected:
     RenderMode mRenderMode;
 
     int8_t mUseClearTypeForDownloadableFonts;
     int8_t mUseClearTypeAlways;
-    HDC mScreenDC;
 
 private:
     void Init();
     IDXGIAdapter1 *GetDXGIAdapter();
 
     bool mUseDirectWrite;
     bool mUsingGDIFonts;
 
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -32,16 +32,17 @@
 #include "nsIChannel.h"
 #include "nsIObserver.h"
 #include "imgIEncoder.h"
 #include "nsIThread.h"
 #include "MainThreadUtils.h"
 #include "gfxColor.h"
 #ifdef MOZ_METRO
 #include "winrt/MetroInput.h"
+#include "winrt/MetroUtils.h"
 #endif // MOZ_METRO
 
 #ifdef NS_ENABLE_TSF
 #include <textstor.h>
 #include "nsTextStore.h"
 #endif // #ifdef NS_ENABLE_TSF
 
 #ifdef PR_LOGGING
@@ -181,16 +182,57 @@ WinUtils::Log(const char *fmt, ...)
   NS_ASSERTION(gWindowsLog, "Called WinUtils Log() but Widget "
                                "log module doesn't exist!");
   PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (buffer));
 #endif
   delete[] buffer;
 }
 
 /* static */
+double
+WinUtils::LogToPhysFactor()
+{
+  // dpi / 96.0
+  if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
+#ifdef MOZ_METRO
+    return MetroUtils::LogToPhysFactor();
+#else
+    return 1.0;
+#endif
+  } else {
+    HDC hdc = ::GetDC(nullptr);
+    double result = ::GetDeviceCaps(hdc, LOGPIXELSY) / 96.0;
+    ::ReleaseDC(nullptr, hdc);
+    return result;
+  }
+}
+
+/* static */
+double
+WinUtils::PhysToLogFactor()
+{
+  // 1.0 / (dpi / 96.0)
+  return 1.0 / LogToPhysFactor();
+}
+
+/* static */
+double
+WinUtils::PhysToLog(int32_t aValue)
+{
+  return double(aValue) * PhysToLogFactor();
+}
+
+/* static */
+int32_t
+WinUtils::LogToPhys(double aValue)
+{
+  return int32_t(NS_round(aValue * LogToPhysFactor()));
+}
+
+/* static */
 bool
 WinUtils::PeekMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
                       UINT aLastMessage, UINT aOption)
 {
 #ifdef NS_ENABLE_TSF
   ITfMessagePump* msgPump = nsTextStore::GetMessagePump();
   if (msgPump) {
     BOOL ret = FALSE;
--- a/widget/windows/WinUtils.h
+++ b/widget/windows/WinUtils.h
@@ -65,16 +65,25 @@ class myDownloadObserver MOZ_FINAL : pub
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOWNLOADOBSERVER
 };
 
 class WinUtils {
 public:
   /**
+   * Functions to convert between logical pixels as used by most Windows APIs
+   * and physical (device) pixels.
+   */
+  static double LogToPhysFactor();
+  static double PhysToLogFactor();
+  static int32_t LogToPhys(double aValue);
+  static double PhysToLog(int32_t aValue);
+
+  /**
    * Logging helpers that dump output to prlog module 'Widget', console, and
    * OutputDebugString. Note these output in both debug and release builds.
    */
   static void Log(const char *fmt, ...);
   static void LogW(const wchar_t *fmt, ...);
 
   /**
    * PeekMessage() and GetMessage() are wrapper methods for PeekMessageW(),
--- a/widget/windows/nsNativeThemeWin.cpp
+++ b/widget/windows/nsNativeThemeWin.cpp
@@ -2425,17 +2425,17 @@ nsNativeThemeWin::GetMinimumWidgetSize(n
       return NS_OK;
   }
 
   int32_t part, state;
   nsresult rv = GetThemePartAndState(aFrame, aWidgetType, part, state);
   if (NS_FAILED(rv))
     return rv;
 
-  HDC hdc = gfxWindowsPlatform::GetPlatform()->GetScreenDC();
+  HDC hdc = ::GetDC(nullptr);
   if (!hdc)
     return NS_ERROR_FAILURE;
 
   SIZE sz;
   GetThemePartSize(theme, hdc, part, state, nullptr, sizeReq, &sz);
   aResult->width = sz.cx;
   aResult->height = sz.cy;
 
@@ -2443,22 +2443,23 @@ nsNativeThemeWin::GetMinimumWidgetSize(n
     case NS_THEME_SPINNER_UP_BUTTON:
     case NS_THEME_SPINNER_DOWN_BUTTON:
       aResult->width++;
       aResult->height = aResult->height / 2 + 1;
       break;
 
     case NS_THEME_MENUSEPARATOR:
     {
-      SIZE gutterSize(GetGutterSize(theme,hdc));
+      SIZE gutterSize(GetGutterSize(theme, hdc));
       aResult->width += gutterSize.cx;
       break;
     }
   }
 
+  ::ReleaseDC(nullptr, hdc);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNativeThemeWin::WidgetStateChanged(nsIFrame* aFrame, uint8_t aWidgetType, 
                                      nsIAtom* aAttribute, bool* aShouldRepaint)
 {
   // Some widget types just never change state.
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -974,17 +974,17 @@ float nsWindow::GetDPI()
     // Something's broken
     return 96.0f;
   }
   return float(heightPx/heightInches);
 }
 
 double nsWindow::GetDefaultScaleInternal()
 {
-  return gfxWindowsPlatform::GetPlatform()->GetDPIScale();
+  return WinUtils::LogToPhysFactor();
 }
 
 nsWindow*
 nsWindow::GetParentWindow(bool aIncludeOwner)
 {
   return static_cast<nsWindow*>(GetParentWindowBase(aIncludeOwner));
 }
 
--- a/widget/windows/winrt/MetroInput.cpp
+++ b/widget/windows/winrt/MetroInput.cpp
@@ -10,27 +10,29 @@
 #include "mozilla/dom/Touch.h"  // Touch
 #include "nsTArray.h" // Touch lists
 #include "nsIDOMSimpleGestureEvent.h" // Constants for gesture events
 #include "InputData.h"
 #include "UIABridgePrivate.h"
 #include "MetroAppShell.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
+#include "WinUtils.h"
 
 // System headers (alphabetical)
 #include <windows.ui.core.h> // ABI::Window::UI::Core namespace
 #include <windows.ui.input.h> // ABI::Window::UI::Input namespace
 
 //#define DEBUG_INPUT
 
 // Using declarations
 using namespace ABI::Windows; // UI, System, Foundation namespaces
 using namespace Microsoft; // WRL namespace (ComPtr, possibly others)
 using namespace mozilla;
+using namespace mozilla::widget;
 using namespace mozilla::widget::winrt;
 using namespace mozilla::dom;
 
 // File-scoped statics (unnamed namespace)
 namespace {
   // XXX: Set these min values appropriately
   const double SWIPE_MIN_DISTANCE = 5.0;
   const double SWIPE_MIN_VELOCITY = 5.0;
@@ -70,18 +72,18 @@ namespace {
     aPoint->get_Properties(props.GetAddressOf());
     aPoint->get_Position(&position);
     aPoint->get_PointerId(&pointerId);
     props->get_ContactRect(&contactRect);
     props->get_Pressure(&pressure);
 
     nsIntPoint touchPoint = MetroUtils::LogToPhys(position);
     nsIntPoint touchRadius;
-    touchRadius.x = MetroUtils::LogToPhys(contactRect.Width) / 2;
-    touchRadius.y = MetroUtils::LogToPhys(contactRect.Height) / 2;
+    touchRadius.x = WinUtils::LogToPhys(contactRect.Width) / 2;
+    touchRadius.y = WinUtils::LogToPhys(contactRect.Height) / 2;
     return new Touch(pointerId,
                      touchPoint,
                      // Rotation radius and angle.
                      // W3C touch events v1 do not use these.
                      // The draft for W3C touch events v2 explains that
                      // radius and angle should describe the ellipse that
                      // most closely circumscribes the touching area.  Since
                      // Windows gives us a bounding rectangle rather than an
@@ -117,18 +119,18 @@ namespace {
     float pressure;
 
     aPoint->get_Properties(props.GetAddressOf());
     aPoint->get_Position(&position);
     props->get_ContactRect(&contactRect);
     props->get_Pressure(&pressure);
     nsIntPoint touchPoint = MetroUtils::LogToPhys(position);
     nsIntPoint touchRadius;
-    touchRadius.x = MetroUtils::LogToPhys(contactRect.Width) / 2;
-    touchRadius.y = MetroUtils::LogToPhys(contactRect.Height) / 2;
+    touchRadius.x = WinUtils::LogToPhys(contactRect.Width) / 2;
+    touchRadius.y = WinUtils::LogToPhys(contactRect.Height) / 2;
 
     // from Touch.Equals
     return touchPoint != aTouch->mRefPoint ||
            pressure != aTouch->Force() ||
            /* mRotationAngle == aTouch->RotationAngle() || */
            touchRadius.x != aTouch->RadiusX() ||
            touchRadius.y != aTouch->RadiusY();
   }
--- a/widget/windows/winrt/MetroUtils.cpp
+++ b/widget/windows/winrt/MetroUtils.cpp
@@ -28,82 +28,102 @@ using namespace ABI::Windows::UI::Applic
 using namespace mozilla;
 
 using namespace ABI::Windows::Foundation;
 using namespace Microsoft::WRL;
 using namespace Microsoft::WRL::Wrappers;
 using namespace ABI::Windows::UI::ViewManagement;
 using namespace ABI::Windows::Graphics::Display;
 
-// File-scoped statics (unnamed namespace)
-namespace {
-  FLOAT LogToPhysFactor() {
-    ComPtr<IDisplayInformationStatics> dispInfoStatics;
-    if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayInformation).Get(),
-                                       dispInfoStatics.GetAddressOf()))) {
-      ComPtr<IDisplayInformation> dispInfo;
-      if (SUCCEEDED(dispInfoStatics->GetForCurrentView(&dispInfo))) {
-        FLOAT dpi;
-        if (SUCCEEDED(dispInfo->get_LogicalDpi(&dpi))) {
-          return dpi / 96.0f;
-        }
+// Conversion between logical and physical coordinates
+
+double
+MetroUtils::LogToPhysFactor()
+{
+  ComPtr<IDisplayInformationStatics> dispInfoStatics;
+  if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayInformation).Get(),
+                                      dispInfoStatics.GetAddressOf()))) {
+    ComPtr<IDisplayInformation> dispInfo;
+    if (SUCCEEDED(dispInfoStatics->GetForCurrentView(&dispInfo))) {
+      FLOAT dpi;
+      if (SUCCEEDED(dispInfo->get_LogicalDpi(&dpi))) {
+        return (double)dpi / 96.0f;
       }
     }
+  }
 
-    ComPtr<IDisplayPropertiesStatics> dispProps;
-    if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(),
-                                       dispProps.GetAddressOf()))) {
-      FLOAT dpi;
-      if (SUCCEEDED(dispProps->get_LogicalDpi(&dpi))) {
-        return dpi / 96.0f;
+  ComPtr<IDisplayPropertiesStatics> dispProps;
+  if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(),
+                                      dispProps.GetAddressOf()))) {
+    FLOAT dpi;
+    if (SUCCEEDED(dispProps->get_LogicalDpi(&dpi))) {
+      return (double)dpi / 96.0f;
+    }
+  }
+
+  return 1.0;
+}
+
+double
+MetroUtils::PhysToLogFactor()
+{
+  return 1.0 / LogToPhysFactor();
+}
+
+double
+MetroUtils::ScaleFactor()
+{
+  // Return the resolution scale factor reported by the metro environment.
+  // XXX TODO: also consider the desktop resolution setting, as IE appears to do?
+  ComPtr<IDisplayInformationStatics> dispInfoStatics;
+  if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayInformation).Get(),
+                                      dispInfoStatics.GetAddressOf()))) {
+    ComPtr<IDisplayInformation> dispInfo;
+    if (SUCCEEDED(dispInfoStatics->GetForCurrentView(&dispInfo))) {
+      ResolutionScale scale;
+      if (SUCCEEDED(dispInfo->get_ResolutionScale(&scale))) {
+        return (double)scale / 100.0;
       }
     }
-
-    return 1.0f;
   }
 
-  FLOAT PhysToLogFactor() {
-    return 1.0f / LogToPhysFactor();
+  ComPtr<IDisplayPropertiesStatics> dispProps;
+  if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(),
+                                     dispProps.GetAddressOf()))) {
+    ResolutionScale scale;
+    if (SUCCEEDED(dispProps->get_ResolutionScale(&scale))) {
+      return (double)scale / 100.0;
+    }
   }
-};
 
-// Conversion between logical and physical coordinates
-int32_t
-MetroUtils::LogToPhys(FLOAT aValue)
-{
-  return int32_t(NS_round(aValue * LogToPhysFactor()));
+  return 1.0;
 }
 
 nsIntPoint
 MetroUtils::LogToPhys(const Point& aPt)
 {
-  FLOAT factor = LogToPhysFactor();
+  double factor = LogToPhysFactor();
   return nsIntPoint(int32_t(NS_round(aPt.X * factor)), int32_t(NS_round(aPt.Y * factor)));
 }
 
 nsIntRect
 MetroUtils::LogToPhys(const Rect& aRect)
 {
-  FLOAT factor = LogToPhysFactor();
+  double factor = LogToPhysFactor();
   return nsIntRect(int32_t(NS_round(aRect.X * factor)),
                    int32_t(NS_round(aRect.Y * factor)),
                    int32_t(NS_round(aRect.Width * factor)),
                    int32_t(NS_round(aRect.Height * factor)));
 }
 
-FLOAT
-MetroUtils::PhysToLog(int32_t aValue)
-{
-  return FLOAT(aValue) * PhysToLogFactor();
-}
-
 Point
 MetroUtils::PhysToLog(const nsIntPoint& aPt)
 {
-  FLOAT factor = PhysToLogFactor();
+  // Points contain FLOATs
+  FLOAT factor = (FLOAT)PhysToLogFactor();
   Point p = { FLOAT(aPt.x) * factor, FLOAT(aPt.y) * factor };
   return p;
 }
 
 nsresult
 MetroUtils::FireObserver(const char* aMessage, const PRUnichar* aData)
 {
   nsCOMPtr<nsIObserverService> observerService =
--- a/widget/windows/winrt/MetroUtils.h
+++ b/widget/windows/winrt/MetroUtils.h
@@ -68,23 +68,25 @@ class MetroUtils
   typedef Microsoft::WRL::Wrappers::HString HString;
   typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState;
   typedef ABI::Windows::Foundation::Point Point;
   typedef ABI::Windows::Foundation::Rect Rect;
 
 public:
   // Functions to convert between logical pixels as used by most Windows APIs
   // and physical (device) pixels.
-  // See MSDN documentation about DIPs (device independent pixels) for details.
-  static int32_t LogToPhys(FLOAT aValue);
+  static double LogToPhysFactor();
+  static double PhysToLogFactor();
   static nsIntPoint LogToPhys(const Point& aPt);
   static nsIntRect LogToPhys(const Rect& aRect);
-  static FLOAT PhysToLog(int32_t aValue);
   static Point PhysToLog(const nsIntPoint& aPt);
 
+  // Resolution scale factor
+  static double ScaleFactor();
+
   static nsresult FireObserver(const char* aMessage, const PRUnichar* aData = nullptr);
 
   static HRESULT CreateUri(HSTRING aUriStr, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut);
   static HRESULT CreateUri(HString& aHString, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut);
   static HRESULT GetViewState(ApplicationViewState& aState);
   static HRESULT TryUnsnap(bool* aResult = nullptr);
   static HRESULT ShowSettingsFlyout();
 
--- a/widget/windows/winrt/MetroWidget.cpp
+++ b/widget/windows/winrt/MetroWidget.cpp
@@ -1326,43 +1326,20 @@ MetroWidget::GetAccessible()
   // If the pref was true, return null here, disabling a11y.
   if (accForceDisable)
       return nullptr;
 
   return GetRootAccessible();
 }
 #endif
 
-double MetroWidget::GetDefaultScaleInternal()
+double
+MetroWidget::GetDefaultScaleInternal()
 {
-  // Return the resolution scale factor reported by the metro environment.
-  // XXX TODO: also consider the desktop resolution setting, as IE appears to do?
-
-  ComPtr<IDisplayInformationStatics> dispInfoStatics;
-  if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayInformation).Get(),
-                                      dispInfoStatics.GetAddressOf()))) {
-    ComPtr<IDisplayInformation> dispInfo;
-    if (SUCCEEDED(dispInfoStatics->GetForCurrentView(&dispInfo))) {
-      ResolutionScale scale;
-      if (SUCCEEDED(dispInfo->get_ResolutionScale(&scale))) {
-        return (double)scale / 100.0;
-      }
-    }
-  }
-
-  ComPtr<IDisplayPropertiesStatics> dispProps;
-  if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(),
-                                     dispProps.GetAddressOf()))) {
-    ResolutionScale scale;
-    if (SUCCEEDED(dispProps->get_ResolutionScale(&scale))) {
-      return (double)scale / 100.0;
-    }
-  }
-
-  return 1.0;
+  return MetroUtils::ScaleFactor();
 }
 
 LayoutDeviceIntPoint
 MetroWidget::CSSIntPointToLayoutDeviceIntPoint(const CSSIntPoint &aCSSPoint)
 {
   CSSToLayoutDeviceScale scale = GetDefaultScale();
   LayoutDeviceIntPoint devPx(int32_t(NS_round(scale.scale * aCSSPoint.x)),
                              int32_t(NS_round(scale.scale * aCSSPoint.y)));
--- a/widget/windows/winrt/UIABridge.cpp
+++ b/widget/windows/winrt/UIABridge.cpp
@@ -310,20 +310,20 @@ UIABridge::get_BoundingRectangle(UiaRect
     return UIA_E_ELEMENTNOTAVAILABLE;
   }
 
   // returns logical pixels
   Rect bounds;
   mWindow->get_Bounds(&bounds);
 
   // we need to return physical pixels
-  retVal->left = MetroUtils::LogToPhys(bounds.X);
-  retVal->top = MetroUtils::LogToPhys(bounds.Y);
-  retVal->width = MetroUtils::LogToPhys(bounds.Width);
-  retVal->height = MetroUtils::LogToPhys(bounds.Height);
+  retVal->left = WinUtils::LogToPhys(bounds.X);
+  retVal->top = WinUtils::LogToPhys(bounds.Y);
+  retVal->width = WinUtils::LogToPhys(bounds.Width);
+  retVal->height = WinUtils::LogToPhys(bounds.Height);
 
   return S_OK;
 }
 
 HRESULT
 UIABridge::GetEmbeddedFragmentRoots(SAFEARRAY ** retVal)
 {
   if (!Connected()) {