Bug 1242720 - Followup: reduce code duplication. r=jfkthame, a=lizzard
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 30 Jan 2016 18:29:40 +0900
changeset 318539 f0111f652a9dae7a2b372dbf6595a077b9fb109b
parent 318538 4b8fab96a86d5cf8b3c7b6a663da76d4e1bc3eb4
child 318540 e5c3d208b29af121bc4fed5eb56972202c321fd8
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame, lizzard
bugs1242720
milestone46.0a2
Bug 1242720 - Followup: reduce code duplication. r=jfkthame, a=lizzard
widget/windows/WinUtils.cpp
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -526,23 +526,31 @@ WinUtils::Log(const char *fmt, ...)
 
 // static
 double
 WinUtils::SystemScaleFactor()
 {
   // The result of GetDeviceCaps won't change dynamically, as it predates
   // per-monitor DPI and support for on-the-fly resolution changes.
   // Therefore, we only need to look it up once.
-  static int logPixelsY = 0;
-  if (!logPixelsY) {
+  static double systemScale = 0;
+  if (systemScale == 0) {
     HDC screenDC = GetDC(nullptr);
-    logPixelsY = GetDeviceCaps(screenDC, LOGPIXELSY);
+    systemScale = GetDeviceCaps(screenDC, LOGPIXELSY) / 96.0;
     ReleaseDC(nullptr, screenDC);
+
+    if (systemScale == 0) {
+      // Bug 1012487 - This can occur when the Screen DC is used off the
+      // main thread on windows. For now just assume a 100% DPI for this
+      // drawing call.
+      // XXX - fixme!
+      return 1.0;
+    }
   }
-  return logPixelsY / 96.0;
+  return systemScale;
 }
 
 #ifndef WM_DPICHANGED
 typedef enum {
   MDT_EFFECTIVE_DPI = 0,
   MDT_ANGULAR_DPI = 1,
   MDT_RAW_DPI = 2,
   MDT_DEFAULT = MDT_EFFECTIVE_DPI
@@ -596,29 +604,17 @@ double
 WinUtils::LogToPhysFactor(HMONITOR aMonitor)
 {
   if (IsPerMonitorDPIAware()) {
     UINT dpiX, dpiY = 96;
     sGetDpiForMonitor(aMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
     return dpiY / 96.0;
   }
 
-  // The system DPI will never change during the session.
-  HDC hdc = ::GetDC(nullptr);
-  double result = ::GetDeviceCaps(hdc, LOGPIXELSY) / 96.0;
-  ::ReleaseDC(nullptr, hdc);
-
-  if (result == 0) {
-    // Bug 1012487 - This can occur when the Screen DC is used off the
-    // main thread on windows. For now just assume a 100% DPI for this
-    // drawing call.
-    // XXX - fixme!
-    result = 1.0;
-  }
-  return result;
+  return SystemScaleFactor();
 }
 
 /* static */
 int32_t
 WinUtils::LogToPhys(HMONITOR aMonitor, double aValue)
 {
   return int32_t(NS_round(aValue * LogToPhysFactor(aMonitor)));
 }