Bug 1350643 - Part 4.1: Get per-monitor dpi in ScreenHelperCocoa. r?mstange
MozReview-Commit-ID: OHa8h2sh26
--- 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;