Browse Source

Add app.disableHardwareAcceleration() API

Cheng Zhao 9 years ago
parent
commit
02cfe30df9
3 changed files with 19 additions and 2 deletions
  1. 12 1
      atom/browser/api/atom_api_app.cc
  2. 1 1
      atom/browser/api/atom_api_app.h
  3. 6 0
      docs/api/app.md

+ 12 - 1
atom/browser/api/atom_api_app.cc

@@ -447,6 +447,15 @@ bool App::Relaunch(mate::Arguments* js_args) {
   return relauncher::RelaunchApp(argv);
 }
 
+void App::DisableHardwareAcceleration(mate::Arguments* args) {
+  if (Browser::Get()->is_ready()) {
+    args->ThrowError("app.disableHardwareAcceleration() can only be called "
+                     "before app is ready");
+    return;
+  }
+  content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
+}
+
 #if defined(USE_NSS_CERTS)
 void App::ImportCertificate(
     const base::DictionaryValue& options,
@@ -528,7 +537,9 @@ void App::BuildPrototype(
 #endif
       .SetMethod("makeSingleInstance", &App::MakeSingleInstance)
       .SetMethod("releaseSingleInstance", &App::ReleaseSingleInstance)
-      .SetMethod("relaunch", &App::Relaunch);
+      .SetMethod("relaunch", &App::Relaunch)
+      .SetMethod("disableHardwareAcceleration",
+                 &App::DisableHardwareAcceleration);
 }
 
 }  // namespace api

+ 1 - 1
atom/browser/api/atom_api_app.h

@@ -111,7 +111,7 @@ class App : public AtomBrowserClient::Delegate,
       const ProcessSingleton::NotificationCallback& callback);
   void ReleaseSingleInstance();
   bool Relaunch(mate::Arguments* args);
-
+  void DisableHardwareAcceleration(mate::Arguments* args);
 #if defined(USE_NSS_CERTS)
   void ImportCertificate(const base::DictionaryValue& options,
                          const net::CompletionCallback& callback);

+ 6 - 0
docs/api/app.md

@@ -561,6 +561,12 @@ Imports the certificate in pkcs12 format into the platform certificate store.
 `callback` is called with the `result` of import operation, a value of `0`
 indicates success while any other value indicates failure according to chromium [net_error_list](https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h).
 
+### `app.disableHardwareAcceleration()`
+
+Disables hardware acceleration for current app.
+
+This method can only be called before app is ready.
+
 ### `app.commandLine.appendSwitch(switch[, value])`
 
 Append a switch (with optional `value`) to Chromium's command line.