
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}
88 lines
3.4 KiB
C++
88 lines
3.4 KiB
C++
/*
|
|
* Copyright (c) 2013 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_DESKTOP_AND_CURSOR_COMPOSER_H_
|
|
#define MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_
|
|
|
|
#include <memory>
|
|
|
|
#include "modules/desktop_capture/desktop_capture_options.h"
|
|
#include "modules/desktop_capture/desktop_capture_types.h"
|
|
#include "modules/desktop_capture/desktop_capturer.h"
|
|
#include "modules/desktop_capture/desktop_frame.h"
|
|
#include "modules/desktop_capture/desktop_geometry.h"
|
|
#include "modules/desktop_capture/mouse_cursor.h"
|
|
#include "modules/desktop_capture/mouse_cursor_monitor.h"
|
|
#include "modules/desktop_capture/shared_memory.h"
|
|
#include "rtc_base/constructor_magic.h"
|
|
#include "rtc_base/system/rtc_export.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// A wrapper for DesktopCapturer that also captures mouse using specified
|
|
// MouseCursorMonitor and renders it on the generated streams.
|
|
class RTC_EXPORT DesktopAndCursorComposer
|
|
: public DesktopCapturer,
|
|
public DesktopCapturer::Callback,
|
|
public MouseCursorMonitor::Callback {
|
|
public:
|
|
// 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,
|
|
const DesktopCaptureOptions& options);
|
|
|
|
~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(
|
|
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
|
|
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;
|
|
|
|
// Constructor to delegate both deprecated and new constructors and allows
|
|
// test cases to use a fake MouseCursorMonitor implementation.
|
|
DesktopAndCursorComposer(DesktopCapturer* desktop_capturer,
|
|
MouseCursorMonitor* mouse_monitor);
|
|
|
|
// DesktopCapturer::Callback interface.
|
|
void OnCaptureResult(DesktopCapturer::Result result,
|
|
std::unique_ptr<DesktopFrame> frame) override;
|
|
|
|
const std::unique_ptr<DesktopCapturer> desktop_capturer_;
|
|
const std::unique_ptr<MouseCursorMonitor> mouse_monitor_;
|
|
|
|
DesktopCapturer::Callback* callback_;
|
|
|
|
std::unique_ptr<MouseCursor> cursor_;
|
|
DesktopVector cursor_position_;
|
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(DesktopAndCursorComposer);
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_
|