-
Notifications
You must be signed in to change notification settings - Fork 16.2k
feat: Implementation of getGPUInfo API. #13486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6dc03f6
Implementation of getGPUInfo API.
nitsakh 0e3f918
Clear promise set
nitsakh 6e072a9
Changes to promise usage
nitsakh 694d498
Minor fixes
nitsakh c88fa85
Fix linux build
nitsakh 4f63f59
Update spec
nitsakh 69033e8
Fix lint (linter didn't run on windows locally)
nitsakh a795f54
Test running single test for CI
nitsakh 7c81055
Merge branch 'api-gpuinfo' of https://github.com/electron/electron in…
nitsakh 86945d9
Update spec
nitsakh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/browser/api/gpu_info_enumerator.h" | ||
|
||
#include <utility> | ||
|
||
namespace atom { | ||
|
||
GPUInfoEnumerator::GPUInfoEnumerator() | ||
: value_stack(), current(std::make_unique<base::DictionaryValue>()) {} | ||
|
||
GPUInfoEnumerator::~GPUInfoEnumerator() {} | ||
|
||
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()); | ||
} | ||
|
||
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(); | ||
top_value->SetDictionary(kVideoDecodeAcceleratorSupportedProfileKey, | ||
std::move(current)); | ||
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(); | ||
top_value->SetDictionary(kVideoEncodeAcceleratorSupportedProfileKey, | ||
std::move(current)); | ||
current = std::move(top_value); | ||
value_stack.pop(); | ||
} | ||
|
||
void GPUInfoEnumerator::BeginAuxAttributes() { | ||
value_stack.push(std::move(current)); | ||
current = std::make_unique<base::DictionaryValue>(); | ||
} | ||
|
||
void GPUInfoEnumerator::EndAuxAttributes() { | ||
auto& top_value = value_stack.top(); | ||
top_value->SetDictionary(kAuxAttributesKey, std::move(current)); | ||
current = std::move(top_value); | ||
value_stack.pop(); | ||
} | ||
|
||
std::unique_ptr<base::DictionaryValue> GPUInfoEnumerator::GetDictionary() { | ||
return std::move(current); | ||
} | ||
|
||
} // namespace atom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | 6D47Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_BROWSER_API_GPU_INFO_ENUMERATOR_H_ | ||
#define ATOM_BROWSER_API_GPU_INFO_ENUMERATOR_H_ | ||
|
||
#include <memory> | ||
#include <stack> | ||
#include <string> | ||
|
||
#include "base/values.h" | ||
#include "gpu/config/gpu_info.h" | ||
|
||
namespace atom { | ||
|
||
// This class implements the enumerator for reading all the attributes in | ||
// GPUInfo into a dictionary. | ||
class GPUInfoEnumerator final : public gpu::GPUInfo::Enumerator { | ||
const char* kGPUDeviceKey = "gpuDevice"; | ||
const char* kVideoDecodeAcceleratorSupportedProfileKey = | ||
"videoDecodeAcceleratorSupportedProfile"; | ||
const char* kVideoEncodeAcceleratorSupportedProfileKey = | ||
"videoEncodeAcceleratorSupportedProfile"; | ||
const char* kAuxAttributesKey = "auxAttributes"; | ||
|
||
public: | ||
GPUInfoEnumerator(); | ||
~GPUInfoEnumerator() override; | ||
void AddInt64(const char* name, int64_t value) override; | ||
void AddInt(const char* name, int value) override; | ||
void AddString(const char* name, const std::string& value) override; | ||
void AddBool(const char* name, bool value) override; | ||
void AddTimeDeltaInSecondsF(const char* name, | ||
const base::TimeDelta& value) override; | ||
void BeginGPUDevice() override; | ||
void EndGPUDevice() override; | ||
void BeginVideoDecodeAcceleratorSupportedProfile() override; | ||
void EndVideoDecodeAcceleratorSupportedProfile() override; | ||
void BeginVideoEncodeAcceleratorSupportedProfile() override; | ||
void EndVideoEncodeAcceleratorSupportedProfile() override; | ||
void BeginAuxAttributes() override; | ||
void EndAuxAttributes() override; | ||
std::unique_ptr<base::DictionaryValue> GetDictionary(); | ||
|
||
private: | ||
// The stack is used to manage nested values | ||
std::stack<std::unique_ptr<base::DictionaryValue>> value_stack; | ||
std::unique_ptr<base::DictionaryValue> current; | ||
}; | ||
|
||
} // namespace atom | ||
#endif // ATOM_BROWSER_API_GPU_INFO_ENUMERATOR_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/browser/api/gpuinfo_manager.h" | ||
#include "atom/browser/api/gpu_info_enumerator.h" | ||
#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" | ||
|
||
namespace atom { | ||
|
||
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 | ||
// https://chromium.googlesource.com/chromium/src.git/+/66.0.3359.181/content/browser/gpu/gpu_data_manager_impl_private.cc#810 | ||
bool GPUInfoManager::NeedsCompleteGpuInfoCollection() { | ||
#if defined(OS_MACOSX) | ||
return gpu_data_manager_->GetGPUInfo().gl_vendor.empty(); | ||
#elif defined(OS_WIN) | ||
const auto& gpu_info = gpu_data_manager_->GetGPUInfo(); | ||
return (gpu_info.dx_diagnostics.values.empty() && | ||
gpu_info.dx_diagnostics.children.empty()); | ||
#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. | ||
for (const auto& promise : complete_info_promise_set_) { | ||
promise->Resolve(*result); | ||
} | ||
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 | ||
void GPUInfoManager::CompleteInfoFetcher(scoped_refptr<util::Promise> promise) { | ||
complete_info_promise_set_.push_back(promise); | ||
|
||
if (NeedsCompleteGpuInfoCollection()) { | ||
gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); | ||
} else { | ||
GPUInfoManager::OnGpuInfoUpdate(); | ||
} | ||
} | ||
|
||
void GPUInfoManager::FetchCompleteInfo(scoped_refptr<util::Promise> promise) { | ||
base::ThreadTaskRunnerHandle::Get()->PostTask( | ||
deepak1556 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FROM_HERE, base::BindOnce(&GPUInfoManager::CompleteInfoFetcher, | ||
base::Unretained(this), promise)); | ||
} | ||
|
||
// This fetches the info synchronously, so no need to post to the task queue. | ||
// There cannot be multiple promises as they are resolved synchronously. | ||
void GPUInfoManager::FetchBasicInfo(scoped_refptr<util::Promise> promise) { | ||
gpu::GPUInfo gpu_info; | ||
CollectBasicGraphicsInfo(&gpu_info); | ||
promise->Resolve(*EnumerateGPUInfo(gpu_info)); | ||
} | ||
|
||
std::unique_ptr<base::DictionaryValue> GPUInfoManager::EnumerateGPUInfo( | ||
gpu::GPUInfo gpu_info) const { | ||
GPUInfoEnumerator enumerator; | ||
gpu_info.EnumerateFields(&enumerator); | ||
return enumerator.GetDictionary(); | ||
} | ||
|
||
} // namespace atom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_BROWSER_API_GPUINFO_MANAGER_H_ | ||
#define ATOM_BROWSER_API_GPUINFO_MANAGER_H_ | ||
|
||
#include <memory> | ||
#include <unordered_set> | ||
#include <vector> | ||
|
||
#include "atom/common/native_mate_converters/value_converter.h" | ||
#include "atom/common/promise_util.h" | ||
#include "content/browser/gpu/gpu_data_manager_impl.h" | ||
#include "content/public/browser/gpu_data_manager.h" | ||
#include "content/public/browser/gpu_data_manager_observer.h" | ||
|
||
namespace atom { | ||
|
||
// GPUInfoManager is a singleton used to manage and fetch GPUInfo | ||
class GPUInfoManager : public content::GpuDataManagerObserver { | ||
public: | ||
static GPUInfoManager* GetInstance(); | ||
|
||
GPUInfoManager(); | ||
~GPUInfoManager() override; | ||
bool NeedsCompleteGpuInfoCollection(); | ||
void FetchCompleteInfo(scoped_refptr<util::Promise> promise); | ||
void FetchBasicInfo(scoped_refptr<util::Promise> promise); | ||
void OnGpuInfoUpdate() override; | ||
|
||
private: | ||
std::unique_ptr<base::DictionaryValue> EnumerateGPUInfo( | ||
gpu::GPUInfo gpu_info) const; | ||
|
||
// These should be posted to the task queue | ||
void CompleteInfoFetcher(scoped_refptr<util::Promise> promise); | ||
void ProcessCompleteInfo(); | ||
|
||
// This set maintains all the promises that should be fulfilled | ||
// once we have the complete information data | ||
std::vector<scoped_refptr<util::Promise>> complete_info_promise_set_; | ||
content::GpuDataManager* gpu_data_manager_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(GPUInfoManager); | ||
}; | ||
|
||
} // namespace atom | ||
#endif // ATOM_BROWSER_API_GPUINFO_MANAGER_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.