xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/mac/desktop_frame_cgimage.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 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_MAC_DESKTOP_FRAME_CGIMAGE_H_
12 #define MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_CGIMAGE_H_
13 
14 #include <CoreGraphics/CoreGraphics.h>
15 
16 #include <memory>
17 
18 #include "modules/desktop_capture/desktop_frame.h"
19 #include "sdk/objc/helpers/scoped_cftyperef.h"
20 
21 namespace webrtc {
22 
23 class DesktopFrameCGImage final : public DesktopFrame {
24  public:
25   // Create an image containing a snapshot of the display at the time this is
26   // being called.
27   static std::unique_ptr<DesktopFrameCGImage> CreateForDisplay(
28       CGDirectDisplayID display_id);
29 
30   // Create an image containing a snaphot of the given window at the time this
31   // is being called. This also works when the window is overlapped or in
32   // another workspace.
33   static std::unique_ptr<DesktopFrameCGImage> CreateForWindow(
34       CGWindowID window_id);
35 
36   ~DesktopFrameCGImage() override;
37 
38   DesktopFrameCGImage(const DesktopFrameCGImage&) = delete;
39   DesktopFrameCGImage& operator=(const DesktopFrameCGImage&) = delete;
40 
41  private:
42   static std::unique_ptr<DesktopFrameCGImage> CreateFromCGImage(
43       rtc::ScopedCFTypeRef<CGImageRef> cg_image);
44 
45   // This constructor expects `cg_image` to hold a non-null CGImageRef.
46   DesktopFrameCGImage(DesktopSize size,
47                       int stride,
48                       uint8_t* data,
49                       rtc::ScopedCFTypeRef<CGImageRef> cg_image,
50                       rtc::ScopedCFTypeRef<CFDataRef> cg_data);
51 
52   const rtc::ScopedCFTypeRef<CGImageRef> cg_image_;
53   const rtc::ScopedCFTypeRef<CFDataRef> cg_data_;
54 };
55 
56 }  // namespace webrtc
57 
58 #endif  // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_CGIMAGE_H_
59