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

Side by Side Diff: remoting/host/host_attributes.cc

Issue 2941623003: [Chromoting] Use latest API to check whether DX capturer is supported (Closed)
Patch Set: Resolve review comments Created 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/host_attributes.h" 5 #include "remoting/host/host_attributes.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <D3DCommon.h> 8 #include <D3DCommon.h>
9 #endif 9 #endif
10 10
11 #include <type_traits> 11 #include <type_traits>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/win/windows_version.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 18
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 #include "third_party/webrtc/modules/desktop_capture/win/dxgi_duplicator_control ler.h" 20 #include "third_party/webrtc/modules/desktop_capture/win/dxgi_duplicator_control ler.h"
20 #include "third_party/webrtc/modules/desktop_capture/win/screen_capturer_win_dir ectx.h" 21 #include "third_party/webrtc/modules/desktop_capture/win/screen_capturer_win_dir ectx.h"
21 #endif 22 #endif
22 23
23 namespace remoting { 24 namespace remoting {
24 25
25 namespace { 26 namespace {
27
26 static constexpr char kSeparator[] = ","; 28 static constexpr char kSeparator[] = ",";
27 29
28 struct Attribute { 30 struct Attribute {
29 const char* name; 31 const char* name;
30 bool(* get_value_func)(); 32 bool(* get_value_func)();
31 }; 33 };
32 34
35 void AppendAttribute(std::string* result, const char* attribute) {
Do not use (sergeyu) 2017/06/27 05:54:44 It would be cleaner to collect all attributes into
Hzj_jie 2017/06/27 23:03:06 Done.
36 DCHECK_EQ(std::string(attribute).find(kSeparator), std::string::npos);
37 if (!result->empty()) {
38 result->append(kSeparator);
39 }
40 result->append(attribute);
41 }
42
33 inline constexpr bool IsDebug() { 43 inline constexpr bool IsDebug() {
34 #if defined(NDEBUG) 44 #if defined(NDEBUG)
35 return false; 45 return false;
36 #else 46 #else
37 return true; 47 return true;
38 #endif 48 #endif
39 } 49 }
40 50
41 inline constexpr bool IsChromeBranded() { 51 inline constexpr bool IsChromeBranded() {
42 #if defined(GOOGLE_CHROME_BUILD) 52 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 15 matching lines...) Expand all
58 #else 68 #else
59 return false; 69 return false;
60 #endif 70 #endif
61 } 71 }
62 72
63 inline constexpr bool IsNonOfficialBuild() { 73 inline constexpr bool IsNonOfficialBuild() {
64 return !IsOfficialBuild(); 74 return !IsOfficialBuild();
65 } 75 }
66 76
67 #if defined(OS_WIN) 77 #if defined(OS_WIN)
68 inline bool MinD3DFeatureLevelGreatThan10() { 78 // TODO(zijiehe): Use ScreenCapturerWinDirectx::IsSessionUnsupported().
69 webrtc::DxgiDuplicatorController::D3dInfo info; 79 bool IsRunningInSession0() {
70 if (webrtc::DxgiDuplicatorController::Instance()->RetrieveD3dInfo(&info)) { 80 DWORD session_id = 0;
71 return info.min_feature_level >= D3D_FEATURE_LEVEL_10_0; 81 if (!::ProcessIdToSessionId(::GetCurrentProcessId(), &session_id)) {
82 LOG(WARNING) << "Failed to retrieve current session id.";
joedow 2017/06/27 15:44:58 If you use PLOG here, the platform error code will
Hzj_jie 2017/06/27 23:03:06 Done.
83 // Assume the binary is running in session 0 if the session id cannot be
84 // retrieved, so IsDirectxCapturerSupported() will fallback to use Windows
85 // version.
86 return true;
72 } 87 }
73 return false; 88 return session_id == 0;
74 } 89 }
75 90
76 inline bool MinD3DFeatureLevelGreatThan11() { 91 bool IsDirectxCapturerSupported() {
77 webrtc::DxgiDuplicatorController::D3dInfo info; 92 if (webrtc::ScreenCapturerWinDirectx::IsSupported()) {
Do not use (sergeyu) 2017/06/27 05:54:44 Is there anything that we get by calling ScreenCap
Hzj_jie 2017/06/27 23:03:06 I believe this used to work well before some upgra
78 if (webrtc::DxgiDuplicatorController::Instance()->RetrieveD3dInfo(&info)) { 93 return true;
79 return info.min_feature_level >= D3D_FEATURE_LEVEL_11_0;
80 } 94 }
81 return false;
82 }
83 95
84 inline bool MinD3DFeatureLevelGreatThan12() { 96 if (IsRunningInSession0()) {
85 webrtc::DxgiDuplicatorController::D3dInfo info; 97 LOG(WARNING) << "Current binary is running in session 0. DXGI components "
86 if (webrtc::DxgiDuplicatorController::Instance()->RetrieveD3dInfo(&info)) { 98 "cannot be initialized. Fallback to use Windows version to "
87 return info.min_feature_level >= D3D_FEATURE_LEVEL_12_0; 99 "decide the support of DirectX capturer. It may be "
100 "inaccurate.";
joedow 2017/06/27 15:44:58 IIUC this method is going to be called in session
Hzj_jie 2017/06/27 23:03:06 Done.
101 return base::win::GetVersion() >= base::win::VERSION_WIN8;
88 } 102 }
103
89 return false; 104 return false;
90 } 105 }
91 #endif 106 #endif
92 107
93 // By using arraysize() macro in base/macros.h, it's illegal to have empty 108 // By using arraysize() macro in base/macros.h, it's illegal to have empty
94 // arrays. 109 // arrays.
95 // 110 //
96 // error: no matching function for call to 'ArraySizeHelper' 111 // error: no matching function for call to 'ArraySizeHelper'
97 // note: candidate template ignored: substitution failure 112 // note: candidate template ignored: substitution failure
98 // [with T = const remoting::StaticAttribute, N = 0]: 113 // [with T = const remoting::StaticAttribute, N = 0]:
99 // zero-length arrays are not permitted in C++. 114 // zero-length arrays are not permitted in C++.
100 // 115 //
101 // So we need IsDebug() function, and "Debug-Build" Attribute. 116 // So we need IsDebug() function, and "Debug-Build" Attribute.
102 117
103 static constexpr Attribute kAttributes[] = { 118 static constexpr Attribute kAttributes[] = {
104 { "Debug-Build", &IsDebug }, 119 { "Debug-Build", &IsDebug },
105 { "ChromeBrand", &IsChromeBranded }, 120 { "ChromeBrand", &IsChromeBranded },
106 { "ChromiumBrand", &IsChromiumBranded }, 121 { "ChromiumBrand", &IsChromiumBranded },
107 { "OfficialBuild", &IsOfficialBuild }, 122 { "OfficialBuild", &IsOfficialBuild },
108 { "NonOfficialBuild", &IsNonOfficialBuild }, 123 { "NonOfficialBuild", &IsNonOfficialBuild },
109 #if defined(OS_WIN) 124 #if defined(OS_WIN)
110 { "DirectX-Capturer", &webrtc::ScreenCapturerWinDirectx::IsSupported }, 125 { "DirectX-Capturer", &IsDirectxCapturerSupported },
111 { "MinD3DGT10", &MinD3DFeatureLevelGreatThan10 },
112 { "MinD3DGT11", &MinD3DFeatureLevelGreatThan11 },
113 { "MinD3DGT12", &MinD3DFeatureLevelGreatThan12 },
114 #endif 126 #endif
115 }; 127 };
116 128
117 } // namespace 129 } // namespace
118 130
119 static_assert(std::is_pod<Attribute>::value, "Attribute should be POD."); 131 static_assert(std::is_pod<Attribute>::value, "Attribute should be POD.");
120 132
121 std::string GetHostAttributes() { 133 std::string GetHostAttributes() {
134 #if defined(OS_WIN)
135 // Ensure the following ScreenCapturerWinDirectx contructions won't
Do not use (sergeyu) 2017/06/27 05:54:44 This is still confusing. Remove IsDirectxCapturerS
Hzj_jie 2017/06/27 23:03:06 In that case, I would prefer to return Windows ver
136 // initialize and unload DxgiDuplicatorController.
137 auto controller = webrtc::DxgiDuplicatorController::Instance();
138 #endif
122 std::string result; 139 std::string result;
123 // By using ranged for-loop, MSVC throws error C3316: 140 // By using ranged for-loop, MSVC throws error C3316:
124 // 'const remoting::StaticAttribute [0]': 141 // 'const remoting::StaticAttribute [0]':
125 // an array of unknown size cannot be used in a range-based for statement. 142 // an array of unknown size cannot be used in a range-based for statement.
126 for (size_t i = 0; i < arraysize(kAttributes); i++) { 143 for (size_t i = 0; i < arraysize(kAttributes); i++) {
127 const auto& attribute = kAttributes[i]; 144 const auto& attribute = kAttributes[i];
128 DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos); 145 DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos);
129 if (attribute.get_value_func()) { 146 if (attribute.get_value_func()) {
130 if (!result.empty()) { 147 AppendAttribute(&result, attribute.name);
131 result.append(kSeparator);
132 }
133 result.append(attribute.name);
134 } 148 }
135 } 149 }
150 #if defined(OS_WIN)
151 {
152 webrtc::DxgiDuplicatorController::D3dInfo info;
153 webrtc::ScreenCapturerWinDirectx::RetrieveD3dInfo(&info);
154 if (info.min_feature_level >= D3D_FEATURE_LEVEL_10_0) {
155 AppendAttribute(&result, "MinD3DGT10");
156 }
157 if (info.min_feature_level >= D3D_FEATURE_LEVEL_11_0) {
158 AppendAttribute(&result, "MinD3DGT11");
159 }
160 if (info.min_feature_level >= D3D_FEATURE_LEVEL_12_0) {
161 AppendAttribute(&result, "MinD3DGT12");
162 }
163 }
164 // Avoid the warning of unused variable.
165 controller = nullptr;
166 #endif
136 167
137 return result; 168 return result;
138 } 169 }
139 170
140 } // namespace remoting 171 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698