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 "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"
|
2024-07-29 17:42:57 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2024-07-02 07:51:33 +00:00
|
|
|
#include "shell/common/thread_restrictions.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
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));
|
2024-03-12 09:15:41 +00:00
|
|
|
gpu_data_manager_->RequestDx12VulkanVideoGpuInfoIfNeeded(
|
|
|
|
content::GpuDataManagerImpl::kGpuInfoRequestAll, /* delayed */ false);
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2024-07-02 07:51:33 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
// Needed for CollectNPUInformation in gpu/config/gpu_info_collector_win.cc
|
|
|
|
// which calls blocking function base::LoadSystemLibrary.
|
|
|
|
electron::ScopedAllowBlockingForElectron allow_blocking;
|
|
|
|
#endif
|
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
|