gecko-dev/widget/windows/ScreenHelperWin.cpp
Cosmin Sabou 79d933ec34 Backed out 22 changesets (bug 1399787) for shutdown leaks on windows 7 debug tc-M without e10s r=backout on a CLOSED TREE
Backed out changeset 463d676df5da (bug 1399787)
Backed out changeset fc9776a2605d (bug 1399787)
Backed out changeset 2e91a90dfbc3 (bug 1399787)
Backed out changeset e82ab72f71ee (bug 1399787)
Backed out changeset d7fef200e8b9 (bug 1399787)
Backed out changeset a7d70f7f3335 (bug 1399787)
Backed out changeset 2800f9d20d96 (bug 1399787)
Backed out changeset 9dfa404abf9d (bug 1399787)
Backed out changeset 09b3c172a01e (bug 1399787)
Backed out changeset f9fd3e750636 (bug 1399787)
Backed out changeset 01284c55bf8a (bug 1399787)
Backed out changeset c2ab1b454283 (bug 1399787)
Backed out changeset e7bfa51404c5 (bug 1399787)
Backed out changeset 3fd2a734f887 (bug 1399787)
Backed out changeset ef21f295db3f (bug 1399787)
Backed out changeset c186893ce0fc (bug 1399787)
Backed out changeset 323da3bddaaa (bug 1399787)
Backed out changeset 3b89f189edff (bug 1399787)
Backed out changeset a47bd86c35ee (bug 1399787)
Backed out changeset 558526301a4c (bug 1399787)
Backed out changeset baa99fb50ba9 (bug 1399787)
Backed out changeset 6d82ed0ba805 (bug 1399787)
2017-12-08 13:09:56 +02:00

92 lines
3.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ScreenHelperWin.h"
#include "mozilla/Logging.h"
#include "nsTArray.h"
#include "WinUtils.h"
static mozilla::LazyLogModule sScreenLog("WidgetScreen");
namespace mozilla {
namespace widget {
BOOL CALLBACK
CollectMonitors(HMONITOR aMon, HDC hDCScreen, LPRECT, LPARAM ioParam)
{
auto screens = reinterpret_cast<nsTArray<RefPtr<Screen>>*>(ioParam);
BOOL success = FALSE;
MONITORINFO info;
info.cbSize = sizeof(MONITORINFO);
success = ::GetMonitorInfoW(aMon, &info);
if (!success) {
MOZ_LOG(sScreenLog, LogLevel::Error, ("GetMonitorInfoW failed"));
return TRUE; // continue the enumeration
}
double scale = WinUtils::LogToPhysFactor(aMon);
DesktopToLayoutDeviceScale contentsScaleFactor;
if (WinUtils::IsPerMonitorDPIAware()) {
contentsScaleFactor.scale = 1.0;
} else {
contentsScaleFactor.scale = scale;
}
CSSToLayoutDeviceScale defaultCssScaleFactor(scale);
LayoutDeviceIntRect rect(info.rcMonitor.left, info.rcMonitor.top,
info.rcMonitor.right - info.rcMonitor.left,
info.rcMonitor.bottom - info.rcMonitor.top);
LayoutDeviceIntRect availRect(info.rcWork.left, info.rcWork.top,
info.rcWork.right - info.rcWork.left,
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 = 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 {
screens->AppendElement(Move(screen));
}
return TRUE;
}
void
ScreenHelperWin::RefreshScreens()
{
MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refreshing screens"));
AutoTArray<RefPtr<Screen>, 4> screens;
HDC hdc = ::CreateDC(L"DISPLAY", nullptr, nullptr, nullptr);
NS_ASSERTION(hdc,"CreateDC Failure");
BOOL result = ::EnumDisplayMonitors(hdc, nullptr,
(MONITORENUMPROC)CollectMonitors,
(LPARAM)&screens);
::DeleteDC(hdc);
if (!result) {
NS_WARNING("Unable to EnumDisplayMonitors");
}
ScreenManager& screenManager = ScreenManager::GetSingleton();
screenManager.Refresh(Move(screens));
}
} // namespace widget
} // namespace mozilla