xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/screen_capturer_fuchsia.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2022 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_SCREEN_CAPTURER_FUCHSIA_H_
12 #define MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_FUCHSIA_H_
13 
14 #include <fuchsia/sysmem/cpp/fidl.h>
15 #include <fuchsia/ui/composition/cpp/fidl.h>
16 #include <lib/sys/cpp/component_context.h>
17 
18 #include <memory>
19 #include <unordered_map>
20 
21 #include "modules/desktop_capture/desktop_capture_options.h"
22 #include "modules/desktop_capture/desktop_capturer.h"
23 #include "modules/desktop_capture/desktop_frame.h"
24 
25 namespace webrtc {
26 
27 class ScreenCapturerFuchsia final : public DesktopCapturer {
28  public:
29   ScreenCapturerFuchsia();
30   ~ScreenCapturerFuchsia() override;
31 
32   static bool CheckRequirements();
33 
34   // DesktopCapturer interface.
35   void Start(Callback* callback) override;
36   void CaptureFrame() override;
37   bool GetSourceList(SourceList* screens) override;
38   bool SelectSource(SourceId id) override;
39 
40  private:
41   fuchsia::sysmem::BufferCollectionConstraints GetBufferConstraints();
42   void SetupBuffers();
43   uint32_t GetPixelsPerRow(
44       const fuchsia::sysmem::ImageFormatConstraints& constraints);
45 
46   Callback* callback_ = nullptr;
47 
48   std::unique_ptr<sys::ComponentContext> component_context_;
49   fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator_;
50   fuchsia::ui::composition::AllocatorSyncPtr flatland_allocator_;
51   fuchsia::ui::composition::ScreenCaptureSyncPtr screen_capture_;
52   fuchsia::sysmem::BufferCollectionSyncPtr collection_;
53   fuchsia::sysmem::BufferCollectionInfo_2 buffer_collection_info_;
54   std::unordered_map<uint32_t, uint8_t*> virtual_memory_mapped_addrs_;
55 
56   bool fatal_error_;
57 
58   // Dimensions of the screen we are capturing
59   uint32_t width_;
60   uint32_t height_;
61 };
62 
63 }  // namespace webrtc
64 
65 #endif  // MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_FUCHSIA_H_
66