blob: 0b9d501e7b0da03c2bc668944d6b4172c71dae72 [file] [log] [blame]
[email protected]2e3d9e42012-02-14 03:23:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c0fc0942010-01-13 00:55:372// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avi66a07722015-12-25 23:38:125#include <stddef.h>
[email protected]e09cee42010-11-09 01:50:086#include <stdlib.h>
7
mostynb6682b1c42016-04-19 10:17:308#include <memory>
dchengf26eed32016-01-13 10:58:149#include <utility>
10
[email protected]ec4bda62013-06-14 15:51:0311#include "base/lazy_instance.h"
Alexander Timin4f9c35c2018-11-01 20:15:2012#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4313#include "base/metrics/histogram_macros.h"
[email protected]2436a6b2012-04-13 21:08:5114#include "base/rand_util.h"
fdoraye716a902016-07-05 16:05:4915#include "base/run_loop.h"
[email protected]d0ea4782013-06-11 04:58:2416#include "base/strings/string_number_conversions.h"
17#include "base/strings/stringprintf.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0318#include "base/system/sys_info.h"
[email protected]ce072a72010-12-31 20:02:1619#include "base/threading/platform_thread.h"
stanisc61507092017-07-06 16:36:5820#include "base/timer/hi_res_timer_manager.h"
primiano50b7444c2015-01-28 04:17:0021#include "base/trace_event/trace_event.h"
[email protected]c0fc0942010-01-13 00:55:3722#include "build/build_config.h"
Etienne Bergeroneba914212018-09-27 21:26:2023#include "components/tracing/common/tracing_sampler_profiler.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0624#include "components/viz/service/main/viz_main_impl.h"
[email protected]91a2aea2013-07-08 23:14:3925#include "content/common/content_constants_internal.h"
John Abd-El-Malek884291c2017-08-09 06:43:4826#include "content/common/content_switches_internal.h"
Khushala4e236f2018-06-01 03:00:4627#include "content/common/skia_utils.h"
[email protected]7a31f7c2011-03-21 23:22:0428#include "content/gpu/gpu_child_thread.h"
[email protected]623c0bd2011-03-12 01:00:4129#include "content/gpu/gpu_process.h"
[email protected]c9e2cbbb2012-05-12 21:17:2730#include "content/public/common/content_client.h"
31#include "content/public/common/content_switches.h"
32#include "content/public/common/main_function_params.h"
jbaumana19f1df2017-01-18 03:01:1733#include "content/public/common/result_codes.h"
Zhenyao Moc76e9032018-01-19 21:15:4634#include "content/public/gpu/content_gpu_client.h"
[email protected]40c19e722013-11-05 23:51:2435#include "gpu/command_buffer/service/gpu_switches.h"
sadruled395922016-09-07 17:32:5836#include "gpu/config/gpu_driver_bug_list.h"
[email protected]d7b5cc72013-05-23 20:05:0037#include "gpu/config/gpu_info_collector.h"
Jonathan Backer16cc8fd2018-05-31 19:59:2238#include "gpu/config/gpu_preferences.h"
tfarina15525c42015-04-28 19:04:1639#include "gpu/config/gpu_switches.h"
[email protected]40c19e722013-11-05 23:51:2440#include "gpu/config/gpu_util.h"
fsamuelc2774222016-03-24 00:27:1241#include "gpu/ipc/common/gpu_memory_buffer_support.h"
markdittmerd88b8352016-04-08 15:28:4542#include "gpu/ipc/service/gpu_config.h"
sadrul454af332016-09-09 18:14:3243#include "gpu/ipc/service/gpu_init.h"
sadrul2fb7e152016-08-30 05:21:4544#include "gpu/ipc/service/gpu_watchdog_thread.h"
Scott Violeta35f9a42018-03-22 22:00:4445#include "media/gpu/buildflags.h"
Tom Sepeza0950c62017-10-18 20:39:1446#include "third_party/angle/src/gpu_info_util/SystemInfo.h"
[email protected]c0939182014-05-24 00:09:1947#include "ui/events/platform/platform_event_source.h"
skyostilb354f882016-12-13 18:42:4548#include "ui/gfx/switches.h"
martina.kollarovaa34211d2015-06-25 11:49:0749#include "ui/gl/gl_context.h"
[email protected]db6101db2012-10-25 15:20:0850#include "ui/gl/gl_implementation.h"
[email protected]c9e2cbbb2012-05-12 21:17:2751#include "ui/gl/gl_surface.h"
52#include "ui/gl/gl_switches.h"
[email protected]1bb06b02012-09-23 19:37:2453#include "ui/gl/gpu_switching_manager.h"
kylechar5b9dec12016-05-16 15:40:5754#include "ui/gl/init/gl_factory.h"
[email protected]c0fc0942010-01-13 00:55:3755
avi66a07722015-12-25 23:38:1256#if defined(OS_WIN)
avi66a07722015-12-25 23:38:1257#include <windows.h>
fdoraye716a902016-07-05 16:05:4958#include <dwmapi.h>
avi66a07722015-12-25 23:38:1259#endif
60
primianob3fb6412015-10-14 16:03:5161#if defined(OS_ANDROID)
62#include "base/trace_event/memory_dump_manager.h"
primianoccb26c62016-06-01 21:50:0263#include "components/tracing/common/graphics_memory_dump_provider_android.h"
primianob3fb6412015-10-14 16:03:5164#endif
65
[email protected]d7de57872011-12-06 23:32:4366#if defined(OS_WIN)
Daniel Libby8f7e6262019-01-08 22:35:5567#include "base/trace_event/trace_event_etw_export_win.h"
[email protected]5f7e4512012-10-01 20:51:3768#include "base/win/scoped_com_initializer.h"
kylechar5b9dec12016-05-16 15:40:5769#include "base/win/windows_version.h"
Miguel Casasd697adf32018-02-26 19:06:3170#include "media/gpu/windows/dxva_video_decode_accelerator_win.h"
71#include "media/gpu/windows/media_foundation_video_encode_accelerator_win.h"
[email protected]181491782012-07-18 00:59:1572#include "sandbox/win/src/sandbox.h"
[email protected]802a13a02010-12-02 01:48:3773#endif
74
[email protected]02ec37a2010-09-20 22:32:1675#if defined(USE_X11)
kylecharb8d249c2017-12-15 00:04:1876#include "ui/base/x/x11_util.h" // nogncheck
77#include "ui/gfx/x/x11_connection.h" // nogncheck
78#include "ui/gfx/x/x11_switches.h" // nogncheck
[email protected]02ec37a2010-09-20 22:32:1679#endif
80
[email protected]2436a6b2012-04-13 21:08:5181#if defined(OS_LINUX)
Tom Sepez085507ab2017-10-18 22:36:0082#include "content/gpu/gpu_sandbox_hook_linux.h"
[email protected]2436a6b2012-04-13 21:08:5183#include "content/public/common/sandbox_init.h"
Tom Sepez903f7f12017-10-26 17:34:0284#include "services/service_manager/sandbox/linux/sandbox_linux.h"
Jay Civelli668c097f2018-05-16 20:44:1385#include "services/service_manager/zygote/common/common_sandbox_support_linux.h"
[email protected]2436a6b2012-04-13 21:08:5186#endif
87
[email protected]826aab02014-05-14 02:58:5988#if defined(OS_MACOSX)
89#include "base/message_loop/message_pump_mac.h"
Greg Kerr3480aa82018-02-01 00:53:0390#include "sandbox/mac/seatbelt.h"
Tom Sepeze2923d52017-10-12 01:23:5591#include "services/service_manager/sandbox/mac/sandbox_mac.h"
[email protected]826aab02014-05-14 02:58:5992#endif
93
tonikitoofb807b102017-02-08 19:52:0394#if defined(USE_OZONE)
95#include "ui/ozone/public/ozone_platform.h"
96#endif
97
Alexandre Courbotc13a5972017-07-23 03:48:4898#if BUILDFLAG(USE_VAAPI)
Miguel Casas42e955c2017-12-04 14:18:1299#include "media/gpu/vaapi/vaapi_wrapper.h"
hshi95837052015-05-12 15:39:51100#endif
101
Greg Kerr3480aa82018-02-01 00:53:03102#if defined(OS_MACOSX)
103extern "C" {
104void _LSSetApplicationLaunchServicesServerConnectionStatus(
105 uint64_t flags,
106 bool (^connection_allowed)(CFDictionaryRef));
107};
108#endif // defined(OS_MACOSX)
109
[email protected]eb398192012-10-22 20:16:19110namespace content {
[email protected]ec4bda62013-06-14 15:51:03111
[email protected]6ec3a572012-08-17 02:09:51112namespace {
[email protected]ec4bda62013-06-14 15:51:03113
[email protected]663c4b32013-04-18 05:52:54114#if defined(OS_LINUX)
Zhenyao Moe9187a862017-10-20 04:26:33115bool StartSandboxLinux(gpu::GpuWatchdogThread*,
116 const gpu::GPUInfo*,
117 const gpu::GpuPreferences&);
[email protected]663c4b32013-04-18 05:52:54118#elif defined(OS_WIN)
119bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
120#endif
[email protected]ec4bda62013-06-14 15:51:03121
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06122base::LazyInstance<viz::VizMainImpl::LogMessages>::DestructorAtExit
scottmg5e65e3a2017-03-08 08:48:46123 deferred_messages = LAZY_INSTANCE_INITIALIZER;
[email protected]ec4bda62013-06-14 15:51:03124
125bool GpuProcessLogMessageHandler(int severity,
126 const char* file, int line,
127 size_t message_start,
128 const std::string& str) {
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06129 viz::VizMainImpl::LogMessage log;
sadruldb04bc32017-01-04 04:50:30130 log.severity = severity;
131 log.header = str.substr(0, message_start);
132 log.message = str.substr(message_start);
sadrul041ca722017-03-24 22:35:35133 deferred_messages.Get().push_back(std::move(log));
[email protected]ec4bda62013-06-14 15:51:03134 return false;
[email protected]6ec3a572012-08-17 02:09:51135}
136
sadrul454af332016-09-09 18:14:32137class ContentSandboxHelper : public gpu::GpuSandboxHelper {
138 public:
139 ContentSandboxHelper() {}
140 ~ContentSandboxHelper() override {}
141
142#if defined(OS_WIN)
143 void set_sandbox_info(const sandbox::SandboxInterfaceInfo* info) {
144 sandbox_info_ = info;
145 }
146#endif
147
sadrul454af332016-09-09 18:14:32148 private:
149 // SandboxHelper:
150 void PreSandboxStartup() override {
151 // Warm up resources that don't need access to GPUInfo.
152 {
153 TRACE_EVENT0("gpu", "Warm up rand");
154 // Warm up the random subsystem, which needs to be done pre-sandbox on all
155 // platforms.
156 (void)base::RandUint64();
157 }
158
Alexandre Courbotc13a5972017-07-23 03:48:48159#if BUILDFLAG(USE_VAAPI)
sadrul454af332016-09-09 18:14:32160 media::VaapiWrapper::PreSandboxInitialization();
161#endif
162#if defined(OS_WIN)
163 media::DXVAVideoDecodeAccelerator::PreSandboxInitialization();
164 media::MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization();
165#endif
Eric Karle35050e2017-09-07 01:44:35166
167 // On Linux, reading system memory doesn't work through the GPU sandbox.
168 // This value is cached, so access it here to populate the cache.
169 base::SysInfo::AmountOfPhysicalMemory();
sadrul454af332016-09-09 18:14:32170 }
171
Satyajit Sahu82a76e02017-09-18 14:50:14172 bool EnsureSandboxInitialized(gpu::GpuWatchdogThread* watchdog_thread,
Zhenyao Moe9187a862017-10-20 04:26:33173 const gpu::GPUInfo* gpu_info,
174 const gpu::GpuPreferences& gpu_prefs) override {
sadrul454af332016-09-09 18:14:32175#if defined(OS_LINUX)
Zhenyao Moe9187a862017-10-20 04:26:33176 return StartSandboxLinux(watchdog_thread, gpu_info, gpu_prefs);
sadrul454af332016-09-09 18:14:32177#elif defined(OS_WIN)
178 return StartSandboxWindows(sandbox_info_);
179#elif defined(OS_MACOSX)
Greg Kerr3480aa82018-02-01 00:53:03180 return sandbox::Seatbelt::IsSandboxed();
sadrul454af332016-09-09 18:14:32181#else
182 return false;
183#endif
184 }
185
186#if defined(OS_WIN)
187 const sandbox::SandboxInterfaceInfo* sandbox_info_ = nullptr;
sadrul454af332016-09-09 18:14:32188#endif
189
190 DISALLOW_COPY_AND_ASSIGN(ContentSandboxHelper);
191};
192
kylechar476993472016-09-14 16:03:48193} // namespace
[email protected]ec4bda62013-06-14 15:51:03194
[email protected]c0fc0942010-01-13 00:55:37195// Main function for starting the Gpu process.
[email protected]eb398192012-10-22 20:16:19196int GpuMain(const MainFunctionParams& parameters) {
[email protected]d13f35d2012-05-18 02:28:15197 TRACE_EVENT0("gpu", "GpuMain");
Ehsan Chiniforooshana8c8dad2017-11-03 07:23:09198 base::trace_event::TraceLog::GetInstance()->set_process_name("GPU Process");
ssidb2e3ece2015-02-09 16:02:20199 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
[email protected]91a2aea2013-07-08 23:14:39200 kTraceEventGpuProcessSortIndex);
[email protected]d13f35d2012-05-18 02:28:15201
avi83883c82014-12-23 00:08:49202 const base::CommandLine& command_line = parameters.command_line;
Zhenyao Mo910beb82017-10-25 03:23:00203
204 gpu::GpuPreferences gpu_preferences;
205 if (command_line.HasSwitch(switches::kGpuPreferences)) {
206 std::string value =
207 command_line.GetSwitchValueASCII(switches::kGpuPreferences);
Jonathan Backer16cc8fd2018-05-31 19:59:22208 bool success = gpu_preferences.FromSwitchValue(value);
Zhenyao Mo910beb82017-10-25 03:23:00209 CHECK(success);
210 }
211
212 if (gpu_preferences.gpu_startup_dialog)
John Abd-El-Malek884291c2017-08-09 06:43:48213 WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:49214
Daniel Libby8f7e6262019-01-08 22:35:55215#if defined(OS_WIN)
216 if (gpu_preferences.enable_trace_export_events_to_etw)
217 base::trace_event::TraceEventETWExport::EnableETWExport();
218#endif
219
[email protected]ca23992b02013-06-13 17:25:19220 base::Time start_time = base::Time::Now();
221
[email protected]23f46562011-09-07 01:42:39222#if defined(OS_WIN)
[email protected]52819472013-11-24 22:49:55223 // Prevent Windows from displaying a modal dialog on failures like not being
224 // able to load a DLL.
225 SetErrorMode(
226 SEM_FAILCRITICALERRORS |
227 SEM_NOGPFAULTERRORBOX |
228 SEM_NOOPENFILEERRORBOX);
Robert Liao98bb92d2017-06-15 22:20:39229
230 // COM is used by some Windows Media Foundation calls made on this thread and
231 // must be MTA so we don't have to worry about pumping messages to handle
232 // COM callbacks.
233 base::win::ScopedCOMInitializer com_initializer(
234 base::win::ScopedCOMInitializer::kMTA);
[email protected]23f46562011-09-07 01:42:39235#endif
[email protected]ec4bda62013-06-14 15:51:03236
[email protected]52819472013-11-24 22:49:55237 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
[email protected]23f46562011-09-07 01:42:39238
ericrk1d9e17f2016-11-30 01:51:28239 // We are experiencing what appear to be memory-stomp issues in the GPU
240 // process. These issues seem to be impacting the message loop and listeners
241 // registered to it. Create the message loop on the heap to guard against
242 // this.
243 // TODO(ericrk): Revisit this once we assess its impact on crbug.com/662802
244 // and crbug.com/609252.
245 std::unique_ptr<base::MessageLoop> main_message_loop;
skyostil82befc52016-12-19 13:48:59246 std::unique_ptr<ui::PlatformEventSource> event_source;
skyostilb354f882016-12-13 18:42:45247 if (command_line.HasSwitch(switches::kHeadless)) {
248 main_message_loop.reset(
249 new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
250 } else {
[email protected]db6101db2012-10-25 15:20:08251#if defined(OS_WIN)
Robert Liao98bb92d2017-06-15 22:20:39252 // The GpuMain thread should not be pumping Windows messages because no UI
253 // is expected to run on this thread.
skyostilb354f882016-12-13 18:42:45254 main_message_loop.reset(
255 new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
kylechar476993472016-09-14 16:03:48256#elif defined(USE_X11)
kylecharb8d249c2017-12-15 00:04:18257 // Depending on how Chrome is running there are multiple threads that can
258 // make Xlib function calls. Call XInitThreads() here to be safe, even if
259 // some configurations don't strictly need it.
260 gfx::InitializeThreadedX11();
261
skyostilb354f882016-12-13 18:42:45262 // We need a UI loop so that we can grab the Expose events. See GLSurfaceGLX
263 // and https://crbug.com/326995.
thomasandersona8d3f52b2017-04-17 21:57:02264 ui::SetDefaultX11ErrorHandlers();
265 if (!gfx::GetXDisplay())
266 return RESULT_CODE_GPU_DEAD_ON_ARRIVAL;
skyostilb354f882016-12-13 18:42:45267 main_message_loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
skyostil82befc52016-12-19 13:48:59268 event_source = ui::PlatformEventSource::CreateDefault();
kylechar476993472016-09-14 16:03:48269#elif defined(USE_OZONE)
tonikitoofb807b102017-02-08 19:52:03270 // The MessageLoop type required depends on the Ozone platform selected at
271 // runtime.
272 main_message_loop.reset(new base::MessageLoop(
273 ui::OzonePlatform::EnsureInstance()->GetMessageLoopTypeForGpu()));
kylechar476993472016-09-14 16:03:48274#elif defined(OS_LINUX)
275#error "Unsupported Linux platform."
[email protected]826aab02014-05-14 02:58:59276#elif defined(OS_MACOSX)
Christopher Cameron1732f2b02017-11-17 10:56:50277 // Cross-process CoreAnimation requires a CFRunLoop to function at all, and
278 // requires a NSRunLoop to not starve under heavy load. See:
279 // https://crbug.com/312462#c51 and https://crbug.com/783298
280 std::unique_ptr<base::MessagePump> pump(new base::MessagePumpNSRunLoop());
skyostilb354f882016-12-13 18:42:45281 main_message_loop.reset(new base::MessageLoop(std::move(pump)));
Greg Kerr3480aa82018-02-01 00:53:03282
283 // Tell LaunchServices to continue without a connection to the daemon.
284 _LSSetApplicationLaunchServicesServerConnectionStatus(0, nullptr);
[email protected]826aab02014-05-14 02:58:59285#else
boliu754c8112016-12-16 23:40:59286 main_message_loop.reset(
287 new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
[email protected]db6101db2012-10-25 15:20:08288#endif
skyostilb354f882016-12-13 18:42:45289 }
[email protected]db6101db2012-10-25 15:20:08290
[email protected]db6101db2012-10-25 15:20:08291 base::PlatformThread::SetName("CrGpuMain");
292
revemane7acf842016-02-05 08:24:32293#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
294 // Set thread priority before sandbox initialization.
295 base::PlatformThread::SetCurrentThreadPriority(base::ThreadPriority::DISPLAY);
296#endif
297
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57298 auto gpu_init = std::make_unique<gpu::GpuInit>();
sadrul454af332016-09-09 18:14:32299 ContentSandboxHelper sandbox_helper;
300#if defined(OS_WIN)
301 sandbox_helper.set_sandbox_info(parameters.sandbox_info);
[email protected]af7c5d92014-02-03 19:53:15302#endif
[email protected]af7c5d92014-02-03 19:53:15303
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57304 gpu_init->set_sandbox_helper(&sandbox_helper);
Sadrul Habib Chowdhuryc0a4a9b92016-08-29 21:43:24305
Khushal1d055592018-07-28 02:00:39306 // Since GPU initialization calls into skia, its important to initialize skia
307 // before it.
308 InitializeSkia();
309
sadrul454af332016-09-09 18:14:32310 // Gpu initialization may fail for various reasons, in which case we will need
311 // to tear down this process. However, we can not do so safely until the IPC
312 // channel is set up, because the detection of early return of a child process
313 // is implemented using an IPC channel error. If the IPC channel is not fully
314 // set up between the browser and GPU process, and the GPU process crashes or
315 // exits early, the browser process will never detect it. For this reason we
sadrul72aae8a2017-01-24 04:52:32316 // defer tearing down the GPU process until receiving the initialization
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06317 // message from the browser (through mojom::VizMain::CreateGpuService()).
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57318 const bool init_success = gpu_init->InitializeAndStartSandbox(
Zhenyao Moe23f75262018-02-07 02:15:00319 const_cast<base::CommandLine*>(&command_line), gpu_preferences);
sadrul454af332016-09-09 18:14:32320 const bool dead_on_arrival = !init_success;
Sadrul Habib Chowdhuryc0a4a9b92016-08-29 21:43:24321
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28322 logging::SetLogMessageHandler(nullptr);
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57323 GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
[email protected]ec4bda62013-06-14 15:51:03324
reveman7caf8cf2016-02-16 02:39:05325 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL;
326#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
327 io_thread_priority = base::ThreadPriority::DISPLAY;
328#endif
329
330 GpuProcess gpu_process(io_thread_priority);
Xi Chengd6390812018-01-24 00:01:50331
Zhenyao Moe23f75262018-02-07 02:15:00332 auto* client = GetContentClient()->gpu();
Xi Chengd6390812018-01-24 00:01:50333 if (client)
334 client->PostIOThreadCreated(gpu_process.io_task_runner());
335
Wez6979109b2018-09-07 17:30:56336 base::RunLoop run_loop;
337 GpuChildThread* child_thread =
338 new GpuChildThread(run_loop.QuitClosure(), std::move(gpu_init),
339 std::move(deferred_messages.Get()));
sadrul041ca722017-03-24 22:35:35340 deferred_messages.Get().clear();
[email protected]8fe0ec522011-03-03 00:31:33341
[email protected]7a31f7c2011-03-21 23:22:04342 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:17343
[email protected]7a31f7c2011-03-21 23:22:04344 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:44345
Etienne Bergeroneba914212018-09-27 21:26:20346 // Setup tracing sampler profiler as early as possible.
Siddhartha017e49f2018-11-15 22:27:45347 std::unique_ptr<tracing::TracingSamplerProfiler> tracing_sampler_profiler =
348 tracing::TracingSamplerProfiler::CreateOnMainThread();
Etienne Bergeroneba914212018-09-27 21:26:20349
primianob3fb6412015-10-14 16:03:51350#if defined(OS_ANDROID)
351 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
primiano186d6bfe2015-10-30 13:21:40352 tracing::GraphicsMemoryDumpProvider::GetInstance(), "AndroidGraphics",
353 nullptr);
primianob3fb6412015-10-14 16:03:51354#endif
355
stanisc61507092017-07-06 16:36:58356 base::HighResolutionTimerManager hi_res_timer_manager;
357
[email protected]d13f35d2012-05-18 02:28:15358 {
359 TRACE_EVENT0("gpu", "Run Message Loop");
Wez6979109b2018-09-07 17:30:56360 run_loop.Run();
[email protected]d13f35d2012-05-18 02:28:15361 }
[email protected]c0fc0942010-01-13 00:55:37362
jbaumana19f1df2017-01-18 03:01:17363 return dead_on_arrival ? RESULT_CODE_GPU_DEAD_ON_ARRIVAL : 0;
[email protected]c0fc0942010-01-13 00:55:37364}
[email protected]6ec3a572012-08-17 02:09:51365
366namespace {
367
[email protected]59a7ae4e2012-10-01 23:54:44368#if defined(OS_LINUX)
Satyajit Sahu82a76e02017-09-18 14:50:14369bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdog_thread,
Zhenyao Moe9187a862017-10-20 04:26:33370 const gpu::GPUInfo* gpu_info,
371 const gpu::GpuPreferences& gpu_prefs) {
fdorayf30bf3a2015-10-28 21:47:00372 TRACE_EVENT0("gpu,startup", "Initialize sandbox");
[email protected]663c4b32013-04-18 05:52:54373
[email protected]f330b762014-02-08 04:52:46374 if (watchdog_thread) {
Tom Sepez437e2202017-10-24 21:26:47375 // SandboxLinux needs to be able to ensure that the thread
[email protected]f330b762014-02-08 04:52:46376 // has really been stopped.
Tom Sepeza2cba0062017-11-07 17:22:43377 service_manager::SandboxLinux::GetInstance()->StopThread(watchdog_thread);
[email protected]f330b762014-02-08 04:52:46378 }
[email protected]655abd522014-06-02 15:23:43379
Tom Sepez437e2202017-10-24 21:26:47380 // SandboxLinux::InitializeSandbox() must always be called
[email protected]663c4b32013-04-18 05:52:54381 // with only one thread.
Tom Sepeza2cba0062017-11-07 17:22:43382 service_manager::SandboxLinux::Options sandbox_options;
Tom Sepeza0950c62017-10-18 20:39:14383 sandbox_options.use_amd_specific_policies =
384 gpu_info && angle::IsAMD(gpu_info->active_gpu().vendor_id);
Zhenyao Moe9187a862017-10-20 04:26:33385 sandbox_options.accelerated_video_decode_enabled =
386 !gpu_prefs.disable_accelerated_video_decode;
Sheng-Hao Tsaoea6aa852018-01-03 06:48:16387 sandbox_options.accelerated_video_encode_enabled =
388 !gpu_prefs.disable_accelerated_video_encode;
Tom Sepez085507ab2017-10-18 22:36:00389
Tom Sepeza2cba0062017-11-07 17:22:43390 bool res = service_manager::SandboxLinux::GetInstance()->InitializeSandbox(
Tom Sepez2255db72017-10-26 18:50:09391 service_manager::SandboxTypeFromCommandLine(
392 *base::CommandLine::ForCurrentProcess()),
Tom Sepez4b101712017-11-08 19:39:58393 base::BindOnce(GpuProcessPreSandboxHook), sandbox_options);
Tom Sepeza0950c62017-10-18 20:39:14394
[email protected]f330b762014-02-08 04:52:46395 if (watchdog_thread) {
Tom Sepeza0950c62017-10-18 20:39:14396 base::Thread::Options thread_options;
397 thread_options.timer_slack = base::TIMER_SLACK_MAXIMUM;
398 watchdog_thread->StartWithOptions(thread_options);
[email protected]f330b762014-02-08 04:52:46399 }
[email protected]663c4b32013-04-18 05:52:54400
401 return res;
402}
403#endif // defined(OS_LINUX)
404
405#if defined(OS_WIN)
406bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) {
fdorayf30bf3a2015-10-28 21:47:00407 TRACE_EVENT0("gpu,startup", "Lower token");
[email protected]663c4b32013-04-18 05:52:54408
409 // For Windows, if the target_services interface is not zero, the process
410 // is sandboxed and we must call LowerToken() before rendering untrusted
411 // content.
412 sandbox::TargetServices* target_services = sandbox_info->target_services;
413 if (target_services) {
414 target_services->LowerToken();
415 return true;
416 }
417
418 return false;
419}
420#endif // defined(OS_WIN)
421
[email protected]6ec3a572012-08-17 02:09:51422} // namespace.
423
[email protected]eb398192012-10-22 20:16:19424} // namespace content