Skip to content

Commit

Permalink
headless: Enable GL support by default
Browse files Browse the repository at this point in the history
Enable GL support by default so that WebGL and GL-based canvas rendering
can be used. GL support can still be disabled to save resources if
necessary.

BUG=617551

Review-Url: https://codereview.chromium.org/2184763002
Cr-Commit-Position: refs/heads/master@{#408121}
  • Loading branch information
skyostil authored and Commit bot committed Jul 27, 2016
1 parent d172705 commit ff3c237
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions headless/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ include_rules = [
"+ui/display",
"+ui/gfx",
"+ui/gfx/geometry",
"+ui/gl",
"+ui/ozone/public",
]
15 changes: 15 additions & 0 deletions headless/lib/headless_browser_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,19 @@ IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, HttpsProtocolHandler) {
EXPECT_EQ(kResponseBody, inner_html);
}

IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, WebGLSupported) {
HeadlessWebContents* web_contents =
browser()->CreateWebContentsBuilder().Build();

bool webgl_supported;
EXPECT_TRUE(EvaluateScript(
web_contents,
"(document.createElement('canvas').getContext('webgl')"
" instanceof WebGLRenderingContext)")
->GetResult()
->GetValue()
->GetAsBoolean(&webgl_supported));
EXPECT_TRUE(webgl_supported);
}

} // namespace headless
9 changes: 7 additions & 2 deletions headless/lib/headless_content_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "headless/lib/renderer/headless_content_renderer_client.h"
#include "headless/lib/utility/headless_content_utility_client.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gl/gl_switches.h"
#include "ui/ozone/public/ozone_switches.h"

namespace headless {
Expand Down Expand Up @@ -51,8 +52,12 @@ bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) {
// adding it here allows us to run in a non-headless build too.
command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless");

// TODO(skyostil): Investigate using Mesa/SwiftShader for output.
command_line->AppendSwitch(switches::kDisableGpu);
if (!browser_->options()->gl_implementation.empty()) {
command_line->AppendSwitchASCII(switches::kUseGL,
browser_->options()->gl_implementation);
} else {
command_line->AppendSwitch(switches::kDisableGpu);
}

SetContentClient(&content_client_);
return false;
Expand Down
8 changes: 7 additions & 1 deletion headless/public/headless_browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Options::Options(int argc, const char** argv)
user_agent(content::BuildUserAgentFromProduct(kProductName)),
message_pump(nullptr),
single_process_mode(false),
disable_sandbox(false) {}
disable_sandbox(false),
gl_implementation("osmesa") {}

Options::Options(Options&& options) = default;

Expand Down Expand Up @@ -75,6 +76,11 @@ Builder& Builder::SetProtocolHandlers(ProtocolHandlerMap protocol_handlers) {
return *this;
}

Builder& Builder::SetGLImplementation(const std::string& gl_implementation) {
options_.gl_implementation = gl_implementation;
return *this;
}

Options Builder::Build() {
return std::move(options_);
}
Expand Down
6 changes: 6 additions & 0 deletions headless/public/headless_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ struct HeadlessBrowser::Options {
// fetching for different network schemes.
ProtocolHandlerMap protocol_handlers;

// Choose the GL implementation to use for rendering. A suitable
// implementantion is selected by default. Setting this to an empty
// string can be used to disable GL rendering (e.g., WebGL support).
std::string gl_implementation;

private:
Options(int argc, const char** argv);

Expand All @@ -141,6 +146,7 @@ class HeadlessBrowser::Options::Builder {
Builder& SetSingleProcessMode(bool single_process_mode);
Builder& SetDisableSandbox(bool disable_sandbox);
Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers);
Builder& SetGLImplementation(const std::string& gl_implementation);

Options Build();

Expand Down

0 comments on commit ff3c237

Please sign in to comment.