Bug 1350643 - Part 5.1: Get per-monitor dpi in ScreenHelperGTK & use the same value in nsWindow::GetDPI. r=karlt
authorSamael Wang <freesamael@gmail.com>
Fri, 16 Jun 2017 10:58:11 +0800
changeset 418576 8e85fca9fd901d8c05074ad1b3ad327526f5632b
parent 418575 d1529cb8f16ca5d6684886123846ce073fd677cf
child 418577 070ca389c4353ea77ddc17e5bceb522e05b34305
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1350643
milestone56.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 1350643 - Part 5.1: Get per-monitor dpi in ScreenHelperGTK & use the same value in nsWindow::GetDPI. r=karlt MozReview-Commit-ID: 9dOkUEzuUL8
widget/gtk/ScreenHelperGTK.cpp
widget/gtk/nsWindow.cpp
--- a/widget/gtk/ScreenHelperGTK.cpp
+++ b/widget/gtk/ScreenHelperGTK.cpp
@@ -147,21 +147,26 @@ MakeScreen(GdkScreen* aScreen, gint aMon
                                 workarea.width * gdkScaleFactor,
                                 workarea.height * gdkScaleFactor);
   uint32_t pixelDepth = GetGTKPixelDepth();
   DesktopToLayoutDeviceScale contentsScale(1.0);
   CSSToLayoutDeviceScale defaultCssScale(
     gdkScaleFactor * gfxPlatformGtk::GetFontScaleFactor());
 
   float dpi = 96.0f;
+  gint heightMM = gdk_screen_get_monitor_height_mm(aScreen, aMonitorNum);
+  if (heightMM > 0) {
+    dpi = rect.height / (heightMM / MM_PER_INCH_FLOAT);
+  }
+
   MOZ_LOG(sScreenLog, LogLevel::Debug,
-           ("New screen [%d %d %d %d (%d %d %d %d) %d %f %f]",
+           ("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, defaultCssScale.scale, dpi));
+            pixelDepth, contentsScale.scale, defaultCssScale.scale, dpi));
   RefPtr<Screen> screen = new Screen(rect, availRect,
                                      pixelDepth, pixelDepth,
                                      contentsScale, defaultCssScale,
                                      dpi);
   return screen.forget();
 }
 
 void
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -799,23 +799,22 @@ nsIWidget *
 nsWindow::GetParent(void)
 {
     return mParent;
 }
 
 float
 nsWindow::GetDPI()
 {
-    GdkScreen *screen = gdk_display_get_default_screen(gdk_display_get_default());
-    double heightInches = gdk_screen_get_height_mm(screen)/MM_PER_INCH_FLOAT;
-    if (heightInches < 0.25) {
-        // Something's broken, but we'd better not crash.
-        return 96.0f;
-    }
-    return float(gdk_screen_get_height(screen)/heightInches);
+    float dpi = 96.0f;
+    nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
+    if (screen) {
+        screen->GetDpi(&dpi);
+    }
+    return dpi;
 }
 
 double
 nsWindow::GetDefaultScaleInternal()
 {
     return GdkScaleFactor() * gfxPlatformGtk::GetFontScaleFactor();
 }