Bug 1350643 - Part 6.2: Get per-monitor dpi in ScreenHelperWin & use the same value in nsWindow::GetDPI. r?jimm
MozReview-Commit-ID: 3oEvQe8zNJ0
--- 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;