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 | |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 7 | #if defined(OS_WIN) |
| 8 | #include <D3DCommon.h> |
| 9 | #endif |
| 10 | |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 11 | #include <type_traits> |
| 12 | |
| 13 | #include "base/atomicops.h" |
| 14 | #include "base/logging.h" |
| 15 | #include "base/macros.h" |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame^] | 16 | #include "base/strings/string_piece.h" |
| 17 | #include "base/strings/string_util.h" |
| 18 | #include "base/win/windows_version.h" |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 19 | #include "build/build_config.h" |
| 20 | |
| 21 | #if defined(OS_WIN) |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 22 | #include "third_party/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h" |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 23 | #include "third_party/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h" |
| 24 | #endif |
| 25 | |
| 26 | namespace remoting { |
| 27 | |
| 28 | namespace { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame^] | 29 | |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 30 | static constexpr char kSeparator[] = ","; |
| 31 | |
| 32 | struct Attribute { |
| 33 | const char* name; |
| 34 | bool(* get_value_func)(); |
| 35 | }; |
| 36 | |
| 37 | inline constexpr bool IsDebug() { |
| 38 | #if defined(NDEBUG) |
| 39 | return false; |
| 40 | #else |
| 41 | return true; |
| 42 | #endif |
| 43 | } |
| 44 | |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 45 | inline 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 | |
| 55 | inline constexpr bool IsChromiumBranded() { |
| 56 | return !IsChromeBranded(); |
| 57 | } |
| 58 | |
| 59 | inline constexpr bool IsOfficialBuild() { |
| 60 | #if defined(OFFICIAL_BUILD) |
| 61 | return true; |
| 62 | #else |
| 63 | return false; |
| 64 | #endif |
| 65 | } |
| 66 | |
| 67 | inline constexpr bool IsNonOfficialBuild() { |
| 68 | return !IsOfficialBuild(); |
| 69 | } |
| 70 | |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 71 | // 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 | |
| 81 | static constexpr Attribute kAttributes[] = { |
| 82 | { "Debug-Build", &IsDebug }, |
zijiehe | fe24f00 | 2017-02-16 00:42:14 | [diff] [blame] | 83 | { "ChromeBrand", &IsChromeBranded }, |
| 84 | { "ChromiumBrand", &IsChromiumBranded }, |
| 85 | { "OfficialBuild", &IsOfficialBuild }, |
| 86 | { "NonOfficialBuild", &IsNonOfficialBuild }, |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace |
| 90 | |
| 91 | static_assert(std::is_pod<Attribute>::value, "Attribute should be POD."); |
| 92 | |
| 93 | std::string GetHostAttributes() { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame^] | 94 | std::vector<base::StringPiece> result; |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 95 | // 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()) { |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame^] | 102 | result.push_back(attribute.name); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 103 | } |
| 104 | } |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame^] | 105 | #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 | } |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 118 | |
zijiehe | be1b074 | 2017-06-28 05:15:08 | [diff] [blame^] | 119 | 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); |
zijiehe | 3010c8d | 2016-11-11 01:50:58 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | } // namespace remoting |