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

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

Issue 2682913002: [DesktopCapture] Detect screen resolution changes in DirectX capturer (Closed)
Patch Set: Resolve review comments Created 3 years, 10 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
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_
13 13
14 #include <D3DCommon.h> 14 #include <D3DCommon.h>
15 15
16 #include <memory> 16 #include <memory>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/criticalsection.h" 19 #include "webrtc/base/criticalsection.h"
20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" 20 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
21 #include "webrtc/modules/desktop_capture/desktop_region.h" 21 #include "webrtc/modules/desktop_capture/desktop_region.h"
22 #include "webrtc/modules/desktop_capture/resolution_change_detector.h"
22 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" 23 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
23 #include "webrtc/modules/desktop_capture/win/d3d_device.h" 24 #include "webrtc/modules/desktop_capture/win/d3d_device.h"
24 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" 25 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h"
25 26
26 namespace webrtc { 27 namespace webrtc {
27 28
28 // A controller for all the objects we need to call Windows DirectX capture APIs 29 // A controller for all the objects we need to call Windows DirectX capture APIs
29 // It's a singleton because only one IDXGIOutputDuplication instance per monitor 30 // It's a singleton because only one IDXGIOutputDuplication instance per monitor
30 // is allowed per application. 31 // is allowed per application.
31 // 32 //
32 // Consumers should create a DxgiDuplicatorController::Context and keep it 33 // Consumers should create a DxgiDuplicatorController::Context and keep it
33 // throughout their lifetime, and pass it when calling Duplicate(). Consumers 34 // throughout their lifetime, and pass it when calling Duplicate(). Consumers
34 // can also call IsSupported() to determine whether the system supports DXGI 35 // can also call IsSupported() to determine whether the system supports DXGI
35 // duplicator or not. If a previous IsSupported() function call returns true, 36 // duplicator or not. If a previous IsSupported() function call returns true,
36 // but a later Duplicate() returns false, this usually means the display mode is 37 // but a later Duplicate() returns false, this usually means the display mode is
37 // changing. Consumers should retry after a while. (Typically 50 milliseconds, 38 // changing. Consumers should retry after a while. (Typically 50 milliseconds,
38 // but according to hardware performance, this time may vary.) 39 // but according to hardware performance, this time may vary.)
39 class DxgiDuplicatorController { 40 class DxgiDuplicatorController {
40 public: 41 public:
41 // A context to store the status of a single consumer of 42 // A context to store the status of a single consumer of
42 // DxgiDuplicatorController. 43 // DxgiDuplicatorController.
43 class Context { 44 class Context {
44 public: 45 public:
45 Context(); 46 Context();
46 // Unregister this Context instance from all Dxgi duplicators during 47 // Unregister this Context instance from all Dxgi duplicators during
47 // destructing. 48 // destructing.
48 ~Context(); 49 ~Context();
49 50
51 // Reset current Context, so it will be reinitialized next time.
52 void Reset();
53
50 private: 54 private:
51 friend class DxgiDuplicatorController; 55 friend class DxgiDuplicatorController;
52 56
53 // A Context will have an exactly same |identity_| as 57 // A Context will have an exactly same |identity_| as
54 // DxgiDuplicatorController, to ensure it has been correctly setted up after 58 // DxgiDuplicatorController, to ensure it has been correctly setted up after
55 // each DxgiDuplicatorController::Initialize(). 59 // each DxgiDuplicatorController::Initialize().
56 int identity_ = 0; 60 int identity_ = 0;
57 61
58 // Child DxgiAdapterDuplicator::Context belongs to this Context. 62 // Child DxgiAdapterDuplicator::Context belongs to this Context.
59 std::vector<DxgiAdapterDuplicator::Context> contexts_; 63 std::vector<DxgiAdapterDuplicator::Context> contexts_;
(...skipping 20 matching lines...) Expand all
80 // Destructs current instance. We need to make sure COM components and their 84 // Destructs current instance. We need to make sure COM components and their
81 // containers are destructed in correct order. 85 // containers are destructed in correct order.
82 ~DxgiDuplicatorController(); 86 ~DxgiDuplicatorController();
83 87
84 // All the following functions implicitly call Initialize() function if 88 // All the following functions implicitly call Initialize() function if
85 // current instance has not been initialized. 89 // current instance has not been initialized.
86 90
87 // Detects whether the system supports DXGI based capturer. 91 // Detects whether the system supports DXGI based capturer.
88 bool IsSupported(); 92 bool IsSupported();
89 93
94 // Calls Deinitialize() function with lock. Consumers can call this function
95 // to force the DxgiDuplicatorController to be reinitialized to avoid an
96 // expected failure in next Duplicate() call.
97 void Reset();
98
90 // Returns a copy of D3dInfo composed by last Initialize() function call. 99 // Returns a copy of D3dInfo composed by last Initialize() function call.
91 bool RetrieveD3dInfo(D3dInfo* info); 100 bool RetrieveD3dInfo(D3dInfo* info);
92 101
93 // Captures current screen and writes into target. Since we are using double 102 // Captures current screen and writes into target. Since we are using double
94 // buffering, |last_frame|.updated_region() is used to represent the not 103 // buffering, |last_frame|.updated_region() is used to represent the not
95 // updated regions in current |target| frame, which should also be copied this 104 // updated regions in current |target| frame, which should also be copied this
96 // time. 105 // time.
97 // TODO(zijiehe): Windows cannot guarantee the frames returned by each 106 // TODO(zijiehe): Windows cannot guarantee the frames returned by each
98 // IDXGIOutputDuplication are synchronized. But we are using a totally 107 // IDXGIOutputDuplication are synchronized. But we are using a totally
99 // different threading model than the way Windows suggested, it's hard to 108 // different threading model than the way Windows suggested, it's hard to
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 bool ContextExpired(const Context* const context) const; 169 bool ContextExpired(const Context* const context) const;
161 170
162 // Updates Context if needed. 171 // Updates Context if needed.
163 void Setup(Context* context); 172 void Setup(Context* context);
164 173
165 // Do the real duplication work. |monitor_id < 0| to capture entire screen. 174 // Do the real duplication work. |monitor_id < 0| to capture entire screen.
166 bool DoDuplicate(Context* context, 175 bool DoDuplicate(Context* context,
167 int monitor_id, 176 int monitor_id,
168 SharedDesktopFrame* target); 177 SharedDesktopFrame* target);
169 178
179 bool DoDuplicateUnlocked(Context* context,
180 int monitor_id,
181 SharedDesktopFrame* target);
182
170 // This lock must be locked whenever accessing any of the following objects. 183 // This lock must be locked whenever accessing any of the following objects.
171 rtc::CriticalSection lock_; 184 rtc::CriticalSection lock_;
172 185
173 // A self-incremented integer to compare with the one in Context, to 186 // A self-incremented integer to compare with the one in Context, to
174 // ensure a Context has been initialized after DxgiDuplicatorController. 187 // ensure a Context has been initialized after DxgiDuplicatorController.
175 int identity_ = 0; 188 int identity_ = 0;
176 DesktopRect desktop_rect_; 189 DesktopRect desktop_rect_;
177 DesktopVector dpi_; 190 DesktopVector dpi_;
178 std::vector<DxgiAdapterDuplicator> duplicators_; 191 std::vector<DxgiAdapterDuplicator> duplicators_;
179 D3dInfo d3d_info_; 192 D3dInfo d3d_info_;
193 ResolutionChangeDetector resolution_change_detector_;
180 }; 194 };
181 195
182 } // namespace webrtc 196 } // namespace webrtc
183 197
184 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ 198 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698