Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(832)

Side by Side Diff: webrtc/modules/desktop_capture/win/dxgi_duplicator_container.h

Issue 2099123002: [Chromoting] Improve DirectX capturer to support multiple outputs (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_DUPLICATOR_CONTAINER_H_
12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTAINER_H_
13
14 #include <vector>
15
16 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/modules/desktop_capture/desktop_frame.h"
18 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
19 #include "webrtc/modules/desktop_capture/desktop_region.h"
20 #include "webrtc/modules/desktop_capture/win/d3d_device.h"
21 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h"
22 #include "webrtc/modules/desktop_capture/win/dxgi_context.h"
23
24 namespace webrtc {
25
26 // A container for all the objects we need to call Windows DirectX based capture
27 // APIs. Note, one application can only have one IDXGIOutputDuplication instance
28 // per output, so this class should be singleton.
29 //
30 // Consumers should create a DxgiContext and keep it through consumer's
31 // lifetime. Calls Prepare function with the DxgiContext before each Duplicate
32 // function calls. If a previous Prepare function call returns true, but a later
33 // one returns false, this usually means the display mode is changing. Consumers
34 // should retry after a while. (Typically 50 milliseconds, but according to
35 // hardware performance, this time may be various.)
36 class DxgiDuplicatorContainer {
37 public:
38 // Creates or retrieves the singleton instance of DxgiDuplicatorContainer.
39 static DxgiDuplicatorContainer* Instance();
40
41 // Destructs current instance. We need to make sure COM components and their
42 // containers are destructed in correct order.
43 ~DxgiDuplicatorContainer();
44
45 // Initializes all the components and updates |context|. This function equals
46 // to call Prepare() and Setup(DxgiContext*) sequentially.
47 bool Prepare(DxgiContext* context);
48
49 // Initializes all the components. Returns false if system does not support
50 // DirectX based capture, or system resource is not enough to support to
51 // capture all monitors. By default, only four applications can capture the
52 // screen with DirectX based capture simultaneously. Returns true if this
53 // instance has been initialized already.
54 bool Prepare();
55
56 // Captures current screen and writes into target. Since we are using double
57 // buffering, |last_frame|.updated_region() is used to represent the not
58 // updated regions in current |target| frame, which should also be copied this
59 // time.
60 // TODO(zijiehe): Windows cannot guarantee the frames returned by each
61 // IDXGIOutputDuplication are synchronized. But we are using a totally
62 // different threading model than the way Windows suggested, it's hard to
63 // synchronize them manually. But we should find a way to do it.
64 bool Duplicate(DxgiContext* context,
65 DesktopFrame* target,
66 const DesktopFrame* last_frame);
67
68 // Captures one screen and writes into target. If id < 0 or greater than
69 // the total screen count of all the Duplicators, this function returns false.
70 bool Duplicate(DxgiContext* context,
71 int id,
72 DesktopFrame* target,
73 const DesktopFrame* last_frame);
74
75 DesktopVector dpi() const {
76 return dpi_;
77 }
78
79 // Returns entire desktop size.
80 DesktopRect desktop_rect() const {
81 return desktop_rect_;
82 }
83
84 // Returns a DesktopSize to cover entire desktop_rect. This may be different
85 // than desktop_rect().size(), since top-left screen does not need to start
86 // from (0, 0).
87 DesktopSize desktop_size() const {
88 return DesktopSize(desktop_rect_.right(), desktop_rect_.bottom());
89 }
90
91 // Returns the size of one screen. If id < 0 or greater than the total screen
92 // count of all the Duplicators, this function returns an empty DesktopRect.
93 DesktopRect ScreenRect(int id) const;
94
95 // Returns the count of screens on the system. These screens can be retrieved
96 // by an integer in the range of [0, ScreenCount()).
97 int ScreenCount() const;
98
99 private:
100 // A class to allow only one thread to enter. This class is used to make sure
101 // only one Initialize function call is being performed.
102 class SingleEntry {
103 public:
104 bool Enter();
105 void Exit();
106 bool Hold() const;
107
108 private:
109 rtc::CriticalSection lock_;
110 bool entered_ = false;
111 };
112
113 // A helper class to execute SingleEntry::Exit in its destructor.
114 class AutoExit;
115
116 // Updates DxgiContext if needed.
117 void Setup(DxgiContext* context);
118
119 bool DoInitialize();
120
121 // Clears all COM components referred by this instance. So next Prepare()
122 // call will eventually initialize this instance again.
123 void Deinitialize();
124
125 rtc::CriticalSection lock_;
126 SingleEntry initializing_;
127 int64_t initialize_time_nanos_ = 0;
128 DesktopRect desktop_rect_;
129 DesktopVector dpi_;
130 std::vector<D3dDevice> devices_;
131 std::vector<DxgiAdapterDuplicator> duplicators_;
132 };
133
134 } // namespace webrtc
135
136 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698