2018-09-27 17:59:23 +03:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 23:46:59 +03:00
|
|
|
#include "shell/browser/api/gpu_info_enumerator.h"
|
2018-09-27 17:59:23 +03:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2022-06-28 19:52:59 +03:00
|
|
|
GPUInfoEnumerator::GPUInfoEnumerator() : value_stack_(), current_{} {}
|
2018-09-27 17:59:23 +03:00
|
|
|
|
2019-09-17 01:12:00 +03:00
|
|
|
GPUInfoEnumerator::~GPUInfoEnumerator() = default;
|
2018-09-27 17:59:23 +03:00
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddInt64(const char* name, int64_t value) {
|
2022-06-28 19:52:59 +03:00
|
|
|
// NOTE(nornagon): this loses precision. base::Value can't store int64_t.
|
|
|
|
current_.Set(name, static_cast<int>(value));
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddInt(const char* name, int value) {
|
2022-06-28 19:52:59 +03:00
|
|
|
current_.Set(name, value);
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddString(const char* name, const std::string& value) {
|
|
|
|
if (!value.empty())
|
2022-06-28 19:52:59 +03:00
|
|
|
current_.Set(name, value);
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddBool(const char* name, bool value) {
|
2022-06-28 19:52:59 +03:00
|
|
|
current_.Set(name, value);
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddTimeDeltaInSecondsF(const char* name,
|
|
|
|
const base::TimeDelta& value) {
|
2022-06-28 19:52:59 +03:00
|
|
|
current_.Set(name, value.InMillisecondsF());
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
2019-12-11 03:22:35 +03:00
|
|
|
void GPUInfoEnumerator::AddBinary(const char* name,
|
|
|
|
const base::span<const uint8_t>& value) {
|
2022-06-28 19:52:59 +03:00
|
|
|
current_.Set(name, base::Value(value));
|
2019-12-11 03:22:35 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 17:59:23 +03:00
|
|
|
void GPUInfoEnumerator::BeginGPUDevice() {
|
2022-06-28 19:52:59 +03:00
|
|
|
value_stack_.push(std::move(current_));
|
|
|
|
current_ = {};
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndGPUDevice() {
|
2022-06-28 19:52:59 +03:00
|
|
|
auto& top_value = value_stack_.top();
|
2018-09-27 17:59:23 +03:00
|
|
|
// GPUDevice can be more than one. So create a list of all.
|
|
|
|
// The first one is the active GPU device.
|
2022-06-28 19:52:59 +03:00
|
|
|
if (base::Value* list_value = top_value.Find(kGPUDeviceKey)) {
|
|
|
|
DCHECK(list_value->is_list());
|
|
|
|
base::Value::List& list = list_value->GetList();
|
|
|
|
list.Append(std::move(current_));
|
2018-09-27 17:59:23 +03:00
|
|
|
} else {
|
2022-06-28 19:52:59 +03:00
|
|
|
base::Value::List gpus;
|
|
|
|
gpus.Append(std::move(current_));
|
|
|
|
top_value.Set(kGPUDeviceKey, std::move(gpus));
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
2022-06-28 19:52:59 +03:00
|
|
|
current_ = std::move(top_value);
|
|
|
|
value_stack_.pop();
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::BeginVideoDecodeAcceleratorSupportedProfile() {
|
2022-06-28 19:52:59 +03:00
|
|
|
value_stack_.push(std::move(current_));
|
|
|
|
current_ = {};
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndVideoDecodeAcceleratorSupportedProfile() {
|
2022-06-28 19:52:59 +03:00
|
|
|
auto& top_value = value_stack_.top();
|
|
|
|
top_value.Set(kVideoDecodeAcceleratorSupportedProfileKey,
|
|
|
|
std::move(current_));
|
|
|
|
current_ = std::move(top_value);
|
|
|
|
value_stack_.pop();
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::BeginVideoEncodeAcceleratorSupportedProfile() {
|
2022-06-28 19:52:59 +03:00
|
|
|
value_stack_.push(std::move(current_));
|
|
|
|
current_ = {};
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndVideoEncodeAcceleratorSupportedProfile() {
|
2022-06-28 19:52:59 +03:00
|
|
|
auto& top_value = value_stack_.top();
|
|
|
|
top_value.Set(kVideoEncodeAcceleratorSupportedProfileKey,
|
|
|
|
std::move(current_));
|
|
|
|
current_ = std::move(top_value);
|
|
|
|
value_stack_.pop();
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 20:34:59 +03:00
|
|
|
void GPUInfoEnumerator::BeginImageDecodeAcceleratorSupportedProfile() {
|
2022-06-28 19:52:59 +03:00
|
|
|
value_stack_.push(std::move(current_));
|
|
|
|
current_ = {};
|
2019-02-21 20:34:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndImageDecodeAcceleratorSupportedProfile() {
|
2022-06-28 19:52:59 +03:00
|
|
|
auto& top_value = value_stack_.top();
|
|
|
|
top_value.Set(kImageDecodeAcceleratorSupportedProfileKey,
|
|
|
|
std::move(current_));
|
|
|
|
current_ = std::move(top_value);
|
|
|
|
value_stack_.pop();
|
2019-02-21 20:34:59 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 17:59:23 +03:00
|
|
|
void GPUInfoEnumerator::BeginAuxAttributes() {
|
2022-06-28 19:52:59 +03:00
|
|
|
value_stack_.push(std::move(current_));
|
|
|
|
current_ = {};
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndAuxAttributes() {
|
2022-06-28 19:52:59 +03:00
|
|
|
auto& top_value = value_stack_.top();
|
|
|
|
top_value.Set(kAuxAttributesKey, std::move(current_));
|
|
|
|
current_ = std::move(top_value);
|
|
|
|
value_stack_.pop();
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 00:35:05 +03:00
|
|
|
void GPUInfoEnumerator::BeginOverlayInfo() {
|
2022-06-28 19:52:59 +03:00
|
|
|
value_stack_.push(std::move(current_));
|
|
|
|
current_ = {};
|
2020-03-04 00:35:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndOverlayInfo() {
|
2022-06-28 19:52:59 +03:00
|
|
|
auto& top_value = value_stack_.top();
|
|
|
|
top_value.Set(kOverlayInfo, std::move(current_));
|
|
|
|
current_ = std::move(top_value);
|
|
|
|
value_stack_.pop();
|
2020-03-04 00:35:05 +03:00
|
|
|
}
|
|
|
|
|
2022-06-28 19:52:59 +03:00
|
|
|
base::Value::Dict GPUInfoEnumerator::GetDictionary() {
|
|
|
|
return std::move(current_);
|
2018-09-27 17:59:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|