feat: add app.isHardwareAccelerationEnabled() (#48680)

* feat: add app.isHardwareAccelerationEnabled()

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: address review feedback

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-11-13 10:32:14 -05:00 committed by GitHub
commit bb930b887b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 0 deletions

View file

@ -1216,6 +1216,13 @@ Disables hardware acceleration for current app.
This method can only be called before app is ready. This method can only be called before app is ready.
### `app.isHardwareAccelerationEnabled()`
Returns `boolean` - whether hardware acceleration is currently disabled.
> [!NOTE]
> This information is only usable after the `gpu-info-update` event is emitted.
### `app.disableDomainBlockingFor3DAPIs()` ### `app.disableDomainBlockingFor3DAPIs()`
By default, Chromium disables 3D APIs (e.g. WebGL) until restart on a per By default, Chromium disables 3D APIs (e.g. WebGL) until restart on a per

View file

@ -1136,6 +1136,10 @@ void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) {
"before app is ready"); "before app is ready");
return; return;
} }
// If the GpuDataManager is already initialized, disable hardware
// acceleration immediately. Otherwise, set a flag to disable it in
// OnPreCreateThreads().
if (content::GpuDataManager::Initialized()) { if (content::GpuDataManager::Initialized()) {
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration(); content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
} else { } else {
@ -1143,6 +1147,13 @@ void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) {
} }
} }
bool App::IsHardwareAccelerationEnabled() {
if (content::GpuDataManager::Initialized())
return content::GpuDataManager::GetInstance()
->HardwareAccelerationEnabled();
return !disable_hw_acceleration_;
}
void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) { void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) {
if (Browser::Get()->is_ready()) { if (Browser::Get()->is_ready()) {
thrower.ThrowError( thrower.ThrowError(
@ -1923,6 +1934,8 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
&App::SetAccessibilitySupportEnabled) &App::SetAccessibilitySupportEnabled)
.SetMethod("disableHardwareAcceleration", .SetMethod("disableHardwareAcceleration",
&App::DisableHardwareAcceleration) &App::DisableHardwareAcceleration)
.SetMethod("isHardwareAccelerationEnabled",
&App::IsHardwareAccelerationEnabled)
.SetMethod("disableDomainBlockingFor3DAPIs", .SetMethod("disableDomainBlockingFor3DAPIs",
&App::DisableDomainBlockingFor3DAPIs) &App::DisableDomainBlockingFor3DAPIs)
.SetMethod("getFileIcon", &App::GetFileIcon) .SetMethod("getFileIcon", &App::GetFileIcon)

View file

@ -212,6 +212,7 @@ class App final : public gin::Wrappable<App>,
void ReleaseSingleInstanceLock(); void ReleaseSingleInstanceLock();
bool Relaunch(gin::Arguments* args); bool Relaunch(gin::Arguments* args);
void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower); void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);
bool IsHardwareAccelerationEnabled();
void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower); void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower);
bool IsAccessibilitySupportEnabled(); bool IsAccessibilitySupportEnabled();
v8::Local<v8::Value> GetAccessibilitySupportFeatures(); v8::Local<v8::Value> GetAccessibilitySupportFeatures();

View file

@ -149,6 +149,12 @@ describe('app module', () => {
}); });
}); });
describe('app.isHardwareAccelerationEnabled()', () => {
it('should be a boolean', () => {
expect(app.isHardwareAccelerationEnabled()).to.be.a('boolean');
});
});
describe('app.isPackaged', () => { describe('app.isPackaged', () => {
it('should be false during tests', () => { it('should be false during tests', () => {
expect(app.isPackaged).to.equal(false); expect(app.isPackaged).to.equal(false);