zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "remoting/host/host_attributes.h" |
| 6 | |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 7 | #include <string> |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 8 | #include <type_traits> |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 9 | #include <vector> |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 10 | |
| 11 | #include "base/atomicops.h" |
Hans Wennborg | 828a097 | 2020-04-27 18:10:09 | [diff] [blame] | 12 | #include "base/check_op.h" |
Lei Zhang | 71d3a02 | 2021-05-27 17:08:42 | [diff] [blame] | 13 | #include "base/cxx17_backports.h" |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 14 | #include "base/strings/string_piece.h" |
| 15 | #include "base/strings/string_util.h" |
Nico Weber | 897593f | 2019-07-25 23:17:55 | [diff] [blame] | 16 | #include "build/branding_buildflags.h" |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 17 | #include "build/build_config.h" |
| 18 | |
| 19 | #if defined(OS_WIN) |
Zijie He | aba7812 | 2017-07-17 18:38:55 | [diff] [blame] | 20 | #include "base/win/windows_version.h" |
Zijie He | caea1e4 | 2017-10-11 23:20:35 | [diff] [blame] | 21 | #include "media/base/win/mf_initializer.h" |
Miguel Casas | d697adf3 | 2018-02-26 19:06:31 | [diff] [blame] | 22 | #include "media/gpu/windows/media_foundation_video_encode_accelerator_win.h" |
Joe Downing | 80099d5 | 2018-08-21 15:14:49 | [diff] [blame] | 23 | #include "remoting/host/win/evaluate_3d_display_mode.h" |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 24 | #include "remoting/host/win/evaluate_d3d.h" |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 25 | #endif |
| 26 | |
| 27 | namespace remoting { |
| 28 | |
| 29 | namespace { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 30 | |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 31 | static constexpr char kSeparator[] = ","; |
| 32 | |
| 33 | struct Attribute { |
| 34 | const char* name; |
| 35 | bool(* get_value_func)(); |
| 36 | }; |
| 37 | |
| 38 | inline constexpr bool IsDebug() { |
| 39 | #if defined(NDEBUG) |
| 40 | return false; |
| 41 | #else |
| 42 | return true; |
| 43 | #endif |
| 44 | } |
| 45 | |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 46 | inline constexpr bool IsChromeBranded() { |
Nico Weber | cda4ff54 | 2019-07-29 20:05:22 | [diff] [blame] | 47 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 48 | return true; |
Nico Weber | 897593f | 2019-07-25 23:17:55 | [diff] [blame] | 49 | #elif BUILDFLAG(CHROMIUM_BRANDING) |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 50 | return false; |
| 51 | #else |
| 52 | #error Only Chrome and Chromium brands are supported. |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | inline constexpr bool IsChromiumBranded() { |
| 57 | return !IsChromeBranded(); |
| 58 | } |
| 59 | |
| 60 | inline constexpr bool IsOfficialBuild() { |
| 61 | #if defined(OFFICIAL_BUILD) |
| 62 | return true; |
| 63 | #else |
| 64 | return false; |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | inline constexpr bool IsNonOfficialBuild() { |
| 69 | return !IsOfficialBuild(); |
| 70 | } |
| 71 | |
Avi Drissman | 88f5d8c5 | 2018-12-24 22:39:20 | [diff] [blame] | 72 | // By using base::size() macro in base/macros.h, it's illegal to have empty |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 73 | // 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 | |
| 82 | static constexpr Attribute kAttributes[] = { |
| 83 | { "Debug-Build", &IsDebug }, |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 84 | { "ChromeBrand", &IsChromeBranded }, |
| 85 | { "ChromiumBrand", &IsChromiumBranded }, |
| 86 | { "OfficialBuild", &IsOfficialBuild }, |
| 87 | { "NonOfficialBuild", &IsNonOfficialBuild }, |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace |
| 91 | |
| 92 | static_assert(std::is_pod<Attribute>::value, "Attribute should be POD."); |
| 93 | |
| 94 | std::string GetHostAttributes() { |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 95 | std::vector<std::string> result; |
Nico Weber | aa14d3a | 2020-03-02 15:55:19 | [diff] [blame] | 96 | for (const auto& attribute : kAttributes) { |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 97 | DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos); |
| 98 | if (attribute.get_value_func()) { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 99 | result.push_back(attribute.name); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 100 | } |
| 101 | } |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 102 | #if defined(OS_WIN) |
| 103 | { |
Joe Downing | 80099d5 | 2018-08-21 15:14:49 | [diff] [blame] | 104 | GetD3DCapabilities(&result); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 105 | |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 106 | auto version = base::win::GetVersion(); |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 107 | if (version >= base::win::Version::WIN8) { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 108 | result.push_back("Win8+"); |
| 109 | } |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 110 | if (version >= base::win::Version::WIN8_1) { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 111 | result.push_back("Win81+"); |
| 112 | } |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 113 | if (version >= base::win::Version::WIN10) { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 114 | result.push_back("Win10+"); |
| 115 | } |
| 116 | } |
Zijie He | caea1e4 | 2017-10-11 23:20:35 | [diff] [blame] | 117 | |
Joey Arhar | dd270e1d | 2021-03-12 00:07:29 | [diff] [blame] | 118 | // 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 He | 282709e | 2017-10-17 22:11:39 | [diff] [blame] | 120 | if (media::MediaFoundationVideoEncodeAccelerator |
| 121 | ::PreSandboxInitialization() && |
| 122 | media::InitializeMediaFoundation()) { |
Zijie He | caea1e4 | 2017-10-11 23:20:35 | [diff] [blame] | 123 | result.push_back("HWEncoder"); |
| 124 | } |
Sean McAllister | acb45d6 | 2020-08-19 17:14:40 | [diff] [blame] | 125 | #elif defined(OS_LINUX) || defined(OS_CHROMEOS) |
Zijie He | caea1e4 | 2017-10-11 23:20:35 | [diff] [blame] | 126 | result.push_back("HWEncoder"); |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 127 | #endif |
| 128 | |
| 129 | return base::JoinString(result, kSeparator); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | } // namespace remoting |