desktop_and_cursor_composer.h (4067B)
1 /* 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_ 12 #define MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_ 13 14 #include <cstdint> 15 #include <memory> 16 17 #include "modules/desktop_capture/desktop_capture_metadata.h" 18 #include "modules/desktop_capture/desktop_capture_options.h" 19 #include "modules/desktop_capture/desktop_capture_types.h" 20 #include "modules/desktop_capture/desktop_capturer.h" 21 #include "modules/desktop_capture/desktop_frame.h" 22 #include "modules/desktop_capture/desktop_geometry.h" 23 #include "modules/desktop_capture/mouse_cursor.h" 24 #include "modules/desktop_capture/mouse_cursor_monitor.h" 25 #include "modules/desktop_capture/shared_memory.h" 26 #include "rtc_base/system/rtc_export.h" 27 28 namespace webrtc { 29 30 // A wrapper for DesktopCapturer that also captures mouse using specified 31 // MouseCursorMonitor and renders it on the generated streams. 32 class RTC_EXPORT DesktopAndCursorComposer 33 : public DesktopCapturer, 34 public DesktopCapturer::Callback, 35 public MouseCursorMonitor::Callback { 36 public: 37 // Creates a new composer that captures mouse cursor using 38 // MouseCursorMonitor::Create(options) and renders it into the frames 39 // generated by `desktop_capturer`. 40 DesktopAndCursorComposer(std::unique_ptr<DesktopCapturer> desktop_capturer, 41 const DesktopCaptureOptions& options); 42 43 ~DesktopAndCursorComposer() override; 44 45 DesktopAndCursorComposer(const DesktopAndCursorComposer&) = delete; 46 DesktopAndCursorComposer& operator=(const DesktopAndCursorComposer&) = delete; 47 48 // Creates a new composer that relies on an external source for cursor shape 49 // and position information via the MouseCursorMonitor::Callback interface. 50 static std::unique_ptr<DesktopAndCursorComposer> 51 CreateWithoutMouseCursorMonitor( 52 std::unique_ptr<DesktopCapturer> desktop_capturer); 53 54 // DesktopCapturer interface. 55 void Start(DesktopCapturer::Callback* callback) override; 56 void SetSharedMemoryFactory( 57 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; 58 void CaptureFrame() override; 59 void SetExcludedWindow(WindowId window) override; 60 bool GetSourceList(SourceList* sources) override; 61 bool SelectSource(SourceId id) override; 62 bool FocusOnSelectedSource() override; 63 bool IsOccluded(const DesktopVector& pos) override; 64 void SetMaxFrameRate(uint32_t max_frame_rate) override; 65 #if defined(WEBRTC_USE_GIO) 66 DesktopCaptureMetadata GetMetadata() override; 67 #endif // defined(WEBRTC_USE_GIO) 68 69 // MouseCursorMonitor::Callback interface. 70 void OnMouseCursor(MouseCursor* cursor) override; 71 void OnMouseCursorPosition(const DesktopVector& position) override; 72 73 private: 74 // Allows test cases to use a fake MouseCursorMonitor implementation. 75 friend class DesktopAndCursorComposerTest; 76 77 // Constructor to delegate both deprecated and new constructors and allows 78 // test cases to use a fake MouseCursorMonitor implementation. 79 DesktopAndCursorComposer(DesktopCapturer* desktop_capturer, 80 MouseCursorMonitor* mouse_monitor); 81 82 // DesktopCapturer::Callback interface. 83 void OnFrameCaptureStart() override; 84 void OnCaptureResult(DesktopCapturer::Result result, 85 std::unique_ptr<DesktopFrame> frame) override; 86 87 const std::unique_ptr<DesktopCapturer> desktop_capturer_; 88 const std::unique_ptr<MouseCursorMonitor> mouse_monitor_; 89 90 DesktopCapturer::Callback* callback_; 91 92 std::unique_ptr<MouseCursor> cursor_; 93 DesktopVector cursor_position_; 94 DesktopRect previous_cursor_rect_; 95 bool cursor_changed_ = false; 96 }; 97 98 } // namespace webrtc 99 100 #endif // MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_