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 <memory> 15 16 #include "modules/desktop_capture/desktop_capture_options.h" 17 #include "modules/desktop_capture/desktop_capture_types.h" 18 #include "modules/desktop_capture/desktop_capturer.h" 19 #include "modules/desktop_capture/desktop_frame.h" 20 #include "modules/desktop_capture/desktop_geometry.h" 21 #include "modules/desktop_capture/mouse_cursor.h" 22 #include "modules/desktop_capture/mouse_cursor_monitor.h" 23 #include "modules/desktop_capture/shared_memory.h" 24 #include "rtc_base/constructor_magic.h" 25 #include "rtc_base/system/rtc_export.h" 26 27 namespace webrtc { 28 29 // A wrapper for DesktopCapturer that also captures mouse using specified 30 // MouseCursorMonitor and renders it on the generated streams. 31 class RTC_EXPORT DesktopAndCursorComposer 32 : public DesktopCapturer, 33 public DesktopCapturer::Callback, 34 public MouseCursorMonitor::Callback { 35 public: 36 // Creates a new composer that captures mouse cursor using 37 // MouseCursorMonitor::Create(options) and renders it into the frames 38 // generated by |desktop_capturer|. 39 DesktopAndCursorComposer(std::unique_ptr<DesktopCapturer> desktop_capturer, 40 const DesktopCaptureOptions& options); 41 42 ~DesktopAndCursorComposer() override; 43 44 // Creates a new composer that relies on an external source for cursor shape 45 // and position information via the MouseCursorMonitor::Callback interface. 46 static std::unique_ptr<DesktopAndCursorComposer> 47 CreateWithoutMouseCursorMonitor( 48 std::unique_ptr<DesktopCapturer> desktop_capturer); 49 50 // DesktopCapturer interface. 51 void Start(DesktopCapturer::Callback* callback) override; 52 void SetSharedMemoryFactory( 53 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; 54 void CaptureFrame() override; 55 void SetExcludedWindow(WindowId window) override; 56 bool GetSourceList(SourceList* sources) override; 57 bool SelectSource(SourceId id) override; 58 bool FocusOnSelectedSource() override; 59 bool IsOccluded(const DesktopVector& pos) override; 60 61 // MouseCursorMonitor::Callback interface. 62 void OnMouseCursor(MouseCursor* cursor) override; 63 void OnMouseCursorPosition(const DesktopVector& position) override; 64 65 private: 66 // Allows test cases to use a fake MouseCursorMonitor implementation. 67 friend class DesktopAndCursorComposerTest; 68 69 // Constructor to delegate both deprecated and new constructors and allows 70 // test cases to use a fake MouseCursorMonitor implementation. 71 DesktopAndCursorComposer(DesktopCapturer* desktop_capturer, 72 MouseCursorMonitor* mouse_monitor); 73 74 // DesktopCapturer::Callback interface. 75 void OnCaptureResult(DesktopCapturer::Result result, 76 std::unique_ptr<DesktopFrame> frame) override; 77 78 const std::unique_ptr<DesktopCapturer> desktop_capturer_; 79 const std::unique_ptr<MouseCursorMonitor> mouse_monitor_; 80 81 DesktopCapturer::Callback* callback_; 82 83 std::unique_ptr<MouseCursor> cursor_; 84 DesktopVector cursor_position_; 85 DesktopRect previous_cursor_rect_; 86 bool cursor_changed_ = false; 87 88 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopAndCursorComposer); 89 }; 90 91 } // namespace webrtc 92 93 #endif // MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_ 94