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/gpuinfo_manager.h"
|
2019-02-21 12:32:44 +00:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
#include "base/memory/singleton.h"
|
2023-02-03 11:43:42 +00:00
|
|
|
#include "base/task/single_thread_task_runner.h"
|
2018-09-27 14:59:23 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "gpu/config/gpu_info_collector.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/gpu_info_enumerator.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2018-09-27 14:59:23 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
GPUInfoManager* GPUInfoManager::GetInstance() {
|
|
|
|
return base::Singleton<GPUInfoManager>::get();
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUInfoManager::GPUInfoManager()
|
|
|
|
: gpu_data_manager_(content::GpuDataManagerImpl::GetInstance()) {
|
|
|
|
gpu_data_manager_->AddObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUInfoManager::~GPUInfoManager() {
|
|
|
|
content::GpuDataManagerImpl::GetInstance()->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Based on
|
2018-10-09 17:37:52 +00:00
|
|
|
// https://chromium.googlesource.com/chromium/src.git/+/69.0.3497.106/content/browser/gpu/gpu_data_manager_impl_private.cc#838
|
2018-10-15 15:26:47 +00:00
|
|
|
bool GPUInfoManager::NeedsCompleteGpuInfoCollection() const {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-03-03 21:35:05 +00:00
|
|
|
return gpu_data_manager_->DxdiagDx12VulkanRequested() &&
|
|
|
|
gpu_data_manager_->GetGPUInfo().dx_diagnostics.IsEmpty();
|
2018-09-27 14:59:23 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should be posted to the task runner
|
|
|
|
void GPUInfoManager::ProcessCompleteInfo() {
|
2022-06-28 16:52:59 +00:00
|
|
|
base::Value::Dict result = EnumerateGPUInfo(gpu_data_manager_->GetGPUInfo());
|
2018-09-27 14:59:23 +00:00
|
|
|
// We have received the complete information, resolve all promises that
|
|
|
|
// were waiting for this info.
|
2019-02-21 12:32:44 +00:00
|
|
|
for (auto& promise : complete_info_promise_set_) {
|
2022-06-28 16:52:59 +00:00
|
|
|
promise.Resolve(base::Value(result.Clone()));
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
complete_info_promise_set_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUInfoManager::OnGpuInfoUpdate() {
|
|
|
|
// Ignore if called when not asked for complete GPUInfo
|
|
|
|
if (NeedsCompleteGpuInfoCollection())
|
|
|
|
return;
|
2023-02-03 11:43:42 +00:00
|
|
|
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
2018-09-27 14:59:23 +00:00
|
|
|
FROM_HERE, base::BindOnce(&GPUInfoManager::ProcessCompleteInfo,
|
|
|
|
base::Unretained(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should be posted to the task runner
|
2019-08-23 00:03:28 +00:00
|
|
|
void GPUInfoManager::CompleteInfoFetcher(
|
2022-06-28 16:52:59 +00:00
|
|
|
gin_helper::Promise<base::Value> promise) {
|
2019-02-21 12:32:44 +00:00
|
|
|
complete_info_promise_set_.emplace_back(std::move(promise));
|
2018-09-27 14:59:23 +00:00
|
|
|
|
|
|
|
if (NeedsCompleteGpuInfoCollection()) {
|
2021-08-11 21:04:56 +00:00
|
|
|
gpu_data_manager_->RequestDxdiagDx12VulkanVideoGpuInfoIfNeeded(
|
2021-06-22 19:17:16 +00:00
|
|
|
content::GpuDataManagerImpl::kGpuInfoRequestAll, /* delayed */ false);
|
2018-09-27 14:59:23 +00:00
|
|
|
} else {
|
|
|
|
GPUInfoManager::OnGpuInfoUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 00:03:28 +00:00
|
|
|
void GPUInfoManager::FetchCompleteInfo(
|
2022-06-28 16:52:59 +00:00
|
|
|
gin_helper::Promise<base::Value> promise) {
|
2023-02-03 11:43:42 +00:00
|
|
|
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
2018-09-27 14:59:23 +00:00
|
|
|
FROM_HERE, base::BindOnce(&GPUInfoManager::CompleteInfoFetcher,
|
2019-02-21 12:32:44 +00:00
|
|
|
base::Unretained(this), std::move(promise)));
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This fetches the info synchronously, so no need to post to the task queue.
|
|
|
|
// There cannot be multiple promises as they are resolved synchronously.
|
2022-06-28 16:52:59 +00:00
|
|
|
void GPUInfoManager::FetchBasicInfo(gin_helper::Promise<base::Value> promise) {
|
2018-09-27 14:59:23 +00:00
|
|
|
gpu::GPUInfo gpu_info;
|
|
|
|
CollectBasicGraphicsInfo(&gpu_info);
|
2022-06-28 16:52:59 +00:00
|
|
|
promise.Resolve(base::Value(EnumerateGPUInfo(gpu_info)));
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 16:52:59 +00:00
|
|
|
base::Value::Dict GPUInfoManager::EnumerateGPUInfo(
|
2018-09-27 14:59:23 +00:00
|
|
|
gpu::GPUInfo gpu_info) const {
|
|
|
|
GPUInfoEnumerator enumerator;
|
|
|
|
gpu_info.EnumerateFields(&enumerator);
|
|
|
|
return enumerator.GetDictionary();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|