2017-03-09 14:32:31 +03:00
|
|
|
/* -*- 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"
|
|
|
|
|
2017-10-06 17:01:22 +03:00
|
|
|
static mozilla::LazyLogModule sScreenLog("WidgetScreen");
|
2017-03-09 14:32:31 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
BOOL CALLBACK
|
2018-04-26 01:01:11 +03:00
|
|
|
CollectMonitors(HMONITOR aMon, HDC, LPRECT, LPARAM ioParam)
|
2017-03-09 14:32:31 +03:00
|
|
|
{
|
|
|
|
auto screens = reinterpret_cast<nsTArray<RefPtr<Screen>>*>(ioParam);
|
|
|
|
BOOL success = FALSE;
|
2018-04-26 01:01:11 +03:00
|
|
|
MONITORINFOEX info;
|
|
|
|
info.cbSize = sizeof(MONITORINFOEX);
|
2017-03-09 14:32:31 +03:00
|
|
|
success = ::GetMonitorInfoW(aMon, &info);
|
|
|
|
if (!success) {
|
|
|
|
MOZ_LOG(sScreenLog, LogLevel::Error, ("GetMonitorInfoW failed"));
|
|
|
|
return TRUE; // continue the enumeration
|
|
|
|
}
|
2018-04-26 01:01:11 +03:00
|
|
|
|
2017-03-28 19:40:47 +03:00
|
|
|
double scale = WinUtils::LogToPhysFactor(aMon);
|
2017-03-09 14:32:31 +03:00
|
|
|
DesktopToLayoutDeviceScale contentsScaleFactor;
|
|
|
|
if (WinUtils::IsPerMonitorDPIAware()) {
|
|
|
|
contentsScaleFactor.scale = 1.0;
|
|
|
|
} else {
|
2017-03-28 19:40:47 +03:00
|
|
|
contentsScaleFactor.scale = scale;
|
2017-03-09 14:32:31 +03:00
|
|
|
}
|
2017-04-05 16:11:34 +03:00
|
|
|
CSSToLayoutDeviceScale defaultCssScaleFactor(scale);
|
2017-03-09 14:32:31 +03:00
|
|
|
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);
|
2018-04-26 01:01:11 +03:00
|
|
|
|
|
|
|
HDC hDC = CreateDC(nullptr, info.szDevice, nullptr, nullptr);
|
|
|
|
if (!hDC) {
|
|
|
|
MOZ_LOG(sScreenLog, LogLevel::Error, ("CollectMonitors CreateDC failed"));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
uint32_t pixelDepth = ::GetDeviceCaps(hDC, BITSPIXEL);
|
|
|
|
DeleteDC(hDC);
|
2017-03-09 14:32:31 +03:00
|
|
|
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;
|
|
|
|
}
|
2018-04-26 01:01:11 +03:00
|
|
|
|
2017-06-16 06:16:47 +03:00
|
|
|
float dpi = WinUtils::MonitorDPI(aMon);
|
|
|
|
MOZ_LOG(sScreenLog, LogLevel::Debug,
|
|
|
|
("New screen [%d %d %d %d (%d %d %d %d) %d %f %f %f]",
|
2018-01-10 19:14:16 +03:00
|
|
|
rect.X(), rect.Y(), rect.Width(), rect.Height(),
|
|
|
|
availRect.X(), availRect.Y(), availRect.Width(), availRect.Height(),
|
2017-06-16 06:16:47 +03:00
|
|
|
pixelDepth, contentsScaleFactor.scale, defaultCssScaleFactor.scale,
|
|
|
|
dpi));
|
2017-03-30 16:49:10 +03:00
|
|
|
auto screen = new Screen(rect, availRect,
|
|
|
|
pixelDepth, pixelDepth,
|
2017-06-06 13:09:34 +03:00
|
|
|
contentsScaleFactor, defaultCssScaleFactor,
|
|
|
|
dpi);
|
2017-03-30 16:49:10 +03:00
|
|
|
if (info.dwFlags & MONITORINFOF_PRIMARY) {
|
|
|
|
// The primary monitor must be the first element of the screen list.
|
2018-05-30 22:15:35 +03:00
|
|
|
screens->InsertElementAt(0, std::move(screen));
|
2017-03-30 16:49:10 +03:00
|
|
|
} else {
|
2018-05-30 22:15:35 +03:00
|
|
|
screens->AppendElement(std::move(screen));
|
2017-03-30 16:49:10 +03:00
|
|
|
}
|
2017-03-09 14:32:31 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScreenHelperWin::RefreshScreens()
|
|
|
|
{
|
|
|
|
MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refreshing screens"));
|
|
|
|
|
|
|
|
AutoTArray<RefPtr<Screen>, 4> screens;
|
2018-04-26 01:01:11 +03:00
|
|
|
BOOL result = ::EnumDisplayMonitors(nullptr, nullptr,
|
2017-03-09 14:32:31 +03:00
|
|
|
(MONITORENUMPROC)CollectMonitors,
|
|
|
|
(LPARAM)&screens);
|
|
|
|
if (!result) {
|
|
|
|
NS_WARNING("Unable to EnumDisplayMonitors");
|
|
|
|
}
|
|
|
|
ScreenManager& screenManager = ScreenManager::GetSingleton();
|
2018-05-30 22:15:35 +03:00
|
|
|
screenManager.Refresh(std::move(screens));
|
2017-03-09 14:32:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|