desktop_and_cursor_conditional_composer.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_HOST_DESKTOP_AND_CURSOR_CONDITIONAL_COMPOSER_H_
  5. #define REMOTING_HOST_DESKTOP_AND_CURSOR_CONDITIONAL_COMPOSER_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "remoting/protocol/desktop_capturer.h"
  10. #include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h"
  11. #include "third_party/webrtc/modules/desktop_capture/desktop_capture_metadata.h"
  12. #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
  13. #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h"
  14. #include "third_party/webrtc/modules/desktop_capture/shared_memory.h"
  15. namespace remoting {
  16. // A wrapper for DesktopAndCursorComposer that allows compositing of the cursor
  17. // to be enabled and disabled, and which exposes a WeakPtr to simplify memory
  18. // management.
  19. class DesktopAndCursorConditionalComposer : public DesktopCapturer {
  20. public:
  21. explicit DesktopAndCursorConditionalComposer(
  22. std::unique_ptr<DesktopCapturer> desktop_capturer);
  23. ~DesktopAndCursorConditionalComposer() override;
  24. base::WeakPtr<DesktopAndCursorConditionalComposer> GetWeakPtr();
  25. void SetComposeEnabled(bool enabled);
  26. void SetMouseCursor(std::unique_ptr<webrtc::MouseCursor> mouse_cursor);
  27. void SetMouseCursorPosition(const webrtc::DesktopVector& position);
  28. // DesktopCapturer interface.
  29. void Start(webrtc::DesktopCapturer::Callback* callback) override;
  30. void SetSharedMemoryFactory(std::unique_ptr<webrtc::SharedMemoryFactory>
  31. shared_memory_factory) override;
  32. void CaptureFrame() override;
  33. void SetExcludedWindow(webrtc::WindowId window) override;
  34. bool GetSourceList(SourceList* sources) override;
  35. bool SelectSource(SourceId id) override;
  36. bool FocusOnSelectedSource() override;
  37. bool IsOccluded(const webrtc::DesktopVector& pos) override;
  38. #if defined(WEBRTC_USE_GIO)
  39. void GetMetadataAsync(base::OnceCallback<void(webrtc::DesktopCaptureMetadata)>
  40. callback) override;
  41. #endif
  42. private:
  43. DesktopAndCursorConditionalComposer(
  44. const DesktopAndCursorConditionalComposer&) = delete;
  45. DesktopAndCursorConditionalComposer& operator=(
  46. const DesktopAndCursorConditionalComposer&) = delete;
  47. std::unique_ptr<webrtc::MouseCursor> mouse_cursor_;
  48. bool compose_enabled_ = false;
  49. #if defined(WEBRTC_USE_GIO)
  50. // Following pointer is not owned by |this| class.
  51. raw_ptr<DesktopCapturer> desktop_capturer_ = nullptr;
  52. #endif
  53. std::unique_ptr<webrtc::DesktopAndCursorComposer> capturer_;
  54. base::WeakPtrFactory<DesktopAndCursorConditionalComposer> weak_factory_{this};
  55. };
  56. } // namespace remoting
  57. #endif // REMOTING_HOST_DESKTOP_AND_CURSOR_CONDITIONAL_COMPOSER_H_