Bug 1350643 - Part 6.2: Get per-monitor dpi in ScreenHelperWin & use the same value in nsWindow::GetDPI. r?jimm draft
authorSamael Wang <freesamael@gmail.com>
Fri, 16 Jun 2017 11:16:47 +0800
changeset 611037 35d464ca97ea04cb05676eee5636e19115816526
parent 611036 bfcee8a5a1c5bed66484687d488b97d1617e0dc3
child 611038 b8f0fd4ab8965e6e247f4bfd51792168ec704378
push id69104
push userbmo:sawang@mozilla.com
push dateWed, 19 Jul 2017 06:01:44 +0000
reviewersjimm
bugs1350643
milestone56.0a1
Bug 1350643 - Part 6.2: Get per-monitor dpi in ScreenHelperWin & use the same value in nsWindow::GetDPI. r?jimm MozReview-Commit-ID: 3oEvQe8zNJ0
widget/windows/ScreenHelperWin.cpp
widget/windows/nsWindow.cpp
--- a/widget/windows/ScreenHelperWin.cpp
+++ b/widget/windows/ScreenHelperWin.cpp
@@ -43,21 +43,23 @@ CollectMonitors(HMONITOR aMon, HDC hDCSc
                                 info.rcWork.bottom - info.rcWork.top);
   uint32_t pixelDepth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
   if (pixelDepth == 32) {
     // If a device uses 32 bits per pixel, it's still only using 8 bits
     // per color component, which is what our callers want to know.
     // (Some devices report 32 and some devices report 24.)
     pixelDepth = 24;
   }
-  float dpi = 96.0f;
-  MOZ_LOG(sScreenLog, LogLevel::Debug, ("New screen [%d %d %d %d %d %f %f]",
-                                        rect.x, rect.y, rect.width, rect.height,
-                                        pixelDepth, defaultCssScaleFactor.scale,
-                                        dpi));
+  float dpi = WinUtils::MonitorDPI(aMon);
+  MOZ_LOG(sScreenLog, LogLevel::Debug,
+           ("New screen [%d %d %d %d (%d %d %d %d) %d %f %f %f]",
+            rect.x, rect.y, rect.width, rect.height,
+            availRect.x, availRect.y, availRect.width, availRect.height,
+            pixelDepth, contentsScaleFactor.scale, defaultCssScaleFactor.scale,
+            dpi));
   auto screen = new Screen(rect, availRect,
                            pixelDepth, pixelDepth,
                            contentsScaleFactor, defaultCssScaleFactor,
                            dpi);
   if (info.dwFlags & MONITORINFOF_PRIMARY) {
     // The primary monitor must be the first element of the screen list.
     screens->InsertElementAt(0, Move(screen));
   } else {
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -1295,28 +1295,22 @@ nsIWidget* nsWindow::GetParent(void)
 static int32_t RoundDown(double aDouble)
 {
   return aDouble > 0 ? static_cast<int32_t>(floor(aDouble)) :
                        static_cast<int32_t>(ceil(aDouble));
 }
 
 float nsWindow::GetDPI()
 {
-  HDC dc = ::GetDC(mWnd);
-  if (!dc)
-    return 96.0f;
-
-  double heightInches = ::GetDeviceCaps(dc, VERTSIZE)/MM_PER_INCH_FLOAT;
-  int heightPx = ::GetDeviceCaps(dc, VERTRES);
-  ::ReleaseDC(mWnd, dc);
-  if (heightInches < 0.25) {
-    // Something's broken
-    return 96.0f;
-  }
-  return float(heightPx/heightInches);
+  float dpi = 96.0f;
+  nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
+  if (screen) {
+    screen->GetDpi(&dpi);
+  }
+  return dpi;
 }
 
 double nsWindow::GetDefaultScaleInternal()
 {
   if (mDefaultScale <= 0.0) {
     mDefaultScale = WinUtils::LogToPhysFactor(mWnd);
   }
   return mDefaultScale;