Bug 1350643 - Part 4.1: Get per-monitor dpi in ScreenHelperCocoa. r=mstange
authorSamael Wang <freesamael@gmail.com>
Tue, 06 Jun 2017 18:18:52 +0800
changeset 418574 ea47118382b93663fa6e7cd96584c19de3d3f2e8
parent 418573 abfd88baf39108831d7a9337f841ecb623b5594c
child 418575 d1529cb8f16ca5d6684886123846ce073fd677cf
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)
reviewersmstange
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 4.1: Get per-monitor dpi in ScreenHelperCocoa. r=mstange MozReview-Commit-ID: OHa8h2sh26
widget/cocoa/ScreenHelperCocoa.mm
widget/cocoa/nsCocoaWindow.h
--- a/widget/cocoa/ScreenHelperCocoa.mm
+++ b/widget/cocoa/ScreenHelperCocoa.mm
@@ -90,20 +90,28 @@ MakeScreen(NSScreen* aScreen)
   LayoutDeviceIntRect rect =
     nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, contentsScaleFactor.scale);
   frame = [aScreen visibleFrame];
   LayoutDeviceIntRect availRect =
     nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, contentsScaleFactor.scale);
   NSWindowDepth depth = [aScreen depth];
   uint32_t pixelDepth = NSBitsPerPixelFromDepth(depth);
   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, contentsScaleFactor.scale,
-                                        dpi));
+  CGDirectDisplayID displayID =
+    [[[aScreen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
+  CGFloat heightMM = ::CGDisplayScreenSize(displayID).height;
+  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 %f]",
+            rect.x, rect.y, rect.width, rect.height,
+            availRect.x, availRect.y, availRect.width, availRect.height,
+            pixelDepth, contentsScaleFactor.scale, defaultCssScaleFactor.scale,
+            dpi));
 
   RefPtr<Screen> screen = new Screen(rect, availRect,
                                      pixelDepth, pixelDepth,
                                      contentsScaleFactor, defaultCssScaleFactor,
                                      dpi);
   return screen.forget();
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nullptr);
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -42,16 +42,18 @@ typedef struct _nsCocoaWindowList {
   NSColor* mInactiveTitlebarColor;
 
   // Invalidation disabling
   BOOL mDisabledNeedsDisplay;
 
   // DPI cache. Getting the physical screen size (CGDisplayScreenSize)
   // is ridiculously slow, so we cache it in the toplevel window for all
   // descendants to use.
+  //
+  // XXX the dpi cache won't change when moving across different monitors.
   float mDPI;
 
   NSTrackingArea* mTrackingArea;
 
   NSRect mDirtyRect;
 
   BOOL mBeingShown;
   BOOL mDrawTitle;