Implement a runtime headless mode for Linux
This patch implements a runtime headless mode (i.e., a
--headless command line switch) that makes it possible to
use a regular Chrome binary as a headless. When the binary
is launched with this switch, the main entrypoint calls
into the Headless Shell entrypoint, effectively starting
that shell instead of Chrome.
To make this possible we must remove the dependency from
Headless to Ozone, because Ozone is a build-time feature
which is generally not enabled for regular Chrome builds.
In practice this means implementing a new headless-specific
WindowTreeHost and modifying various graphics and input
entrypoints to do something appropriate in headless mode.
Since many of the modifications are in platform-specific
code, this initial patch only adds headless support in Linux.
Other platforms will be added later.
Design doc: https://docs.google.com/document/d/1aIJUzQr3eougZQp90bp4mqGr5gY6hdUice8UPa-Ys90/edit#
BUG=612904
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Review-Url: https://codereview.chromium.org/1991953002
Cr-Commit-Position: refs/heads/master@{#438239}
diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc
index a529db7..00c21c8 100644
--- a/content/gpu/gpu_main.cc
+++ b/content/gpu/gpu_main.cc
@@ -40,6 +40,7 @@
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "ui/events/platform/platform_event_source.h"
+#include "ui/gfx/switches.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
@@ -200,35 +201,39 @@
// TODO(ericrk): Revisit this once we assess its impact on crbug.com/662802
// and crbug.com/609252.
std::unique_ptr<base::MessageLoop> main_message_loop;
-
+ if (command_line.HasSwitch(switches::kHeadless)) {
+ main_message_loop.reset(
+ new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
+ } else {
#if defined(OS_WIN)
- // OK to use default non-UI message loop because all GPU windows run on
- // dedicated thread.
- main_message_loop.reset(
- new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
+ // OK to use default non-UI message loop because all GPU windows run on
+ // dedicated thread.
+ main_message_loop.reset(
+ new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
#elif defined(USE_X11)
- // We need a UI loop so that we can grab the Expose events. See GLSurfaceGLX
- // and https://crbug.com/326995.
- main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
- std::unique_ptr<ui::PlatformEventSource> event_source =
- ui::PlatformEventSource::CreateDefault();
+ // We need a UI loop so that we can grab the Expose events. See GLSurfaceGLX
+ // and https://crbug.com/326995.
+ main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
+ std::unique_ptr<ui::PlatformEventSource> event_source =
+ ui::PlatformEventSource::CreateDefault();
#elif defined(USE_OZONE) && defined(OZONE_X11)
- // If we might be running Ozone X11 we need a UI loop to grab Expose events.
- // See GLSurfaceGLX and https://crbug.com/326995.
- main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
+ // If we might be running Ozone X11 we need a UI loop to grab Expose events.
+ // See GLSurfaceGLX and https://crbug.com/326995.
+ main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
#elif defined(USE_OZONE)
- main_message_loop.reset(
- new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
+ main_message_loop.reset(
+ new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
#elif defined(OS_LINUX)
#error "Unsupported Linux platform."
#elif defined(OS_MACOSX)
- // This is necessary for CoreAnimation layers hosted in the GPU process to be
- // drawn. See http://crbug.com/312462.
- std::unique_ptr<base::MessagePump> pump(new base::MessagePumpCFRunLoop());
- main_message_loop.reset(new base::MessageLoop(std::move(pump)));
+ // This is necessary for CoreAnimation layers hosted in the GPU process to
+ // be drawn. See http://crbug.com/312462.
+ std::unique_ptr<base::MessagePump> pump(new base::MessagePumpCFRunLoop());
+ main_message_loop.reset(new base::MessageLoop(std::move(pump)));
#else
- main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO));
+ main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO));
#endif
+ }
base::PlatformThread::SetName("CrGpuMain");