tor-browser

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

cropping_window_capturer.h (3357B)


      1 /*
      2 *  Copyright (c) 2014 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_CROPPING_WINDOW_CAPTURER_H_
     12 #define MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
     13 
     14 #include <memory>
     15 
     16 #include "modules/desktop_capture/desktop_capture_options.h"
     17 #include "modules/desktop_capture/desktop_capture_types.h"
     18 #include "modules/desktop_capture/desktop_capturer.h"
     19 #include "modules/desktop_capture/desktop_frame.h"
     20 #include "modules/desktop_capture/desktop_geometry.h"
     21 #include "modules/desktop_capture/shared_memory.h"
     22 #include "rtc_base/system/rtc_export.h"
     23 
     24 namespace webrtc {
     25 
     26 // WindowCapturer implementation that uses a screen capturer to capture the
     27 // whole screen and crops the video frame to the window area when the captured
     28 // window is on top.
     29 class RTC_EXPORT CroppingWindowCapturer : public DesktopCapturer,
     30                                          public DesktopCapturer::Callback {
     31 public:
     32  static std::unique_ptr<DesktopCapturer> CreateCapturer(
     33      const DesktopCaptureOptions& options);
     34 
     35  ~CroppingWindowCapturer() override;
     36 
     37  // DesktopCapturer implementation.
     38  void Start(DesktopCapturer::Callback* callback) override;
     39  void SetSharedMemoryFactory(
     40      std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
     41  void CaptureFrame() override;
     42  void SetExcludedWindow(WindowId window) override;
     43  bool GetSourceList(SourceList* sources) override;
     44  bool SelectSource(SourceId id) override;
     45  bool FocusOnSelectedSource() override;
     46  bool IsOccluded(const DesktopVector& pos) override;
     47 
     48  // DesktopCapturer::Callback implementation, passed to `screen_capturer_` to
     49  // intercept the capture result.
     50  void OnCaptureResult(DesktopCapturer::Result result,
     51                       std::unique_ptr<DesktopFrame> frame) override;
     52 
     53 protected:
     54  explicit CroppingWindowCapturer(const DesktopCaptureOptions& options);
     55 
     56  // The platform implementation should override these methods.
     57 
     58  // Returns true if it is OK to capture the whole screen and crop to the
     59  // selected window, i.e. the selected window is opaque, rectangular, and not
     60  // occluded.
     61  virtual bool ShouldUseScreenCapturer() = 0;
     62 
     63  // Returns the window area relative to the top left of the virtual screen
     64  // within the bounds of the virtual screen. This function should return the
     65  // DesktopRect in full desktop coordinates, i.e. the top-left monitor starts
     66  // from (0, 0).
     67  virtual DesktopRect GetWindowRectInVirtualScreen() = 0;
     68 
     69  WindowId selected_window() const { return selected_window_; }
     70  WindowId excluded_window() const { return excluded_window_; }
     71  DesktopCapturer* window_capturer() const { return window_capturer_.get(); }
     72 
     73 private:
     74  DesktopCaptureOptions options_;
     75  DesktopCapturer::Callback* callback_;
     76  std::unique_ptr<DesktopCapturer> window_capturer_;
     77  std::unique_ptr<DesktopCapturer> screen_capturer_;
     78  SourceId selected_window_;
     79  WindowId excluded_window_;
     80 };
     81 
     82 }  // namespace webrtc
     83 
     84 #endif  // MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_