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"
|
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
|
|
|
#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"
|
2018-09-27 14:59:23 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-09-27 14:59:23 +00:00
|
|
|
|
|
|
|
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 {
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
return gpu_data_manager_->GetGPUInfo().gl_vendor.empty();
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
return (gpu_data_manager_->GetGPUInfo().dx_diagnostics.values.empty() &&
|
|
|
|
gpu_data_manager_->GetGPUInfo().dx_diagnostics.children.empty());
|
2018-09-27 14:59:23 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should be posted to the task runner
|
|
|
|
void GPUInfoManager::ProcessCompleteInfo() {
|
|
|
|
const auto result = EnumerateGPUInfo(gpu_data_manager_->GetGPUInfo());
|
|
|
|
// 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_) {
|
|
|
|
promise.Resolve(*result);
|
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;
|
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
|
|
|
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(
|
|
|
|
util::Promise<base::DictionaryValue> 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()) {
|
2019-10-18 19:57:34 +00:00
|
|
|
gpu_data_manager_->RequestDxdiagDx12VulkanGpuInfoIfNeeded(
|
2019-09-18 19:58:00 +00:00
|
|
|
content::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(
|
|
|
|
util::Promise<base::DictionaryValue> promise) {
|
2018-09-27 14:59:23 +00:00
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
|
|
|
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.
|
2019-08-23 00:03:28 +00:00
|
|
|
void GPUInfoManager::FetchBasicInfo(
|
|
|
|
util::Promise<base::DictionaryValue> promise) {
|
2018-09-27 14:59:23 +00:00
|
|
|
gpu::GPUInfo gpu_info;
|
|
|
|
CollectBasicGraphicsInfo(&gpu_info);
|
2019-02-21 12:32:44 +00:00
|
|
|
promise.Resolve(*EnumerateGPUInfo(gpu_info));
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<base::DictionaryValue> GPUInfoManager::EnumerateGPUInfo(
|
|
|
|
gpu::GPUInfo gpu_info) const {
|
|
|
|
GPUInfoEnumerator enumerator;
|
|
|
|
gpu_info.EnumerateFields(&enumerator);
|
|
|
|
return enumerator.GetDictionary();
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|