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_PROVIDER_H_ 12 #define MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_PROVIDER_H_ 13 14 #include <CoreGraphics/CoreGraphics.h> 15 #include <IOSurface/IOSurface.h> 16 17 #include <map> 18 #include <memory> 19 20 #include "api/sequence_checker.h" 21 #include "modules/desktop_capture/shared_desktop_frame.h" 22 #include "sdk/objc/helpers/scoped_cftyperef.h" 23 24 namespace webrtc { 25 26 class DesktopFrameProvider { 27 public: 28 explicit DesktopFrameProvider(bool allow_iosurface); 29 ~DesktopFrameProvider(); 30 31 DesktopFrameProvider(const DesktopFrameProvider&) = delete; 32 DesktopFrameProvider& operator=(const DesktopFrameProvider&) = delete; 33 34 // The caller takes ownership of the returned desktop frame. Otherwise 35 // returns null if `display_id` is invalid or not ready. Note that this 36 // function does not remove the frame from the internal container. Caller 37 // has to call the Release function. 38 std::unique_ptr<DesktopFrame> TakeLatestFrameForDisplay( 39 CGDirectDisplayID display_id); 40 41 // OS sends the latest IOSurfaceRef through 42 // CGDisplayStreamFrameAvailableHandler callback; we store it here. 43 void InvalidateIOSurface(CGDirectDisplayID display_id, 44 rtc::ScopedCFTypeRef<IOSurfaceRef> io_surface); 45 46 // Expected to be called before stopping the CGDisplayStreamRef streams. 47 void Release(); 48 49 private: 50 SequenceChecker thread_checker_; 51 const bool allow_iosurface_; 52 53 // Most recent IOSurface that contains a capture of matching display. 54 std::map<CGDirectDisplayID, std::unique_ptr<SharedDesktopFrame>> io_surfaces_; 55 }; 56 57 } // namespace webrtc 58 59 #endif // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_PROVIDER_H_ 60