blob: 9b4cd76aa9d0dc045a5ed380787871659f043d7b [file] [log] [blame]
zijiehe3010c8d2016-11-11 01:50:581// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/host/host_attributes.h"
6
zijiehefe24f002017-02-16 00:42:147#if defined(OS_WIN)
8#include <D3DCommon.h>
9#endif
10
zijiehe3010c8d2016-11-11 01:50:5811#include <type_traits>
12
13#include "base/atomicops.h"
14#include "base/logging.h"
15#include "base/macros.h"
zijiehebe1b0742017-06-28 05:15:0816#include "base/strings/string_piece.h"
17#include "base/strings/string_util.h"
18#include "base/win/windows_version.h"
zijiehe3010c8d2016-11-11 01:50:5819#include "build/build_config.h"
20
21#if defined(OS_WIN)
zijiehefe24f002017-02-16 00:42:1422#include "third_party/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h"
zijiehe3010c8d2016-11-11 01:50:5823#include "third_party/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h"
24#endif
25
26namespace remoting {
27
28namespace {
zijiehebe1b0742017-06-28 05:15:0829
zijiehe3010c8d2016-11-11 01:50:5830static constexpr char kSeparator[] = ",";
31
32struct Attribute {
33 const char* name;
34 bool(* get_value_func)();
35};
36
37inline constexpr bool IsDebug() {
38#if defined(NDEBUG)
39 return false;
40#else
41 return true;
42#endif
43}
44
zijiehefe24f002017-02-16 00:42:1445inline constexpr bool IsChromeBranded() {
46#if defined(GOOGLE_CHROME_BUILD)
47 return true;
48#elif defined(CHROMIUM_BUILD)
49 return false;
50#else
51 #error Only Chrome and Chromium brands are supported.
52#endif
53}
54
55inline constexpr bool IsChromiumBranded() {
56 return !IsChromeBranded();
57}
58
59inline constexpr bool IsOfficialBuild() {
60#if defined(OFFICIAL_BUILD)
61 return true;
62#else
63 return false;
64#endif
65}
66
67inline constexpr bool IsNonOfficialBuild() {
68 return !IsOfficialBuild();
69}
70
zijiehe3010c8d2016-11-11 01:50:5871// By using arraysize() macro in base/macros.h, it's illegal to have empty
72// arrays.
73//
74// error: no matching function for call to 'ArraySizeHelper'
75// note: candidate template ignored: substitution failure
76// [with T = const remoting::StaticAttribute, N = 0]:
77// zero-length arrays are not permitted in C++.
78//
79// So we need IsDebug() function, and "Debug-Build" Attribute.
80
81static constexpr Attribute kAttributes[] = {
82 { "Debug-Build", &IsDebug },
zijiehefe24f002017-02-16 00:42:1483 { "ChromeBrand", &IsChromeBranded },
84 { "ChromiumBrand", &IsChromiumBranded },
85 { "OfficialBuild", &IsOfficialBuild },
86 { "NonOfficialBuild", &IsNonOfficialBuild },
zijiehe3010c8d2016-11-11 01:50:5887};
88
89} // namespace
90
91static_assert(std::is_pod<Attribute>::value, "Attribute should be POD.");
92
93std::string GetHostAttributes() {
zijiehebe1b0742017-06-28 05:15:0894 std::vector<base::StringPiece> result;
zijiehe3010c8d2016-11-11 01:50:5895 // By using ranged for-loop, MSVC throws error C3316:
96 // 'const remoting::StaticAttribute [0]':
97 // an array of unknown size cannot be used in a range-based for statement.
98 for (size_t i = 0; i < arraysize(kAttributes); i++) {
99 const auto& attribute = kAttributes[i];
100 DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos);
101 if (attribute.get_value_func()) {
zijiehebe1b0742017-06-28 05:15:08102 result.push_back(attribute.name);
zijiehe3010c8d2016-11-11 01:50:58103 }
104 }
zijiehebe1b0742017-06-28 05:15:08105#if defined(OS_WIN)
106 {
107 webrtc::DxgiDuplicatorController::D3dInfo info;
108 webrtc::ScreenCapturerWinDirectx::RetrieveD3dInfo(&info);
109 if (info.min_feature_level >= D3D_FEATURE_LEVEL_10_0) {
110 result.push_back("MinD3DGT10");
111 }
112 if (info.min_feature_level >= D3D_FEATURE_LEVEL_11_0) {
113 result.push_back("MinD3DGT11");
114 }
115 if (info.min_feature_level >= D3D_FEATURE_LEVEL_12_0) {
116 result.push_back("MinD3DGT12");
117 }
zijiehe3010c8d2016-11-11 01:50:58118
zijiehebe1b0742017-06-28 05:15:08119 auto version = base::win::GetVersion();
120 if (version >= base::win::VERSION_WIN8) {
121 result.push_back("Win8+");
122 }
123 if (version >= base::win::VERSION_WIN8_1) {
124 result.push_back("Win81+");
125 }
126 if (version >= base::win::VERSION_WIN10) {
127 result.push_back("Win10+");
128 }
129 }
130#endif
131
132 return base::JoinString(result, kSeparator);
zijiehe3010c8d2016-11-11 01:50:58133}
134
135} // namespace remoting