desktop_frame_iosurface.h (2008B)
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_IOSURFACE_H_ 12 #define MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_IOSURFACE_H_ 13 14 #include <CoreGraphics/CoreGraphics.h> 15 #include <IOSurface/IOSurface.h> 16 17 #include <memory> 18 19 #include "modules/desktop_capture/desktop_frame.h" 20 #include "sdk/objc/helpers/scoped_cftyperef.h" 21 22 namespace webrtc { 23 24 class DesktopFrameIOSurface final : public DesktopFrame { 25 public: 26 // Lock an IOSurfaceRef containing a snapshot of a display. Return NULL if 27 // failed to lock. `rect` specifies the portion of the surface that the 28 // DesktopFrame should be cropped to. 29 static std::unique_ptr<DesktopFrameIOSurface> Wrap( 30 ScopedCFTypeRef<IOSurfaceRef> io_surface, CGRect rect = {}); 31 32 ~DesktopFrameIOSurface() override; 33 34 DesktopFrameIOSurface(const DesktopFrameIOSurface&) = delete; 35 DesktopFrameIOSurface& operator=(const DesktopFrameIOSurface&) = delete; 36 37 private: 38 // `io_surface` must hold a non-null IOSurfaceRef that is already locked. 39 // `data` is the address of the first byte of data in `io_surface`'s locked 40 // buffer. 41 // `width` and `height` make up the dimensions of `io_surface` in pixels. 42 // `stride` is the number of bytes of a single row of pixels in `data`. 43 DesktopFrameIOSurface(ScopedCFTypeRef<IOSurfaceRef> io_surface, 44 uint8_t* data, 45 int32_t width, 46 int32_t height, 47 int32_t stride); 48 49 const ScopedCFTypeRef<IOSurfaceRef> io_surface_; 50 }; 51 52 } // namespace webrtc 53 54 #endif // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_IOSURFACE_H_