From aef9fd486a77d8373bf9568d5535b878dbdd98ed Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 17 Aug 2015 18:14:59 -0400 Subject: [PATCH] cefclient: Set recommended command-line switches for off-screen rendering --- tests/cefclient/browser/client_app_browser.cc | 37 +++++++++++++++++++ tests/cefclient/browser/client_app_browser.h | 3 ++ tests/cefclient/common/client_switches.cc | 1 + tests/cefclient/common/client_switches.h | 1 + 4 files changed, 42 insertions(+) diff --git a/tests/cefclient/browser/client_app_browser.cc b/tests/cefclient/browser/client_app_browser.cc index 2302a6ec3..98a3557b6 100644 --- a/tests/cefclient/browser/client_app_browser.cc +++ b/tests/cefclient/browser/client_app_browser.cc @@ -6,12 +6,49 @@ #include "include/base/cef_logging.h" #include "include/cef_cookie.h" +#include "cefclient/common/client_switches.h" namespace client { ClientAppBrowser::ClientAppBrowser() { } +void ClientAppBrowser::OnBeforeCommandLineProcessing( + const CefString& process_type, + CefRefPtr command_line) { + // Pass additional command-line flags to the browser process. + if (process_type.empty()) { + // Pass additional command-line flags when off-screen rendering is enabled. + if (command_line->HasSwitch(switches::kOffScreenRenderingEnabled)) { + // If the PDF extension is enabled then cc Surfaces must be disabled for + // PDFs to render correctly. + // See https://bitbucket.org/chromiumembedded/cef/issues/1689 for details. + if (!command_line->HasSwitch("disable-extensions") && + !command_line->HasSwitch("disable-pdf-extension")) { + command_line->AppendSwitch("disable-surfaces"); + } + + // Use software rendering and compositing (disable GPU) for increased FPS + // and decreased CPU usage. This will also disable WebGL so remove these + // switches if you need that capability. + // See https://bitbucket.org/chromiumembedded/cef/issues/1257 for details. + if (!command_line->HasSwitch(switches::kEnableGPU)) { + command_line->AppendSwitch("disable-gpu"); + command_line->AppendSwitch("disable-gpu-compositing"); + } + + // Synchronize the frame rate between all processes. This results in + // decreased CPU usage by avoiding the generation of extra frames that + // would otherwise be discarded. The frame rate can be set at browser + // creation time via CefBrowserSettings.windowless_frame_rate or changed + // dynamically using CefBrowserHost::SetWindowlessFrameRate. In cefclient + // it can be set via the command-line using `--off-screen-frame-rate=XX`. + // See https://bitbucket.org/chromiumembedded/cef/issues/1368 for details. + command_line->AppendSwitch("enable-begin-frame-scheduling"); + } + } +} + void ClientAppBrowser::OnContextInitialized() { CreateDelegates(delegates_); diff --git a/tests/cefclient/browser/client_app_browser.h b/tests/cefclient/browser/client_app_browser.h index e38d874e4..18a4041a1 100644 --- a/tests/cefclient/browser/client_app_browser.h +++ b/tests/cefclient/browser/client_app_browser.h @@ -46,6 +46,9 @@ class ClientAppBrowser : public ClientApp, static CefRefPtr CreatePrintHandler(); // CefApp methods. + void OnBeforeCommandLineProcessing( + const CefString& process_type, + CefRefPtr command_line) OVERRIDE; CefRefPtr GetBrowserProcessHandler() OVERRIDE { return this; } diff --git a/tests/cefclient/common/client_switches.cc b/tests/cefclient/common/client_switches.cc index 0de1de39a..50c5989f4 100644 --- a/tests/cefclient/common/client_switches.cc +++ b/tests/cefclient/common/client_switches.cc @@ -27,6 +27,7 @@ const char kShowUpdateRect[] = "show-update-rect"; const char kMouseCursorChangeDisabled[] = "mouse-cursor-change-disabled"; const char kRequestContextPerBrowser[] = "request-context-per-browser"; const char kBackgroundColor[] = "background-color"; +const char kEnableGPU[] = "enable-gpu"; } // namespace switches } // namespace client diff --git a/tests/cefclient/common/client_switches.h b/tests/cefclient/common/client_switches.h index d52e1cdb3..c94351c51 100644 --- a/tests/cefclient/common/client_switches.h +++ b/tests/cefclient/common/client_switches.h @@ -21,6 +21,7 @@ extern const char kShowUpdateRect[]; extern const char kMouseCursorChangeDisabled[]; extern const char kRequestContextPerBrowser[]; extern const char kBackgroundColor[]; +extern const char kEnableGPU[]; } // namespace switches } // namespace client