tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

desktop_frame_provider.h (2144B)


      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                           ScopedCFTypeRef<IOSurfaceRef> io_surface);
     45 
     46  // Expected to be called before stopping the CGDisplayStreamRef streams.
     47  void Release();
     48 
     49  bool allow_iosurface() const { return allow_iosurface_; }
     50 
     51 private:
     52  SequenceChecker thread_checker_;
     53  const bool allow_iosurface_;
     54 
     55  // Most recent IOSurface that contains a capture of matching display.
     56  std::map<CGDirectDisplayID, std::unique_ptr<SharedDesktopFrame>> io_surfaces_;
     57 };
     58 
     59 }  // namespace webrtc
     60 
     61 #endif  // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_PROVIDER_H_