Make MouseCursorMonitor optional for DesktopAndCursorComposer.

DesktopAndCursorComposer already handles a null MouseCursorMonitor. This
CL allows that code-path to be utilized by callers that already have a
MouseCursorMonitor, allowing its callbacks to be re-used by this class.
This is more efficient, and works around an apparent X Server deadlock
on Linux if multiple MouseCursorMonitors are simultaneously active.

The intended use-case for this is to allow the host-side cursor to be
composited into the desktop image if mouse-lock is active at the client.

Bug: chromium:1043325
Change-Id: I7e036850dd8c17fe55e57db252392062a847d10f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166581
Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Jamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#30312}
This commit is contained in:
Jamie Walch 2020-01-17 16:21:01 -08:00 committed by Commit Bot
parent 40dc6aca10
commit c380e97ee6
2 changed files with 18 additions and 5 deletions

View file

@ -144,6 +144,13 @@ DesktopAndCursorComposer::DesktopAndCursorComposer(
DesktopAndCursorComposer::~DesktopAndCursorComposer() = default;
std::unique_ptr<DesktopAndCursorComposer>
DesktopAndCursorComposer::CreateWithoutMouseCursorMonitor(
std::unique_ptr<DesktopCapturer> desktop_capturer) {
return std::unique_ptr<DesktopAndCursorComposer>(
new DesktopAndCursorComposer(desktop_capturer.release(), nullptr));
}
void DesktopAndCursorComposer::Start(DesktopCapturer::Callback* callback) {
callback_ = callback;
if (mouse_monitor_)

View file

@ -33,7 +33,7 @@ class RTC_EXPORT DesktopAndCursorComposer
public DesktopCapturer::Callback,
public MouseCursorMonitor::Callback {
public:
// Creates a new blender that captures mouse cursor using
// Creates a new composer that captures mouse cursor using
// MouseCursorMonitor::Create(options) and renders it into the frames
// generated by |desktop_capturer|.
DesktopAndCursorComposer(std::unique_ptr<DesktopCapturer> desktop_capturer,
@ -41,6 +41,12 @@ class RTC_EXPORT DesktopAndCursorComposer
~DesktopAndCursorComposer() override;
// Creates a new composer that relies on an external source for cursor shape
// and position information via the MouseCursorMonitor::Callback interface.
static std::unique_ptr<DesktopAndCursorComposer>
CreateWithoutMouseCursorMonitor(
std::unique_ptr<DesktopCapturer> desktop_capturer);
// DesktopCapturer interface.
void Start(DesktopCapturer::Callback* callback) override;
void SetSharedMemoryFactory(
@ -48,6 +54,10 @@ class RTC_EXPORT DesktopAndCursorComposer
void CaptureFrame() override;
void SetExcludedWindow(WindowId window) override;
// MouseCursorMonitor::Callback interface.
void OnMouseCursor(MouseCursor* cursor) override;
void OnMouseCursorPosition(const DesktopVector& position) override;
private:
// Allows test cases to use a fake MouseCursorMonitor implementation.
friend class DesktopAndCursorComposerTest;
@ -61,10 +71,6 @@ class RTC_EXPORT DesktopAndCursorComposer
void OnCaptureResult(DesktopCapturer::Result result,
std::unique_ptr<DesktopFrame> frame) override;
// MouseCursorMonitor::Callback interface.
void OnMouseCursor(MouseCursor* cursor) override;
void OnMouseCursorPosition(const DesktopVector& position) override;
const std::unique_ptr<DesktopCapturer> desktop_capturer_;
const std::unique_ptr<MouseCursorMonitor> mouse_monitor_;