• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  private:
39   static std::unique_ptr<DesktopFrameCGImage> CreateFromCGImage(
40       rtc::ScopedCFTypeRef<CGImageRef> cg_image);
41 
42   // This constructor expects |cg_image| to hold a non-null CGImageRef.
43   DesktopFrameCGImage(DesktopSize size,
44                       int stride,
45                       uint8_t* data,
46                       rtc::ScopedCFTypeRef<CGImageRef> cg_image,
47                       rtc::ScopedCFTypeRef<CFDataRef> cg_data);
48 
49   const rtc::ScopedCFTypeRef<CGImageRef> cg_image_;
50   const rtc::ScopedCFTypeRef<CFDataRef> cg_data_;
51 
52   RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameCGImage);
53 };
54 
55 }  // namespace webrtc
56 
57 #endif  // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_CGIMAGE_H_
58