webrtc_m130/modules/desktop_capture/win/display_configuration_monitor.h
Joe Downing 60795e8c7a Re-initialize the DXGI capturer when the DPI of the monitor changes
I am updating Chrome Remote Desktop to apply a scale factor when using
curtain mode (i.e. a loopback RDP session) and I've found that while
the changes are applied and the desktop is scaled, DXGI stops
producing frames.

This is essentially the same issue as crbug.com/1307357 except this
issue is occurring when the DPI is changed rather than the desktop
size.

The fix is to look at the effective DPI for the source being
captured (or the primary monitor when capturing the full desktop)
and then signaling an environment change when the DPI differs.

Bug: webrtc:14894,b:154733991
Change-Id: Id768d4a384434ba59e7396bc919d0ba30d0f6acc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/292791
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Joe Downing <joedow@google.com>
Cr-Commit-Position: refs/heads/main@{#39305}
2023-02-13 18:26:29 +00:00

54 lines
2.1 KiB
C++

/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_DESKTOP_CAPTURE_WIN_DISPLAY_CONFIGURATION_MONITOR_H_
#define MODULES_DESKTOP_CAPTURE_WIN_DISPLAY_CONFIGURATION_MONITOR_H_
#include "modules/desktop_capture/desktop_capturer.h"
#include "modules/desktop_capture/desktop_geometry.h"
#include "rtc_base/containers/flat_map.h"
namespace webrtc {
// A passive monitor to detect the change of display configuration on a Windows
// system.
// TODO(zijiehe): Also check for pixel format changes.
class DisplayConfigurationMonitor {
public:
// Checks whether the display configuration has changed since the last time
// IsChanged() was called. |source_id| is used to observe changes for a
// specific display or all displays if kFullDesktopScreenId is passed in.
// Returns false if object was Reset() or if IsChanged() has not been called.
bool IsChanged(DesktopCapturer::SourceId source_id);
// Resets to the initial state.
void Reset();
private:
DesktopVector GetDpiForSourceId(DesktopCapturer::SourceId source_id);
// Represents the size of the desktop which includes all displays.
DesktopRect rect_;
// Tracks the DPI for each display being captured. We need to track for each
// display as each one can be configured to use a different DPI which will not
// be reflected in calls to get the system DPI.
flat_map<DesktopCapturer::SourceId, DesktopVector> source_dpis_;
// Indicates whether |rect_| and |source_dpis_| have been initialized. This is
// used to prevent the monitor instance from signaling 'IsChanged()' before
// the initial values have been set.
bool initialized_ = false;
};
} // namespace webrtc
#endif // MODULES_DESKTOP_CAPTURE_WIN_DISPLAY_CONFIGURATION_MONITOR_H_