mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 19:25:43 +00:00
e2a9b2f533
ScreenHelperWin is the platform dependent part of the original nsScreenManagerWin and nsScreenWin. It listens the WM_DISPLAYCHANGE message and pushes updates to ScreenManager. See patch part 4. for how ScreenManager works. MozReview-Commit-ID: 20A3ZQKmH9a --HG-- rename : widget/windows/nsScreenManagerWin.cpp => widget/windows/ScreenHelperWin.cpp rename : widget/windows/nsScreenManagerWin.h => widget/windows/ScreenHelperWin.h extra : rebase_source : a3058c237d38f72103251802ab5f5bbd672e9b70
91 lines
3.4 KiB
C++
91 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 LazyLogModule sScreenLog("WidgetScreen");
|
|
|
|
namespace mozilla {
|
|
namespace widget {
|
|
|
|
BOOL CALLBACK
|
|
CollectMonitors(HMONITOR aMon, HDC, 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
|
|
}
|
|
DesktopToLayoutDeviceScale contentsScaleFactor;
|
|
if (WinUtils::IsPerMonitorDPIAware()) {
|
|
contentsScaleFactor.scale = 1.0;
|
|
} else {
|
|
contentsScaleFactor.scale = WinUtils::LogToPhysFactor(aMon);
|
|
}
|
|
CSSToLayoutDeviceScale defaultCssScaleFactor(nsIWidget::DefaultScaleOverride());
|
|
if (defaultCssScaleFactor.scale <= 0.0) {
|
|
defaultCssScaleFactor.scale = contentsScaleFactor.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);
|
|
//XXX not sure how to get this info for multiple monitors, this might be ok...
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
uint32_t pixelDepth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
|
|
::ReleaseDC(nullptr, hDCScreen);
|
|
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;
|
|
}
|
|
MOZ_LOG(sScreenLog, LogLevel::Debug, ("New screen [%d %d %d %d %d %f]",
|
|
rect.x, rect.y, rect.width, rect.height,
|
|
pixelDepth, defaultCssScaleFactor.scale));
|
|
screens->AppendElement(new Screen(rect, availRect,
|
|
pixelDepth, pixelDepth,
|
|
contentsScaleFactor, defaultCssScaleFactor));
|
|
return TRUE;
|
|
}
|
|
|
|
float
|
|
ScreenHelperWin::GetSystemDefaultScale()
|
|
{
|
|
HMONITOR primary = widget::WinUtils::GetPrimaryMonitor();
|
|
return float(widget::WinUtils::LogToPhysFactor(primary));
|
|
}
|
|
|
|
void
|
|
ScreenHelperWin::RefreshScreens()
|
|
{
|
|
MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refreshing screens"));
|
|
|
|
AutoTArray<RefPtr<Screen>, 4> screens;
|
|
BOOL result = ::EnumDisplayMonitors(nullptr, nullptr,
|
|
(MONITORENUMPROC)CollectMonitors,
|
|
(LPARAM)&screens);
|
|
if (!result) {
|
|
NS_WARNING("Unable to EnumDisplayMonitors");
|
|
}
|
|
ScreenManager& screenManager = ScreenManager::GetSingleton();
|
|
screenManager.Refresh(Move(screens));
|
|
}
|
|
|
|
} // namespace widget
|
|
} // namespace mozilla
|