gpu_info_enumerator.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/api/gpu_info_enumerator.h"
  5. #include <utility>
  6. namespace electron {
  7. GPUInfoEnumerator::GPUInfoEnumerator() = default;
  8. GPUInfoEnumerator::~GPUInfoEnumerator() = default;
  9. void GPUInfoEnumerator::AddInt64(const char* name, int64_t value) {
  10. // NOTE(nornagon): this loses precision. base::Value can't store int64_t.
  11. current_.Set(name, static_cast<int>(value));
  12. }
  13. void GPUInfoEnumerator::AddInt(const char* name, int value) {
  14. current_.Set(name, value);
  15. }
  16. void GPUInfoEnumerator::AddString(const char* name, const std::string& value) {
  17. if (!value.empty())
  18. current_.Set(name, value);
  19. }
  20. void GPUInfoEnumerator::AddBool(const char* name, bool value) {
  21. current_.Set(name, value);
  22. }
  23. void GPUInfoEnumerator::AddTimeDeltaInSecondsF(const char* name,
  24. const base::TimeDelta& value) {
  25. current_.Set(name, value.InMillisecondsF());
  26. }
  27. void GPUInfoEnumerator::AddBinary(const char* name,
  28. const base::span<const uint8_t>& value) {
  29. current_.Set(name, base::Value(value));
  30. }
  31. void GPUInfoEnumerator::BeginGPUDevice() {
  32. value_stack_.push(std::move(current_));
  33. current_ = {};
  34. }
  35. void GPUInfoEnumerator::EndGPUDevice() {
  36. auto& top_value = value_stack_.top();
  37. // GPUDevice can be more than one. So create a list of all.
  38. // The first one is the active GPU device.
  39. if (base::Value* list_value = top_value.Find(kGPUDeviceKey)) {
  40. DCHECK(list_value->is_list());
  41. base::Value::List& list = list_value->GetList();
  42. list.Append(std::move(current_));
  43. } else {
  44. base::Value::List gpus;
  45. gpus.Append(std::move(current_));
  46. top_value.Set(kGPUDeviceKey, std::move(gpus));
  47. }
  48. current_ = std::move(top_value);
  49. value_stack_.pop();
  50. }
  51. void GPUInfoEnumerator::BeginVideoDecodeAcceleratorSupportedProfile() {
  52. value_stack_.push(std::move(current_));
  53. current_ = {};
  54. }
  55. void GPUInfoEnumerator::EndVideoDecodeAcceleratorSupportedProfile() {
  56. auto& top_value = value_stack_.top();
  57. top_value.Set(kVideoDecodeAcceleratorSupportedProfileKey,
  58. std::move(current_));
  59. current_ = std::move(top_value);
  60. value_stack_.pop();
  61. }
  62. void GPUInfoEnumerator::BeginVideoEncodeAcceleratorSupportedProfile() {
  63. value_stack_.push(std::move(current_));
  64. current_ = {};
  65. }
  66. void GPUInfoEnumerator::EndVideoEncodeAcceleratorSupportedProfile() {
  67. auto& top_value = value_stack_.top();
  68. top_value.Set(kVideoEncodeAcceleratorSupportedProfileKey,
  69. std::move(current_));
  70. current_ = std::move(top_value);
  71. value_stack_.pop();
  72. }
  73. void GPUInfoEnumerator::BeginImageDecodeAcceleratorSupportedProfile() {
  74. value_stack_.push(std::move(current_));
  75. current_ = {};
  76. }
  77. void GPUInfoEnumerator::EndImageDecodeAcceleratorSupportedProfile() {
  78. auto& top_value = value_stack_.top();
  79. top_value.Set(kImageDecodeAcceleratorSupportedProfileKey,
  80. std::move(current_));
  81. current_ = std::move(top_value);
  82. value_stack_.pop();
  83. }
  84. void GPUInfoEnumerator::BeginAuxAttributes() {
  85. value_stack_.push(std::move(current_));
  86. current_ = {};
  87. }
  88. void GPUInfoEnumerator::EndAuxAttributes() {
  89. auto& top_value = value_stack_.top();
  90. top_value.Set(kAuxAttributesKey, std::move(current_));
  91. current_ = std::move(top_value);
  92. value_stack_.pop();
  93. }
  94. void GPUInfoEnumerator::BeginOverlayInfo() {
  95. value_stack_.push(std::move(current_));
  96. current_ = {};
  97. }
  98. void GPUInfoEnumerator::EndOverlayInfo() {
  99. auto& top_value = value_stack_.top();
  100. top_value.Set(kOverlayInfo, std::move(current_));
  101. current_ = std::move(top_value);
  102. value_stack_.pop();
  103. }
  104. base::Value::Dict GPUInfoEnumerator::GetDictionary() {
  105. return std::move(current_);
  106. }
  107. } // namespace electron