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

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

Issue 2299663003: [WebRTC] Two DirectX capturers cannot work concurrently (Closed)
Patch Set: Sync latest changes Created 4 years, 3 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_OUTPUT_DUPLICATOR_H_ 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
13 13
14 #include <comdef.h> 14 #include <comdef.h>
15 #include <wrl/client.h> 15 #include <wrl/client.h>
16 #include <DXGI.h> 16 #include <DXGI.h>
17 #include <DXGI1_2.h> 17 #include <DXGI1_2.h>
18 18
19 #include <memory> 19 #include <memory>
20 #include <vector> 20 #include <vector>
21 21
22 #include "webrtc/base/criticalsection.h" 22 #include "webrtc/base/criticalsection.h"
23 #include "webrtc/base/thread_annotations.h" 23 #include "webrtc/base/thread_annotations.h"
24 #include "webrtc/modules/desktop_capture/desktop_frame.h"
25 #include "webrtc/modules/desktop_capture/desktop_geometry.h" 24 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
26 #include "webrtc/modules/desktop_capture/desktop_region.h" 25 #include "webrtc/modules/desktop_capture/desktop_region.h"
26 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
27 #include "webrtc/modules/desktop_capture/win/d3d_device.h" 27 #include "webrtc/modules/desktop_capture/win/d3d_device.h"
28 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" 28 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h"
29 29
30 namespace webrtc { 30 namespace webrtc {
31 31
32 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one 32 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one
33 // video card. None of functions in this class is thread-safe. 33 // video card. None of functions in this class is thread-safe.
34 // TODO(zijiehe): Understand the meaning of rotation. 34 // TODO(zijiehe): Understand the meaning of rotation.
35 class DxgiOutputDuplicator { 35 class DxgiOutputDuplicator {
36 public: 36 public:
(...skipping 16 matching lines...) Expand all
53 53
54 // Destructs this instance. We need to make sure texture_ has been released 54 // Destructs this instance. We need to make sure texture_ has been released
55 // before duplication_. 55 // before duplication_.
56 ~DxgiOutputDuplicator(); 56 ~DxgiOutputDuplicator();
57 57
58 // Initializes duplication_ object. 58 // Initializes duplication_ object.
59 bool Initialize(); 59 bool Initialize();
60 60
61 // Copies the content of current IDXGIOutput to the |target|. To improve the 61 // Copies the content of current IDXGIOutput to the |target|. To improve the
62 // performance, this function copies only regions merged from 62 // performance, this function copies only regions merged from
63 // |last_frame|.updated_region and DetectUpdatedRegion(). The |offset| decides 63 // |context|->updated_region and DetectUpdatedRegion(). The |offset| decides
64 // the 64 // the offset in the |target| where the content should be copied to. i.e. this
65 // offset in the |target| where the content should be copied to. i.e. this
66 // function copies the content to the rectangle of (offset.x(), offset.y()) to 65 // function copies the content to the rectangle of (offset.x(), offset.y()) to
67 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()). 66 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()).
68 // The |last_frame| is always expected to be translated by the same offset.
69 // Returns false in case of a failure. 67 // Returns false in case of a failure.
70 bool Duplicate(Context* context, 68 bool Duplicate(Context* context,
71 const DesktopFrame* last_frame, 69 DesktopVector offset,
72 const DesktopVector offset, 70 SharedDesktopFrame* target);
73 DesktopFrame* target);
74 71
75 // Returns the desktop rect covered by this DxgiOutputDuplicator. 72 // Returns the desktop rect covered by this DxgiOutputDuplicator.
76 DesktopRect desktop_rect() const { return desktop_rect_; } 73 DesktopRect desktop_rect() const { return desktop_rect_; }
77 74
78 private: 75 private:
79 friend class DxgiAdapterDuplicator; 76 friend class DxgiAdapterDuplicator;
80 77
81 // Detects updated region translated by offset from IDXGIOutput1. This 78 // Detects updated region translated by offset from IDXGIOutput1. This
82 // function will set the |updated_region| as entire DesktopRect starts from 79 // function will set the |updated_region| as entire DesktopRect starts from
83 // offset if it failed to execute Windows APIs. 80 // offset if it failed to execute Windows APIs.
84 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, 81 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
85 const DesktopVector offset, 82 DesktopVector offset,
86 DesktopRegion* updated_region); 83 DesktopRegion* updated_region);
87 84
88 // Returns untranslated updated region, which are directly returned by Windows 85 // Returns untranslated updated region, which are directly returned by Windows
89 // APIs. Returns false in case of a failure. 86 // APIs. Returns false in case of a failure.
90 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, 87 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
91 DesktopRegion* updated_region); 88 DesktopRegion* updated_region);
92 89
93 bool ReleaseFrame(); 90 bool ReleaseFrame();
94 91
95 // Initializes duplication_ instance. Expects duplication_ is in empty status. 92 // Initializes duplication_ instance. Expects duplication_ is in empty status.
96 // Returns false if system does not support IDXGIOutputDuplication. 93 // Returns false if system does not support IDXGIOutputDuplication.
97 bool DuplicateOutput(); 94 bool DuplicateOutput();
98 95
99 // Returns a DesktopRect with the same size of desktop_size_, but translated 96 // Returns a DesktopRect with the same size of desktop_size_, but translated
100 // by offset. 97 // by offset.
101 DesktopRect TranslatedDesktopRect(const DesktopVector offset); 98 DesktopRect TranslatedDesktopRect(DesktopVector offset);
102 99
103 void Setup(Context* context); 100 void Setup(Context* context);
104 101
105 void Unregister(const Context* const context); 102 void Unregister(const Context* const context);
106 103
107 // Spreads changes from |context| to other registered Context(s) in 104 // Spreads changes from |context| to other registered Context(s) in
108 // contexts_. 105 // contexts_.
109 void SpreadContextChange(const Context* const context); 106 void SpreadContextChange(const Context* const context);
110 107
108 // Returns a DesktopRect in the coordinate of |texture_|->AsDesktopFrame().
109 DesktopRect SourceRect(DesktopRect rect);
110
111 // Returns a DesktopRect in the coordinate of |offset|.
112 DesktopRect TargetRect(DesktopRect rect, DesktopVector offset);
113
111 const D3dDevice& device_; 114 const D3dDevice& device_;
112 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_; 115 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_;
113 const DesktopRect desktop_rect_; 116 const DesktopRect desktop_rect_;
114 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; 117 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
115 DXGI_OUTDUPL_DESC desc_; 118 DXGI_OUTDUPL_DESC desc_;
116 std::vector<uint8_t> metadata; 119 std::vector<uint8_t> metadata;
117 std::unique_ptr<DxgiTexture> texture_; 120 std::unique_ptr<DxgiTexture> texture_;
118 121
119 // After each AcquireNextFrame() function call, updated_region_(s) of all 122 // After each AcquireNextFrame() function call, updated_region_(s) of all
120 // active Context(s) need to be updated. Since they have missed the 123 // active Context(s) need to be updated. Since they have missed the
121 // change this time. And during next Duplicate() function call, their 124 // change this time. And during next Duplicate() function call, their
122 // updated_region_ will be merged and copied. 125 // updated_region_ will be merged and copied.
123 std::vector<Context*> contexts_; 126 std::vector<Context*> contexts_;
127
128 // The last full frame of this output and its offset. If on AcquireNextFrame()
129 // failed because of timeout, i.e. no update, we can copy content from
130 // |last_frame_|.
131 std::unique_ptr<SharedDesktopFrame> last_frame_;
132 DesktopVector last_frame_offset_;
124 }; 133 };
125 134
126 } // namespace webrtc 135 } // namespace webrtc
127 136
128 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ 137 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698