OLD | NEW |
---|---|
(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 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" | |
12 | |
13 #include <comdef.h> | |
14 #include <DXGI.h> | |
15 | |
16 #include "webrtc/base/logging.h" | |
17 | |
18 namespace webrtc { | |
19 | |
20 using Microsoft::WRL::ComPtr; | |
21 | |
22 namespace { | |
23 | |
24 bool IsValidRect(const RECT& rect) { | |
25 return rect.left >= 0 && rect.top >= 0 && | |
26 rect.right > rect.left && rect.bottom > rect.top; | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 bool DxgiAdapterDuplicator::Initialize(const D3dDevice& device) { | |
32 if (DoInitialize(device)) { | |
33 return true; | |
34 } | |
35 duplicators_.clear(); | |
36 return false; | |
37 } | |
38 | |
39 bool DxgiAdapterDuplicator::DoInitialize(const D3dDevice& device) { | |
40 for (int i = 0;; i++) { | |
41 ComPtr<IDXGIOutput> output; | |
42 _com_error error = device.dxgi_adapter()->EnumOutputs( | |
43 i, output.GetAddressOf()); | |
44 if (error.Error() == S_OK && output) { | |
45 DXGI_OUTPUT_DESC desc; | |
46 error = _com_error(output->GetDesc(&desc)); | |
47 if (error.Error() == S_OK) { | |
48 if (desc.AttachedToDesktop && IsValidRect(desc.DesktopCoordinates)) { | |
49 ComPtr<IDXGIOutput1> output1; | |
50 error = _com_error(output.As(&output1)); | |
51 if (error.Error() != S_OK || !output1) { | |
52 LOG(LS_WARNING) << "Failed to convert IDXGIOutput to IDXGIOutput1, " | |
53 "this usually means the system does not support " | |
54 "DirectX 11"; | |
55 return false; | |
56 } | |
57 duplicators_.emplace_back(device, output1, desc); | |
58 if (!duplicators_.back().Initialize()) { | |
59 return false; | |
60 } | |
61 if (desktop_rect_.is_empty()) { | |
62 desktop_rect_ = duplicators_.back().desktop_rect(); | |
63 } else { | |
64 desktop_rect_.JoinWith(duplicators_.back().desktop_rect()); | |
65 } | |
66 } | |
67 } else { | |
68 LOG(LS_WARNING) << "Failed to get output description of device " << i | |
69 << ", ignore."; | |
70 } | |
71 } else if (error.Error() == DXGI_ERROR_NOT_FOUND) { | |
72 return true; | |
Sergey Ulanov
2016/07/08 22:36:54
break; and return true after the loop
Hzj_jie
2016/07/11 00:54:59
Done.
| |
73 } else { | |
74 return false; | |
Sergey Ulanov
2016/07/08 22:36:53
handle error cases first:
if (error.Error() == DX
Hzj_jie
2016/07/11 00:54:59
Done.
| |
75 } | |
76 } | |
77 } | |
78 | |
79 bool DxgiAdapterDuplicator::Duplicate( | |
80 DesktopFrame* target, const DesktopFrame* last_frame) { | |
Sergey Ulanov
2016/07/08 22:36:53
one argument per line, please
(clang-format should
Hzj_jie
2016/07/11 00:54:59
Done.
| |
81 for (size_t i = 0; i < duplicators_.size(); i++) { | |
Sergey Ulanov
2016/07/08 22:36:53
for (auto& duplicator: duplicators_)...
Hzj_jie
2016/07/11 00:54:59
Oh, I thought for each and auto& are both discoura
Sergey Ulanov
2016/07/20 19:05:17
Nope, see https://chromium-cpp.appspot.com/
auto s
Hzj_jie
2016/07/22 18:43:43
Got it, I have updated both this file and DxgiDupl
| |
82 if (!duplicators_[i].Duplicate(target, last_frame)) { | |
83 return false; | |
84 } | |
85 } | |
86 return true; | |
87 } | |
88 | |
89 bool DxgiAdapterDuplicator::Duplicate( | |
90 int id, DesktopFrame* target, const DesktopFrame* last_frame) { | |
Sergey Ulanov
2016/07/08 22:36:53
one argument per line, please
(clang-format should
Hzj_jie
2016/07/11 00:54:59
Done.
| |
91 if (id < 0 || id >= static_cast<int>(duplicators_.size())) { | |
92 return false; | |
93 } | |
94 return duplicators_[id].Duplicate(target, last_frame, DesktopVector()); | |
95 } | |
96 | |
97 DesktopRect DxgiAdapterDuplicator::ScreenRect(int id) const { | |
98 if (id < 0 || id >= static_cast<int>(duplicators_.size())) { | |
99 return DesktopRect(); | |
100 } | |
101 return duplicators_[id].desktop_rect(); | |
102 } | |
103 | |
104 } // namespace webrtc | |
OLD | NEW |