2018-09-27 14:59:23 +00: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 20:46:59 +00:00
|
|
|
#include "shell/browser/api/gpu_info_enumerator.h"
|
2018-09-27 14:59:23 +00:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-09-27 14:59:23 +00:00
|
|
|
|
|
|
|
GPUInfoEnumerator::GPUInfoEnumerator()
|
|
|
|
: value_stack(), current(std::make_unique<base::DictionaryValue>()) {}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
GPUInfoEnumerator::~GPUInfoEnumerator() = default;
|
2018-09-27 14:59:23 +00:00
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddInt64(const char* name, int64_t value) {
|
|
|
|
current->SetInteger(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddInt(const char* name, int value) {
|
|
|
|
current->SetInteger(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddString(const char* name, const std::string& value) {
|
|
|
|
if (!value.empty())
|
|
|
|
current->SetString(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddBool(const char* name, bool value) {
|
|
|
|
current->SetBoolean(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::AddTimeDeltaInSecondsF(const char* name,
|
|
|
|
const base::TimeDelta& value) {
|
|
|
|
current->SetInteger(name, value.InMilliseconds());
|
|
|
|
}
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
void GPUInfoEnumerator::AddBinary(const char* name,
|
|
|
|
const base::span<const uint8_t>& value) {
|
|
|
|
current->Set(name, std::make_unique<base::Value>(value));
|
|
|
|
}
|
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
void GPUInfoEnumerator::BeginGPUDevice() {
|
|
|
|
value_stack.push(std::move(current));
|
|
|
|
current = std::make_unique<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndGPUDevice() {
|
|
|
|
auto& top_value = value_stack.top();
|
|
|
|
// GPUDevice can be more than one. So create a list of all.
|
|
|
|
// The first one is the active GPU device.
|
|
|
|
if (top_value->HasKey(kGPUDeviceKey)) {
|
|
|
|
base::ListValue* list;
|
|
|
|
top_value->GetList(kGPUDeviceKey, &list);
|
|
|
|
list->Append(std::move(current));
|
|
|
|
} else {
|
|
|
|
auto gpus = std::make_unique<base::ListValue>();
|
|
|
|
gpus->Append(std::move(current));
|
|
|
|
top_value->SetList(kGPUDeviceKey, std::move(gpus));
|
|
|
|
}
|
|
|
|
current = std::move(top_value);
|
|
|
|
value_stack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::BeginVideoDecodeAcceleratorSupportedProfile() {
|
|
|
|
value_stack.push(std::move(current));
|
|
|
|
current = std::make_unique<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndVideoDecodeAcceleratorSupportedProfile() {
|
|
|
|
auto& top_value = value_stack.top();
|
2022-02-10 02:58:52 +00:00
|
|
|
top_value->SetKey(kVideoDecodeAcceleratorSupportedProfileKey,
|
|
|
|
base::Value::FromUniquePtrValue(std::move(current)));
|
2018-09-27 14:59:23 +00:00
|
|
|
current = std::move(top_value);
|
|
|
|
value_stack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::BeginVideoEncodeAcceleratorSupportedProfile() {
|
|
|
|
value_stack.push(std::move(current));
|
|
|
|
current = std::make_unique<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndVideoEncodeAcceleratorSupportedProfile() {
|
|
|
|
auto& top_value = value_stack.top();
|
2022-02-10 02:58:52 +00:00
|
|
|
top_value->SetKey(kVideoEncodeAcceleratorSupportedProfileKey,
|
|
|
|
base::Value::FromUniquePtrValue(std::move(current)));
|
2018-09-27 14:59:23 +00:00
|
|
|
current = std::move(top_value);
|
|
|
|
value_stack.pop();
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:34:59 +00:00
|
|
|
void GPUInfoEnumerator::BeginImageDecodeAcceleratorSupportedProfile() {
|
|
|
|
value_stack.push(std::move(current));
|
|
|
|
current = std::make_unique<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndImageDecodeAcceleratorSupportedProfile() {
|
|
|
|
auto& top_value = value_stack.top();
|
2022-02-10 02:58:52 +00:00
|
|
|
top_value->SetKey(kImageDecodeAcceleratorSupportedProfileKey,
|
|
|
|
base::Value::FromUniquePtrValue(std::move(current)));
|
2019-02-21 17:34:59 +00:00
|
|
|
current = std::move(top_value);
|
|
|
|
value_stack.pop();
|
|
|
|
}
|
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
void GPUInfoEnumerator::BeginAuxAttributes() {
|
|
|
|
value_stack.push(std::move(current));
|
|
|
|
current = std::make_unique<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndAuxAttributes() {
|
|
|
|
auto& top_value = value_stack.top();
|
2022-02-10 02:58:52 +00:00
|
|
|
top_value->SetKey(kAuxAttributesKey,
|
|
|
|
base::Value::FromUniquePtrValue(std::move(current)));
|
2018-09-27 14:59:23 +00:00
|
|
|
current = std::move(top_value);
|
|
|
|
value_stack.pop();
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:35:05 +00:00
|
|
|
void GPUInfoEnumerator::BeginOverlayInfo() {
|
|
|
|
value_stack.push(std::move(current));
|
|
|
|
current = std::make_unique<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoEnumerator::EndOverlayInfo() {
|
|
|
|
auto& top_value = value_stack.top();
|
2022-02-10 02:58:52 +00:00
|
|
|
top_value->SetKey(kOverlayInfo,
|
|
|
|
base::Value::FromUniquePtrValue(std::move(current)));
|
2020-03-03 21:35:05 +00:00
|
|
|
current = std::move(top_value);
|
|
|
|
value_stack.pop();
|
|
|
|
}
|
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> GPUInfoEnumerator::GetDictionary() {
|
|
|
|
return std::move(current);
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|