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