blob: 8b023bf55c73d2ca5cfab4c29ed26d796f944c0c [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
Zijie He12d34902017-08-02 02:05:177#include <string>
zijiehe3010c8d2016-11-11 01:50:588#include <type_traits>
Zijie He12d34902017-08-02 02:05:179#include <vector>
zijiehe3010c8d2016-11-11 01:50:5810
11#include "base/atomicops.h"
12#include "base/logging.h"
13#include "base/macros.h"
zijiehebe1b0742017-06-28 05:15:0814#include "base/strings/string_piece.h"
15#include "base/strings/string_util.h"
zijiehe3010c8d2016-11-11 01:50:5816#include "build/build_config.h"
17
18#if defined(OS_WIN)
Zijie Heaba78122017-07-17 18:38:5519#include "base/win/windows_version.h"
Zijie Hecaea1e42017-10-11 23:20:3520#include "media/base/win/mf_initializer.h"
21#include "media/gpu/media_foundation_video_encode_accelerator_win.h"
Zijie He12d34902017-08-02 02:05:1722#include "remoting/host/win/evaluate_d3d.h"
zijiehe3010c8d2016-11-11 01:50:5823#endif
24
25namespace remoting {
26
27namespace {
zijiehebe1b0742017-06-28 05:15:0828
zijiehe3010c8d2016-11-11 01:50:5829static constexpr char kSeparator[] = ",";
30
31struct Attribute {
32 const char* name;
33 bool(* get_value_func)();
34};
35
36inline constexpr bool IsDebug() {
37#if defined(NDEBUG)
38 return false;
39#else
40 return true;
41#endif
42}
43
zijiehefe24f002017-02-16 00:42:1444inline constexpr bool IsChromeBranded() {
45#if defined(GOOGLE_CHROME_BUILD)
46 return true;
47#elif defined(CHROMIUM_BUILD)
48 return false;
49#else
50 #error Only Chrome and Chromium brands are supported.
51#endif
52}
53
54inline constexpr bool IsChromiumBranded() {
55 return !IsChromeBranded();
56}
57
58inline constexpr bool IsOfficialBuild() {
59#if defined(OFFICIAL_BUILD)
60 return true;
61#else
62 return false;
63#endif
64}
65
66inline constexpr bool IsNonOfficialBuild() {
67 return !IsOfficialBuild();
68}
69
zijiehe3010c8d2016-11-11 01:50:5870// By using arraysize() macro in base/macros.h, it's illegal to have empty
71// arrays.
72//
73// error: no matching function for call to 'ArraySizeHelper'
74// note: candidate template ignored: substitution failure
75// [with T = const remoting::StaticAttribute, N = 0]:
76// zero-length arrays are not permitted in C++.
77//
78// So we need IsDebug() function, and "Debug-Build" Attribute.
79
80static constexpr Attribute kAttributes[] = {
81 { "Debug-Build", &IsDebug },
zijiehefe24f002017-02-16 00:42:1482 { "ChromeBrand", &IsChromeBranded },
83 { "ChromiumBrand", &IsChromiumBranded },
84 { "OfficialBuild", &IsOfficialBuild },
85 { "NonOfficialBuild", &IsNonOfficialBuild },
zijiehe3010c8d2016-11-11 01:50:5886};
87
88} // namespace
89
90static_assert(std::is_pod<Attribute>::value, "Attribute should be POD.");
91
92std::string GetHostAttributes() {
Zijie He12d34902017-08-02 02:05:1793 std::vector<std::string> result;
zijiehe3010c8d2016-11-11 01:50:5894 // By using ranged for-loop, MSVC throws error C3316:
95 // 'const remoting::StaticAttribute [0]':
96 // an array of unknown size cannot be used in a range-based for statement.
97 for (size_t i = 0; i < arraysize(kAttributes); i++) {
98 const auto& attribute = kAttributes[i];
99 DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos);
100 if (attribute.get_value_func()) {
zijiehebe1b0742017-06-28 05:15:08101 result.push_back(attribute.name);
zijiehe3010c8d2016-11-11 01:50:58102 }
103 }
zijiehebe1b0742017-06-28 05:15:08104#if defined(OS_WIN)
105 {
Zijie He12d34902017-08-02 02:05:17106 GetD3DCapability(&result);
zijiehe3010c8d2016-11-11 01:50:58107
zijiehebe1b0742017-06-28 05:15:08108 auto version = base::win::GetVersion();
109 if (version >= base::win::VERSION_WIN8) {
110 result.push_back("Win8+");
111 }
112 if (version >= base::win::VERSION_WIN8_1) {
113 result.push_back("Win81+");
114 }
115 if (version >= base::win::VERSION_WIN10) {
116 result.push_back("Win10+");
117 }
118 }
Zijie Hecaea1e42017-10-11 23:20:35119
Zijie He282709e2017-10-17 22:11:39120 if (media::MediaFoundationVideoEncodeAccelerator
121 ::PreSandboxInitialization() &&
122 media::InitializeMediaFoundation()) {
Zijie Hecaea1e42017-10-11 23:20:35123 result.push_back("HWEncoder");
124 }
125#elif defined(OS_LINUX)
126 result.push_back("HWEncoder");
zijiehebe1b0742017-06-28 05:15:08127#endif
128
129 return base::JoinString(result, kSeparator);
zijiehe3010c8d2016-11-11 01:50:58130}
131
132} // namespace remoting