blob: 9bd6cff604242e6f44fead3cd916ca98403f46ff [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"
Hans Wennborg828a0972020-04-27 18:10:0912#include "base/check_op.h"
Lei Zhang71d3a022021-05-27 17:08:4213#include "base/cxx17_backports.h"
zijiehebe1b0742017-06-28 05:15:0814#include "base/strings/string_piece.h"
15#include "base/strings/string_util.h"
Nico Weber897593f2019-07-25 23:17:5516#include "build/branding_buildflags.h"
zijiehe3010c8d2016-11-11 01:50:5817#include "build/build_config.h"
18
19#if defined(OS_WIN)
Zijie Heaba78122017-07-17 18:38:5520#include "base/win/windows_version.h"
Zijie Hecaea1e42017-10-11 23:20:3521#include "media/base/win/mf_initializer.h"
Miguel Casasd697adf32018-02-26 19:06:3122#include "media/gpu/windows/media_foundation_video_encode_accelerator_win.h"
Joe Downing80099d52018-08-21 15:14:4923#include "remoting/host/win/evaluate_3d_display_mode.h"
Zijie He12d34902017-08-02 02:05:1724#include "remoting/host/win/evaluate_d3d.h"
zijiehe3010c8d2016-11-11 01:50:5825#endif
26
27namespace remoting {
28
29namespace {
zijiehebe1b0742017-06-28 05:15:0830
zijiehe3010c8d2016-11-11 01:50:5831static constexpr char kSeparator[] = ",";
32
33struct Attribute {
34 const char* name;
35 bool(* get_value_func)();
36};
37
38inline constexpr bool IsDebug() {
39#if defined(NDEBUG)
40 return false;
41#else
42 return true;
43#endif
44}
45
zijiehefe24f002017-02-16 00:42:1446inline constexpr bool IsChromeBranded() {
Nico Webercda4ff542019-07-29 20:05:2247#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
zijiehefe24f002017-02-16 00:42:1448 return true;
Nico Weber897593f2019-07-25 23:17:5549#elif BUILDFLAG(CHROMIUM_BRANDING)
zijiehefe24f002017-02-16 00:42:1450 return false;
51#else
52 #error Only Chrome and Chromium brands are supported.
53#endif
54}
55
56inline constexpr bool IsChromiumBranded() {
57 return !IsChromeBranded();
58}
59
60inline constexpr bool IsOfficialBuild() {
61#if defined(OFFICIAL_BUILD)
62 return true;
63#else
64 return false;
65#endif
66}
67
68inline constexpr bool IsNonOfficialBuild() {
69 return !IsOfficialBuild();
70}
71
Avi Drissman88f5d8c52018-12-24 22:39:2072// By using base::size() macro in base/macros.h, it's illegal to have empty
zijiehe3010c8d2016-11-11 01:50:5873// arrays.
74//
75// error: no matching function for call to 'ArraySizeHelper'
76// note: candidate template ignored: substitution failure
77// [with T = const remoting::StaticAttribute, N = 0]:
78// zero-length arrays are not permitted in C++.
79//
80// So we need IsDebug() function, and "Debug-Build" Attribute.
81
82static constexpr Attribute kAttributes[] = {
83 { "Debug-Build", &IsDebug },
zijiehefe24f002017-02-16 00:42:1484 { "ChromeBrand", &IsChromeBranded },
85 { "ChromiumBrand", &IsChromiumBranded },
86 { "OfficialBuild", &IsOfficialBuild },
87 { "NonOfficialBuild", &IsNonOfficialBuild },
zijiehe3010c8d2016-11-11 01:50:5888};
89
90} // namespace
91
92static_assert(std::is_pod<Attribute>::value, "Attribute should be POD.");
93
94std::string GetHostAttributes() {
Zijie He12d34902017-08-02 02:05:1795 std::vector<std::string> result;
Nico Weberaa14d3a2020-03-02 15:55:1996 for (const auto& attribute : kAttributes) {
zijiehe3010c8d2016-11-11 01:50:5897 DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos);
98 if (attribute.get_value_func()) {
zijiehebe1b0742017-06-28 05:15:0899 result.push_back(attribute.name);
zijiehe3010c8d2016-11-11 01:50:58100 }
101 }
zijiehebe1b0742017-06-28 05:15:08102#if defined(OS_WIN)
103 {
Joe Downing80099d52018-08-21 15:14:49104 GetD3DCapabilities(&result);
zijiehe3010c8d2016-11-11 01:50:58105
zijiehebe1b0742017-06-28 05:15:08106 auto version = base::win::GetVersion();
Bruce Dawsonaed9bea2019-04-20 02:30:09107 if (version >= base::win::Version::WIN8) {
zijiehebe1b0742017-06-28 05:15:08108 result.push_back("Win8+");
109 }
Bruce Dawsonaed9bea2019-04-20 02:30:09110 if (version >= base::win::Version::WIN8_1) {
zijiehebe1b0742017-06-28 05:15:08111 result.push_back("Win81+");
112 }
Bruce Dawsonaed9bea2019-04-20 02:30:09113 if (version >= base::win::Version::WIN10) {
zijiehebe1b0742017-06-28 05:15:08114 result.push_back("Win10+");
115 }
116 }
Zijie Hecaea1e42017-10-11 23:20:35117
Joey Arhardd270e1d2021-03-12 00:07:29118 // TODO(crbug.com/1184041): Remove this and/or the entire HostAttributes class
119 // so we can remove //remoting/host:common from //media/gpu's visibility list.
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 }
Sean McAllisteracb45d62020-08-19 17:14:40125#elif defined(OS_LINUX) || defined(OS_CHROMEOS)
Zijie Hecaea1e42017-10-11 23:20:35126 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