tor-browser

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

dxgi_adapter_duplicator.h (3547B)


      1 /*
      2 *  Copyright (c) 2016 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_WIN_DXGI_ADAPTER_DUPLICATOR_H_
     12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_ADAPTER_DUPLICATOR_H_
     13 
     14 #include <cstdint>
     15 #include <optional>
     16 #include <string>
     17 #include <vector>
     18 
     19 #include "modules/desktop_capture/desktop_geometry.h"
     20 #include "modules/desktop_capture/shared_desktop_frame.h"
     21 #include "modules/desktop_capture/win/d3d_device.h"
     22 #include "modules/desktop_capture/win/dxgi_context.h"
     23 #include "modules/desktop_capture/win/dxgi_output_duplicator.h"
     24 
     25 namespace webrtc {
     26 
     27 // A container of DxgiOutputDuplicators to duplicate monitors attached to a
     28 // single video card.
     29 class DxgiAdapterDuplicator {
     30 public:
     31  using Context = DxgiAdapterContext;
     32 
     33  // Creates an instance of DxgiAdapterDuplicator from a D3dDevice. Only
     34  // DxgiDuplicatorController can create an instance.
     35  explicit DxgiAdapterDuplicator(const D3dDevice& device);
     36 
     37  // Move constructor, to make it possible to store instances of
     38  // DxgiAdapterDuplicator in std::vector<>.
     39  DxgiAdapterDuplicator(DxgiAdapterDuplicator&& other);
     40 
     41  ~DxgiAdapterDuplicator();
     42 
     43  // Initializes the DxgiAdapterDuplicator from a D3dDevice.
     44  bool Initialize();
     45 
     46  // Sequentially calls Duplicate function of all the DxgiOutputDuplicator
     47  // instances owned by this instance, and writes into `target`.
     48  bool Duplicate(Context* context, SharedDesktopFrame* target);
     49 
     50  // Captures one monitor and writes into `target`. `monitor_id` should be
     51  // between [0, screen_count()).
     52  bool DuplicateMonitor(Context* context,
     53                        int monitor_id,
     54                        SharedDesktopFrame* target);
     55 
     56  // Returns desktop rect covered by this DxgiAdapterDuplicator.
     57  DesktopRect desktop_rect() const { return desktop_rect_; }
     58 
     59  // Returns the device scale factor of screen identified by `screen_id`, which
     60  // is owned by this DxgiAdapterDuplicator. `screen_id` should be between [0,
     61  // screen_count()).
     62  std::optional<float> GetDeviceScaleFactor(int screen_id) const;
     63 
     64  // Returns the size of one screen owned by this DxgiAdapterDuplicator. `id`
     65  // should be between [0, screen_count()).
     66  DesktopRect ScreenRect(int id) const;
     67 
     68  // Returns the device name of one screen owned by this DxgiAdapterDuplicator
     69  // in utf8 encoding. `id` should be between [0, screen_count()).
     70  const std::string& GetDeviceName(int id) const;
     71 
     72  // Returns the count of screens owned by this DxgiAdapterDuplicator. These
     73  // screens can be retrieved by an interger in the range of
     74  // [0, screen_count()).
     75  int screen_count() const;
     76 
     77  void Setup(Context* context);
     78 
     79  void Unregister(const Context* const context);
     80 
     81  // The minimum num_frames_captured() returned by `duplicators_`.
     82  int64_t GetNumFramesCaptured(int monitor_id) const;
     83 
     84  // Moves `desktop_rect_` and all underlying `duplicators_`. See
     85  // DxgiDuplicatorController::TranslateRect().
     86  void TranslateRect(const DesktopVector& position);
     87 
     88 private:
     89  bool DoInitialize();
     90 
     91  const D3dDevice device_;
     92  std::vector<DxgiOutputDuplicator> duplicators_;
     93  DesktopRect desktop_rect_;
     94 };
     95 
     96 }  // namespace webrtc
     97 
     98 #endif  // MODULES_DESKTOP_CAPTURE_WIN_DXGI_ADAPTER_DUPLICATOR_H_