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 "modules/desktop_capture/shared_desktop_frame.h" 21 #include "rtc_base/thread_checker.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 // The caller takes ownership of the returned desktop frame. Otherwise 32 // returns null if |display_id| is invalid or not ready. Note that this 33 // function does not remove the frame from the internal container. Caller 34 // has to call the Release function. 35 std::unique_ptr<DesktopFrame> TakeLatestFrameForDisplay( 36 CGDirectDisplayID display_id); 37 38 // OS sends the latest IOSurfaceRef through 39 // CGDisplayStreamFrameAvailableHandler callback; we store it here. 40 void InvalidateIOSurface(CGDirectDisplayID display_id, 41 rtc::ScopedCFTypeRef<IOSurfaceRef> io_surface); 42 43 // Expected to be called before stopping the CGDisplayStreamRef streams. 44 void Release(); 45 46 private: 47 rtc::ThreadChecker thread_checker_; 48 const bool allow_iosurface_; 49 50 // Most recent IOSurface that contains a capture of matching display. 51 std::map<CGDirectDisplayID, std::unique_ptr<SharedDesktopFrame>> io_surfaces_; 52 53 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameProvider); 54 }; 55 56 } // namespace webrtc 57 58 #endif // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_PROVIDER_H_ 59