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" |
| 12 | #include "base/logging.h" |
| 13 | #include "base/macros.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" |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 16 | #include "build/build_config.h" |
| 17 | |
| 18 | #if defined(OS_WIN) |
Zijie He | aba7812 | 2017-07-17 18:38:55 | [diff] [blame] | 19 | #include "base/win/windows_version.h" |
Zijie He | caea1e4 | 2017-10-11 23:20:35 | [diff] [blame] | 20 | #include "media/base/win/mf_initializer.h" |
| 21 | #include "media/gpu/media_foundation_video_encode_accelerator_win.h" |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 22 | #include "remoting/host/win/evaluate_d3d.h" |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | namespace remoting { |
| 26 | |
| 27 | namespace { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 28 | |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 29 | static constexpr char kSeparator[] = ","; |
| 30 | |
| 31 | struct Attribute { |
| 32 | const char* name; |
| 33 | bool(* get_value_func)(); |
| 34 | }; |
| 35 | |
| 36 | inline constexpr bool IsDebug() { |
| 37 | #if defined(NDEBUG) |
| 38 | return false; |
| 39 | #else |
| 40 | return true; |
| 41 | #endif |
| 42 | } |
| 43 | |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 44 | inline 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 | |
| 54 | inline constexpr bool IsChromiumBranded() { |
| 55 | return !IsChromeBranded(); |
| 56 | } |
| 57 | |
| 58 | inline constexpr bool IsOfficialBuild() { |
| 59 | #if defined(OFFICIAL_BUILD) |
| 60 | return true; |
| 61 | #else |
| 62 | return false; |
| 63 | #endif |
| 64 | } |
| 65 | |
| 66 | inline constexpr bool IsNonOfficialBuild() { |
| 67 | return !IsOfficialBuild(); |
| 68 | } |
| 69 | |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 70 | // 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 | |
| 80 | static constexpr Attribute kAttributes[] = { |
| 81 | { "Debug-Build", &IsDebug }, |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 82 | { "ChromeBrand", &IsChromeBranded }, |
| 83 | { "ChromiumBrand", &IsChromiumBranded }, |
| 84 | { "OfficialBuild", &IsOfficialBuild }, |
| 85 | { "NonOfficialBuild", &IsNonOfficialBuild }, |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // namespace |
| 89 | |
| 90 | static_assert(std::is_pod<Attribute>::value, "Attribute should be POD."); |
| 91 | |
| 92 | std::string GetHostAttributes() { |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 93 | std::vector<std::string> result; |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 94 | // 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()) { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 101 | result.push_back(attribute.name); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 102 | } |
| 103 | } |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 104 | #if defined(OS_WIN) |
| 105 | { |
Zijie He | 12d3490 | 2017-08-02 02:05:17 | [diff] [blame] | 106 | GetD3DCapability(&result); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 107 | |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame] | 108 | 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 He | caea1e4 | 2017-10-11 23:20:35 | [diff] [blame] | 119 | |
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 | } |
| 125 | #elif defined(OS_LINUX) |
| 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 |