From 0ecfb4e2f86ea1d606aceefdfc67c3c0527d908b Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 30 May 2017 19:06:08 +0200 Subject: [PATCH 1/4] Add app.getGPUFeatureStatus --- atom/browser/api/atom_api_app.cc | 30 +++++++++++++++++++++++ atom/browser/api/atom_api_app.h | 1 + docs/api/app.md | 4 +++ docs/api/structures/gpu-feature-status.md | 29 ++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 docs/api/structures/gpu-feature-status.md diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index d6fe607de496..fd4fe4b79ced 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -34,6 +34,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/icon_manager.h" #include "chrome/common/chrome_paths.h" +#include "content/browser/gpu/compositor_util.h" #include "content/public/browser/browser_accessibility_state.h" #include "content/public/browser/browser_child_process_host.h" #include "content/public/browser/child_process_data.h" @@ -1021,6 +1022,34 @@ std::vector App::GetAppMetrics(v8::Isolate* isolate) { return result; } +static mate::Dictionary ConvertDictionary( + v8::Isolate* isolate, const base::DictionaryValue &dict) { + auto result = mate::Dictionary::CreateEmpty(isolate); + + for (base::DictionaryValue::Iterator iterator(dict); + !iterator.IsAtEnd(); + iterator.Advance()) { + auto& key = iterator.key(); + auto& value = iterator.value(); + if (value.is_string()) { + std::string strValue; + if (value.GetAsString(&strValue)) { + result.Set(key, strValue); + } + } + } + + return result; +} + +mate::Dictionary App::GetGPUFeatureStatus(v8::Isolate* isolate) { + if (auto status = content::GetFeatureStatus()) { + return ConvertDictionary(isolate, *status); + } else { + return mate::Dictionary::CreateEmpty(isolate); + } +} + // static mate::Handle App::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new App(isolate)); @@ -1094,6 +1123,7 @@ void App::BuildPrototype( &App::DisableHardwareAcceleration) .SetMethod("getFileIcon", &App::GetFileIcon) .SetMethod("getAppMetrics", &App::GetAppMetrics) + .SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus) // TODO(juturu): Remove in 2.0, deprecate before then with warnings .SetMethod("getAppMemoryInfo", &App::GetAppMetrics); } diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index d68b172a7fad..eab1dcdf88ab 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -177,6 +177,7 @@ class App : public AtomBrowserClient::Delegate, mate::Arguments* args); std::vector GetAppMetrics(v8::Isolate* isolate); + mate::Dictionary GetGPUFeatureStatus(v8::Isolate* isolate); #if defined(OS_WIN) // Get the current Jump List settings. diff --git a/docs/api/app.md b/docs/api/app.md index 78d3942985e8..784b20a47301 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -771,6 +771,10 @@ Returns [`ProcessMetric[]`](structures/process-metric.md): Array of `ProcessMet Returns [`ProcessMetric[]`](structures/process-metric.md): Array of `ProcessMetric` objects that correspond to memory and cpu usage statistics of all the processes associated with the app. +### `app.getGpuFeatureStatus()` + +Returns [`GPUFeatureStatus`](structures/gpu-feature-status.md) - The Graphics Feature Status from `chrome://gpu/`. + ### `app.setBadgeCount(count)` _Linux_ _macOS_ * `count` Integer diff --git a/docs/api/structures/gpu-feature-status.md b/docs/api/structures/gpu-feature-status.md new file mode 100644 index 000000000000..f7bf3933d6c4 --- /dev/null +++ b/docs/api/structures/gpu-feature-status.md @@ -0,0 +1,29 @@ +# GPUFeatureStatus Object + +* `2d_canvas` String - Canvas +* `flash_3d` String - Flash +* `flash_stage3d` String - Flash Stage3D +* `flash_stage3d_baseline` String - Flash Stage3D Baseline profile +* `gpu_compositing` String - Compositing +* `multiple_raster_threads` String - Multiple Raster Threads +* `native_gpu_memory_buffers` String - Native GpuMemoryBuffers +* `rasterization` String - Rasterization +* `video_decode` String - Video Decode +* `video_encode` String - Video Encode +* `vpx_decode` String - VPx Video Decode +* `webgl` String - WebGL +* `webgl2` String - WebGL2 + +Possible values: + +* `disabled_software` - Software only. Hardware acceleration disabled (yellow) +* `disabled_off` - Disabled (red) +* `disabled_off_ok` - Disabled (yellow) +* `unavailable_software` - Software only, hardware acceleration unavailable (yellow) +* `unavailable_off` - Unavailable (red) +* `unavailable_off_ok` - Unavailable (yellow) +* `enabled_readback` - Hardware accelerated but at reduced performance (yellow) +* `enabled_force` - Hardware accelerated on all pages (green) +* `enabled` - Hardware accelerated (green) +* `enabled_on` - Enabled (green) +* `enabled_force_on` - Force enabled (green) From 4a5831a73381955b02cb1996791c0382fcad6b1c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 30 May 2017 13:00:00 -0700 Subject: [PATCH 2/4] Add initial getGPUFeatureStatus spec --- spec/api-app-spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index fdf8510f90ef..bbba81955f93 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -558,4 +558,14 @@ describe('app module', function () { assert.ok(types.includes('Tab')) }) }) + + describe('getGPUFeatureStatus() API', function () { + if (process.platform !== 'darwin') return + + it('returns the graphic features statuses', function () { + const features = app.getGPUFeatureStatus() + assert.equal(typeof features.webgl, 'string') + assert.equal(typeof features.gpu_compositing, 'string') + }) + }) }) From bf2fca3dd13988ccbb371aedaa5880ae7a5731d9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 30 May 2017 13:00:55 -0700 Subject: [PATCH 3/4] Use base::DictionaryValue converter --- atom/browser/api/atom_api_app.cc | 30 ++++-------------------------- atom/browser/api/atom_api_app.h | 2 +- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index fd4fe4b79ced..8f2d08277aea 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -1022,32 +1022,10 @@ std::vector App::GetAppMetrics(v8::Isolate* isolate) { return result; } -static mate::Dictionary ConvertDictionary( - v8::Isolate* isolate, const base::DictionaryValue &dict) { - auto result = mate::Dictionary::CreateEmpty(isolate); - - for (base::DictionaryValue::Iterator iterator(dict); - !iterator.IsAtEnd(); - iterator.Advance()) { - auto& key = iterator.key(); - auto& value = iterator.value(); - if (value.is_string()) { - std::string strValue; - if (value.GetAsString(&strValue)) { - result.Set(key, strValue); - } - } - } - - return result; -} - -mate::Dictionary App::GetGPUFeatureStatus(v8::Isolate* isolate) { - if (auto status = content::GetFeatureStatus()) { - return ConvertDictionary(isolate, *status); - } else { - return mate::Dictionary::CreateEmpty(isolate); - } +v8::Local App::GetGPUFeatureStatus(v8::Isolate* isolate) { + auto status = content::GetFeatureStatus(); + return mate::ConvertToV8(isolate, + status ? *status : base::DictionaryValue()); } // static diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index eab1dcdf88ab..f97265943509 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -177,7 +177,7 @@ class App : public AtomBrowserClient::Delegate, mate::Arguments* args); std::vector GetAppMetrics(v8::Isolate* isolate); - mate::Dictionary GetGPUFeatureStatus(v8::Isolate* isolate); + v8::Local GetGPUFeatureStatus(v8::Isolate* isolate); #if defined(OS_WIN) // Get the current Jump List settings. From 55fcb286a5c4ab0ecf97a0de1086fbe10f83abbb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 31 May 2017 08:10:55 -0700 Subject: [PATCH 4/4] Run getGPUFeatureStatus spec on all platforms --- spec/api-app-spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index bbba81955f93..cda0fbea2109 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -560,8 +560,6 @@ describe('app module', function () { }) describe('getGPUFeatureStatus() API', function () { - if (process.platform !== 'darwin') return - it('returns the graphic features statuses', function () { const features = app.getGPUFeatureStatus() assert.equal(typeof features.webgl, 'string')