blob: de80e1023c948a347440eeb960079f498e43fb87 [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
Sebastien Marchandf8cbfab2019-01-25 16:02:3011#include "base/bind.h"
Sunny Sachanandani5cd10e962019-06-13 22:55:3212#include "base/feature_list.h"
[email protected]ec4bda62013-06-14 15:51:0313#include "base/lazy_instance.h"
asvitkine8d51e9d2016-09-02 23:55:4314#include "base/metrics/histogram_macros.h"
[email protected]2436a6b2012-04-13 21:08:5115#include "base/rand_util.h"
fdoraye716a902016-07-05 16:05:4916#include "base/run_loop.h"
[email protected]d0ea4782013-06-11 04:58:2417#include "base/strings/string_number_conversions.h"
18#include "base/strings/stringprintf.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0319#include "base/system/sys_info.h"
Alex Clarke636e7052019-05-30 10:49:3720#include "base/task/single_thread_task_executor.h"
[email protected]ce072a72010-12-31 20:02:1621#include "base/threading/platform_thread.h"
stanisc61507092017-07-06 16:36:5822#include "base/timer/hi_res_timer_manager.h"
primiano50b7444c2015-01-28 04:17:0023#include "base/trace_event/trace_event.h"
[email protected]c0fc0942010-01-13 00:55:3724#include "build/build_config.h"
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0625#include "components/viz/service/main/viz_main_impl.h"
[email protected]91a2aea2013-07-08 23:14:3926#include "content/common/content_constants_internal.h"
John Abd-El-Malek884291c2017-08-09 06:43:4827#include "content/common/content_switches_internal.h"
Khushala4e236f2018-06-01 03:00:4628#include "content/common/skia_utils.h"
[email protected]7a31f7c2011-03-21 23:22:0429#include "content/gpu/gpu_child_thread.h"
[email protected]623c0bd2011-03-12 01:00:4130#include "content/gpu/gpu_process.h"
[email protected]c9e2cbbb2012-05-12 21:17:2731#include "content/public/common/content_client.h"
32#include "content/public/common/content_switches.h"
33#include "content/public/common/main_function_params.h"
jbaumana19f1df2017-01-18 03:01:1734#include "content/public/common/result_codes.h"
Zhenyao Moc76e9032018-01-19 21:15:4635#include "content/public/gpu/content_gpu_client.h"
[email protected]40c19e722013-11-05 23:51:2436#include "gpu/command_buffer/service/gpu_switches.h"
sadruled395922016-09-07 17:32:5837#include "gpu/config/gpu_driver_bug_list.h"
Sunny Sachanandani5cd10e962019-06-13 22:55:3238#include "gpu/config/gpu_finch_features.h"
[email protected]d7b5cc72013-05-23 20:05:0039#include "gpu/config/gpu_info_collector.h"
Jonathan Backer16cc8fd2018-05-31 19:59:2240#include "gpu/config/gpu_preferences.h"
tfarina15525c42015-04-28 19:04:1641#include "gpu/config/gpu_switches.h"
[email protected]40c19e722013-11-05 23:51:2442#include "gpu/config/gpu_util.h"
fsamuelc2774222016-03-24 00:27:1243#include "gpu/ipc/common/gpu_memory_buffer_support.h"
markdittmerd88b8352016-04-08 15:28:4544#include "gpu/ipc/service/gpu_config.h"
sadrul454af3332016-09-09 18:14:3245#include "gpu/ipc/service/gpu_init.h"
sadrul2fb7e152016-08-30 05:21:4546#include "gpu/ipc/service/gpu_watchdog_thread.h"
Scott Violeta35f9a42018-03-22 22:00:4447#include "media/gpu/buildflags.h"
Oystein Eftevaag424fd372019-06-07 17:51:0348#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
Tom Sepeza0950c62017-10-18 20:39:1449#include "third_party/angle/src/gpu_info_util/SystemInfo.h"
[email protected]c0939182014-05-24 00:09:1950#include "ui/events/platform/platform_event_source.h"
skyostilb354f882016-12-13 18:42:4551#include "ui/gfx/switches.h"
martina.kollarovaa34211d2015-06-25 11:49:0752#include "ui/gl/gl_context.h"
[email protected]db6101db2012-10-25 15:20:0853#include "ui/gl/gl_implementation.h"
[email protected]c9e2cbbb2012-05-12 21:17:2754#include "ui/gl/gl_surface.h"
55#include "ui/gl/gl_switches.h"
[email protected]1bb06b02012-09-23 19:37:2456#include "ui/gl/gpu_switching_manager.h"
kylechar5b9dec12016-05-16 15:40:5757#include "ui/gl/init/gl_factory.h"
[email protected]c0fc0942010-01-13 00:55:3758
avi66a07722015-12-25 23:38:1259#if defined(OS_WIN)
avi66a07722015-12-25 23:38:1260#include <windows.h>
fdoraye716a902016-07-05 16:05:4961#include <dwmapi.h>
avi66a07722015-12-25 23:38:1262#endif
63
primianob3fb6412015-10-14 16:03:5164#if defined(OS_ANDROID)
65#include "base/trace_event/memory_dump_manager.h"
primianoccb26c62016-06-01 21:50:0266#include "components/tracing/common/graphics_memory_dump_provider_android.h"
primianob3fb6412015-10-14 16:03:5167#endif
68
[email protected]d7de57872011-12-06 23:32:4369#if defined(OS_WIN)
Daniel Libby8f7e6262019-01-08 22:35:5570#include "base/trace_event/trace_event_etw_export_win.h"
[email protected]5f7e4512012-10-01 20:51:3771#include "base/win/scoped_com_initializer.h"
kylechar5b9dec12016-05-16 15:40:5772#include "base/win/windows_version.h"
Miguel Casasd697adf32018-02-26 19:06:3173#include "media/gpu/windows/dxva_video_decode_accelerator_win.h"
74#include "media/gpu/windows/media_foundation_video_encode_accelerator_win.h"
[email protected]181491782012-07-18 00:59:1575#include "sandbox/win/src/sandbox.h"
[email protected]802a13a02010-12-02 01:48:3776#endif
77
[email protected]02ec37a2010-09-20 22:32:1678#if defined(USE_X11)
kylecharb8d249c2017-12-15 00:04:1879#include "ui/base/x/x11_util.h" // nogncheck
80#include "ui/gfx/x/x11_connection.h" // nogncheck
81#include "ui/gfx/x/x11_switches.h" // nogncheck
[email protected]02ec37a2010-09-20 22:32:1682#endif
83
[email protected]2436a6b2012-04-13 21:08:5184#if defined(OS_LINUX)
Tom Sepez085507ab2017-10-18 22:36:0085#include "content/gpu/gpu_sandbox_hook_linux.h"
[email protected]2436a6b2012-04-13 21:08:5186#include "content/public/common/sandbox_init.h"
Tom Sepez903f7f12017-10-26 17:34:0287#include "services/service_manager/sandbox/linux/sandbox_linux.h"
Jay Civelli668c097f2018-05-16 20:44:1388#include "services/service_manager/zygote/common/common_sandbox_support_linux.h"
[email protected]2436a6b2012-04-13 21:08:5189#endif
90
[email protected]826aab02014-05-14 02:58:5991#if defined(OS_MACOSX)
92#include "base/message_loop/message_pump_mac.h"
Greg Kerr3480aa82018-02-01 00:53:0393#include "sandbox/mac/seatbelt.h"
Tom Sepeze2923d52017-10-12 01:23:5594#include "services/service_manager/sandbox/mac/sandbox_mac.h"
[email protected]826aab02014-05-14 02:58:5995#endif
96
Alexandre Courbotc13a5972017-07-23 03:48:4897#if BUILDFLAG(USE_VAAPI)
Miguel Casas42e955c2017-12-04 14:18:1298#include "media/gpu/vaapi/vaapi_wrapper.h"
hshi95837052015-05-12 15:39:5199#endif
100
Greg Kerr3480aa82018-02-01 00:53:03101#if defined(OS_MACOSX)
102extern "C" {
103void _LSSetApplicationLaunchServicesServerConnectionStatus(
104 uint64_t flags,
105 bool (^connection_allowed)(CFDictionaryRef));
Nico Webere86ed9b32019-02-22 18:11:12106}
Greg Kerr3480aa82018-02-01 00:53:03107#endif // defined(OS_MACOSX)
108
[email protected]eb398192012-10-22 20:16:19109namespace content {
[email protected]ec4bda62013-06-14 15:51:03110
[email protected]6ec3a572012-08-17 02:09:51111namespace {
[email protected]ec4bda62013-06-14 15:51:03112
[email protected]663c4b32013-04-18 05:52:54113#if defined(OS_LINUX)
Zhenyao Moe9187a862017-10-20 04:26:33114bool StartSandboxLinux(gpu::GpuWatchdogThread*,
115 const gpu::GPUInfo*,
116 const gpu::GpuPreferences&);
[email protected]663c4b32013-04-18 05:52:54117#elif defined(OS_WIN)
118bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
119#endif
[email protected]ec4bda62013-06-14 15:51:03120
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06121base::LazyInstance<viz::VizMainImpl::LogMessages>::DestructorAtExit
scottmg5e65e3a2017-03-08 08:48:46122 deferred_messages = LAZY_INSTANCE_INITIALIZER;
[email protected]ec4bda62013-06-14 15:51:03123
124bool GpuProcessLogMessageHandler(int severity,
125 const char* file, int line,
126 size_t message_start,
127 const std::string& str) {
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06128 viz::VizMainImpl::LogMessage log;
sadruldb04bc32017-01-04 04:50:30129 log.severity = severity;
130 log.header = str.substr(0, message_start);
131 log.message = str.substr(message_start);
sadrul041ca722017-03-24 22:35:35132 deferred_messages.Get().push_back(std::move(log));
[email protected]ec4bda62013-06-14 15:51:03133 return false;
[email protected]6ec3a572012-08-17 02:09:51134}
135
sadrul454af3332016-09-09 18:14:32136class ContentSandboxHelper : public gpu::GpuSandboxHelper {
137 public:
138 ContentSandboxHelper() {}
139 ~ContentSandboxHelper() override {}
140
141#if defined(OS_WIN)
142 void set_sandbox_info(const sandbox::SandboxInterfaceInfo* info) {
143 sandbox_info_ = info;
144 }
145#endif
146
sadrul454af3332016-09-09 18:14:32147 private:
148 // SandboxHelper:
149 void PreSandboxStartup() override {
150 // Warm up resources that don't need access to GPUInfo.
151 {
152 TRACE_EVENT0("gpu", "Warm up rand");
153 // Warm up the random subsystem, which needs to be done pre-sandbox on all
154 // platforms.
155 (void)base::RandUint64();
156 }
157
Alexandre Courbotc13a5972017-07-23 03:48:48158#if BUILDFLAG(USE_VAAPI)
sadrul454af3332016-09-09 18:14:32159 media::VaapiWrapper::PreSandboxInitialization();
160#endif
161#if defined(OS_WIN)
162 media::DXVAVideoDecodeAccelerator::PreSandboxInitialization();
163 media::MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization();
164#endif
Eric Karle35050e2017-09-07 01:44:35165
166 // On Linux, reading system memory doesn't work through the GPU sandbox.
167 // This value is cached, so access it here to populate the cache.
168 base::SysInfo::AmountOfPhysicalMemory();
sadrul454af3332016-09-09 18:14:32169 }
170
Satyajit Sahu82a76e02017-09-18 14:50:14171 bool EnsureSandboxInitialized(gpu::GpuWatchdogThread* watchdog_thread,
Zhenyao Moe9187a862017-10-20 04:26:33172 const gpu::GPUInfo* gpu_info,
173 const gpu::GpuPreferences& gpu_prefs) override {
sadrul454af3332016-09-09 18:14:32174#if defined(OS_LINUX)
Zhenyao Moe9187a862017-10-20 04:26:33175 return StartSandboxLinux(watchdog_thread, gpu_info, gpu_prefs);
sadrul454af3332016-09-09 18:14:32176#elif defined(OS_WIN)
177 return StartSandboxWindows(sandbox_info_);
178#elif defined(OS_MACOSX)
Greg Kerr3480aa82018-02-01 00:53:03179 return sandbox::Seatbelt::IsSandboxed();
sadrul454af3332016-09-09 18:14:32180#else
181 return false;
182#endif
183 }
184
185#if defined(OS_WIN)
186 const sandbox::SandboxInterfaceInfo* sandbox_info_ = nullptr;
sadrul454af3332016-09-09 18:14:32187#endif
188
189 DISALLOW_COPY_AND_ASSIGN(ContentSandboxHelper);
190};
191
kylechar476993472016-09-14 16:03:48192} // namespace
[email protected]ec4bda62013-06-14 15:51:03193
[email protected]c0fc0942010-01-13 00:55:37194// Main function for starting the Gpu process.
[email protected]eb398192012-10-22 20:16:19195int GpuMain(const MainFunctionParams& parameters) {
[email protected]d13f35d2012-05-18 02:28:15196 TRACE_EVENT0("gpu", "GpuMain");
Ehsan Chiniforooshana8c8dad2017-11-03 07:23:09197 base::trace_event::TraceLog::GetInstance()->set_process_name("GPU Process");
ssidb2e3ece2015-02-09 16:02:20198 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
[email protected]91a2aea2013-07-08 23:14:39199 kTraceEventGpuProcessSortIndex);
[email protected]d13f35d2012-05-18 02:28:15200
avi83883c82014-12-23 00:08:49201 const base::CommandLine& command_line = parameters.command_line;
Zhenyao Mo910beb82017-10-25 03:23:00202
203 gpu::GpuPreferences gpu_preferences;
204 if (command_line.HasSwitch(switches::kGpuPreferences)) {
205 std::string value =
206 command_line.GetSwitchValueASCII(switches::kGpuPreferences);
Jonathan Backer16cc8fd2018-05-31 19:59:22207 bool success = gpu_preferences.FromSwitchValue(value);
Zhenyao Mo910beb82017-10-25 03:23:00208 CHECK(success);
209 }
210
211 if (gpu_preferences.gpu_startup_dialog)
John Abd-El-Malek884291c2017-08-09 06:43:48212 WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:49213
[email protected]ca23992b02013-06-13 17:25:19214 base::Time start_time = base::Time::Now();
215
[email protected]23f46562011-09-07 01:42:39216#if defined(OS_WIN)
Daniel Libby1700bbe82019-01-30 22:22:36217 base::trace_event::TraceEventETWExport::EnableETWExport();
218
[email protected]52819472013-11-24 22:49:55219 // Prevent Windows from displaying a modal dialog on failures like not being
220 // able to load a DLL.
221 SetErrorMode(
222 SEM_FAILCRITICALERRORS |
223 SEM_NOGPFAULTERRORBOX |
224 SEM_NOOPENFILEERRORBOX);
Robert Liao98bb92d2017-06-15 22:20:39225
226 // COM is used by some Windows Media Foundation calls made on this thread and
227 // must be MTA so we don't have to worry about pumping messages to handle
228 // COM callbacks.
229 base::win::ScopedCOMInitializer com_initializer(
230 base::win::ScopedCOMInitializer::kMTA);
Sunny Sachanandani35c727c2019-07-09 13:12:52231
232 if (base::FeatureList::IsEnabled(features::kGpuProcessHighPriorityWin))
Sunny Sachanandani49bdbad2019-07-17 19:15:10233 ::SetPriorityClass(::GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
[email protected]23f46562011-09-07 01:42:39234#endif
[email protected]ec4bda62013-06-14 15:51:03235
[email protected]52819472013-11-24 22:49:55236 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
[email protected]23f46562011-09-07 01:42:39237
ericrk1d9e17f2016-11-30 01:51:28238 // We are experiencing what appear to be memory-stomp issues in the GPU
Alex Clarkef7fb8a82019-06-06 15:41:53239 // process. These issues seem to be impacting the task executor and listeners
240 // registered to it. Create the task executor on the heap to guard against
ericrk1d9e17f2016-11-30 01:51:28241 // this.
242 // TODO(ericrk): Revisit this once we assess its impact on crbug.com/662802
243 // and crbug.com/609252.
Alex Clarke636e7052019-05-30 10:49:37244 std::unique_ptr<base::SingleThreadTaskExecutor> main_thread_task_executor;
skyostil82befc52016-12-19 13:48:59245 std::unique_ptr<ui::PlatformEventSource> event_source;
skyostilb354f882016-12-13 18:42:45246 if (command_line.HasSwitch(switches::kHeadless)) {
Alex Clarke636e7052019-05-30 10:49:37247 main_thread_task_executor =
248 std::make_unique<base::SingleThreadTaskExecutor>(
249 base::MessagePump::Type::DEFAULT);
skyostilb354f882016-12-13 18:42:45250 } 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.
Alex Clarke636e7052019-05-30 10:49:37254 main_thread_task_executor =
255 std::make_unique<base::SingleThreadTaskExecutor>(
256 base::MessagePump::Type::DEFAULT);
kylechar476993472016-09-14 16:03:48257#elif defined(USE_X11)
kylecharb8d249c2017-12-15 00:04:18258 // Depending on how Chrome is running there are multiple threads that can
259 // make Xlib function calls. Call XInitThreads() here to be safe, even if
260 // some configurations don't strictly need it.
261 gfx::InitializeThreadedX11();
262
skyostilb354f882016-12-13 18:42:45263 // We need a UI loop so that we can grab the Expose events. See GLSurfaceGLX
264 // and https://crbug.com/326995.
thomasandersona8d3f52b2017-04-17 21:57:02265 ui::SetDefaultX11ErrorHandlers();
266 if (!gfx::GetXDisplay())
267 return RESULT_CODE_GPU_DEAD_ON_ARRIVAL;
Alex Clarke636e7052019-05-30 10:49:37268 main_thread_task_executor =
269 std::make_unique<base::SingleThreadTaskExecutor>(
270 base::MessagePump::Type::UI);
skyostil82befc52016-12-19 13:48:59271 event_source = ui::PlatformEventSource::CreateDefault();
kylechar476993472016-09-14 16:03:48272#elif defined(USE_OZONE)
Alex Clarke636e7052019-05-30 10:49:37273 // The MessagePump type required depends on the Ozone platform selected at
tonikitoofb807b102017-02-08 19:52:03274 // runtime.
Mohsen Izadid66900e2019-07-16 13:50:15275 main_thread_task_executor =
276 std::make_unique<base::SingleThreadTaskExecutor>(
277 gpu_preferences.message_loop_type);
kylechar476993472016-09-14 16:03:48278#elif defined(OS_LINUX)
279#error "Unsupported Linux platform."
[email protected]826aab02014-05-14 02:58:59280#elif defined(OS_MACOSX)
Christopher Cameron1732f2b02017-11-17 10:56:50281 // Cross-process CoreAnimation requires a CFRunLoop to function at all, and
282 // requires a NSRunLoop to not starve under heavy load. See:
283 // https://crbug.com/312462#c51 and https://crbug.com/783298
Alex Clarke636e7052019-05-30 10:49:37284 main_thread_task_executor =
285 std::make_unique<base::SingleThreadTaskExecutor>(
286 base::MessagePump::Type::NS_RUNLOOP);
Greg Kerr3480aa82018-02-01 00:53:03287
288 // Tell LaunchServices to continue without a connection to the daemon.
289 _LSSetApplicationLaunchServicesServerConnectionStatus(0, nullptr);
[email protected]826aab02014-05-14 02:58:59290#else
Alex Clarke636e7052019-05-30 10:49:37291 main_thread_task_executor =
292 std::make_unique<base::SingleThreadTaskExecutor>(
293 base::MessagePump::Type::DEFAULT);
[email protected]db6101db2012-10-25 15:20:08294#endif
skyostilb354f882016-12-13 18:42:45295 }
[email protected]db6101db2012-10-25 15:20:08296
[email protected]db6101db2012-10-25 15:20:08297 base::PlatformThread::SetName("CrGpuMain");
298
Michael Spang50ed1ff2019-07-02 22:26:56299#if !defined(OS_MACOSX)
Sunny Sachanandani5cd10e962019-06-13 22:55:32300 if (base::FeatureList::IsEnabled(features::kGpuUseDisplayThreadPriority)) {
301 // Set thread priority before sandbox initialization.
302 base::PlatformThread::SetCurrentThreadPriority(
303 base::ThreadPriority::DISPLAY);
304 }
Michael Spang50ed1ff2019-07-02 22:26:56305#endif
revemane7acf842016-02-05 08:24:32306
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57307 auto gpu_init = std::make_unique<gpu::GpuInit>();
sadrul454af3332016-09-09 18:14:32308 ContentSandboxHelper sandbox_helper;
309#if defined(OS_WIN)
310 sandbox_helper.set_sandbox_info(parameters.sandbox_info);
[email protected]af7c5d92014-02-03 19:53:15311#endif
[email protected]af7c5d92014-02-03 19:53:15312
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57313 gpu_init->set_sandbox_helper(&sandbox_helper);
Sadrul Habib Chowdhuryc0a4a9b92016-08-29 21:43:24314
Khushal1d055592018-07-28 02:00:39315 // Since GPU initialization calls into skia, its important to initialize skia
316 // before it.
317 InitializeSkia();
318
sadrul454af3332016-09-09 18:14:32319 // Gpu initialization may fail for various reasons, in which case we will need
320 // to tear down this process. However, we can not do so safely until the IPC
321 // channel is set up, because the detection of early return of a child process
322 // is implemented using an IPC channel error. If the IPC channel is not fully
323 // set up between the browser and GPU process, and the GPU process crashes or
324 // exits early, the browser process will never detect it. For this reason we
sadrul72aae8a2017-01-24 04:52:32325 // defer tearing down the GPU process until receiving the initialization
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06326 // message from the browser (through mojom::VizMain::CreateGpuService()).
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57327 const bool init_success = gpu_init->InitializeAndStartSandbox(
Zhenyao Moe23f75262018-02-07 02:15:00328 const_cast<base::CommandLine*>(&command_line), gpu_preferences);
sadrul454af3332016-09-09 18:14:32329 const bool dead_on_arrival = !init_success;
Sadrul Habib Chowdhuryc0a4a9b92016-08-29 21:43:24330
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28331 logging::SetLogMessageHandler(nullptr);
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:57332 GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
[email protected]ec4bda62013-06-14 15:51:03333
Sunny Sachanandani5cd10e962019-06-13 22:55:32334 const base::ThreadPriority io_thread_priority =
335 base::FeatureList::IsEnabled(features::kGpuUseDisplayThreadPriority)
336 ? base::ThreadPriority::DISPLAY
337 : base::ThreadPriority::NORMAL;
behdad8b57eaad2019-07-18 13:58:48338#if defined(OS_MACOSX)
339 // Increase the thread priority to get more reliable values in performance
340 // test of mac_os.
341 GpuProcess gpu_process(
342 (command_line.HasSwitch(switches::kUseHighGPUThreadPriorityForPerfTests)
343 ? base::ThreadPriority::REALTIME_AUDIO
344 : io_thread_priority));
345#else
reveman7caf8cf2016-02-16 02:39:05346 GpuProcess gpu_process(io_thread_priority);
behdad8b57eaad2019-07-18 13:58:48347#endif
Xi Chengd6390812018-01-24 00:01:50348
Zhenyao Moe23f75262018-02-07 02:15:00349 auto* client = GetContentClient()->gpu();
Xi Chengd6390812018-01-24 00:01:50350 if (client)
351 client->PostIOThreadCreated(gpu_process.io_task_runner());
352
Wez6979109b2018-09-07 17:30:56353 base::RunLoop run_loop;
354 GpuChildThread* child_thread =
355 new GpuChildThread(run_loop.QuitClosure(), std::move(gpu_init),
356 std::move(deferred_messages.Get()));
sadrul041ca722017-03-24 22:35:35357 deferred_messages.Get().clear();
[email protected]8fe0ec522011-03-03 00:31:33358
[email protected]7a31f7c2011-03-21 23:22:04359 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:17360
[email protected]7a31f7c2011-03-21 23:22:04361 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:44362
Etienne Bergeroneba914212018-09-27 21:26:20363 // Setup tracing sampler profiler as early as possible.
Oystein Eftevaag71022d602019-07-12 02:41:29364 tracing::TracingSamplerProfiler::CreateForCurrentThread();
Etienne Bergeroneba914212018-09-27 21:26:20365
primianob3fb6412015-10-14 16:03:51366#if defined(OS_ANDROID)
367 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
primiano186d6bfe2015-10-30 13:21:40368 tracing::GraphicsMemoryDumpProvider::GetInstance(), "AndroidGraphics",
369 nullptr);
primianob3fb6412015-10-14 16:03:51370#endif
371
stanisc61507092017-07-06 16:36:58372 base::HighResolutionTimerManager hi_res_timer_manager;
373
[email protected]d13f35d2012-05-18 02:28:15374 {
375 TRACE_EVENT0("gpu", "Run Message Loop");
Wez6979109b2018-09-07 17:30:56376 run_loop.Run();
[email protected]d13f35d2012-05-18 02:28:15377 }
[email protected]c0fc0942010-01-13 00:55:37378
jbaumana19f1df2017-01-18 03:01:17379 return dead_on_arrival ? RESULT_CODE_GPU_DEAD_ON_ARRIVAL : 0;
[email protected]c0fc0942010-01-13 00:55:37380}
[email protected]6ec3a572012-08-17 02:09:51381
382namespace {
383
[email protected]59a7ae4e2012-10-01 23:54:44384#if defined(OS_LINUX)
Satyajit Sahu82a76e02017-09-18 14:50:14385bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdog_thread,
Zhenyao Moe9187a862017-10-20 04:26:33386 const gpu::GPUInfo* gpu_info,
387 const gpu::GpuPreferences& gpu_prefs) {
fdorayf30bf3a2015-10-28 21:47:00388 TRACE_EVENT0("gpu,startup", "Initialize sandbox");
[email protected]663c4b32013-04-18 05:52:54389
[email protected]f330b762014-02-08 04:52:46390 if (watchdog_thread) {
Tom Sepez437e2202017-10-24 21:26:47391 // SandboxLinux needs to be able to ensure that the thread
[email protected]f330b762014-02-08 04:52:46392 // has really been stopped.
Tom Sepeza2cba0062017-11-07 17:22:43393 service_manager::SandboxLinux::GetInstance()->StopThread(watchdog_thread);
[email protected]f330b762014-02-08 04:52:46394 }
[email protected]655abd522014-06-02 15:23:43395
Tom Sepez437e2202017-10-24 21:26:47396 // SandboxLinux::InitializeSandbox() must always be called
[email protected]663c4b32013-04-18 05:52:54397 // with only one thread.
Tom Sepeza2cba0062017-11-07 17:22:43398 service_manager::SandboxLinux::Options sandbox_options;
Tom Sepeza0950c62017-10-18 20:39:14399 sandbox_options.use_amd_specific_policies =
400 gpu_info && angle::IsAMD(gpu_info->active_gpu().vendor_id);
Zhenyao Moe9187a862017-10-20 04:26:33401 sandbox_options.accelerated_video_decode_enabled =
402 !gpu_prefs.disable_accelerated_video_decode;
Sheng-Hao Tsaoea6aa852018-01-03 06:48:16403 sandbox_options.accelerated_video_encode_enabled =
404 !gpu_prefs.disable_accelerated_video_encode;
Tom Sepez085507ab2017-10-18 22:36:00405
Tom Sepeza2cba0062017-11-07 17:22:43406 bool res = service_manager::SandboxLinux::GetInstance()->InitializeSandbox(
Tom Sepez2255db72017-10-26 18:50:09407 service_manager::SandboxTypeFromCommandLine(
408 *base::CommandLine::ForCurrentProcess()),
Tom Sepez4b101712017-11-08 19:39:58409 base::BindOnce(GpuProcessPreSandboxHook), sandbox_options);
Tom Sepeza0950c62017-10-18 20:39:14410
[email protected]f330b762014-02-08 04:52:46411 if (watchdog_thread) {
Tom Sepeza0950c62017-10-18 20:39:14412 base::Thread::Options thread_options;
413 thread_options.timer_slack = base::TIMER_SLACK_MAXIMUM;
414 watchdog_thread->StartWithOptions(thread_options);
[email protected]f330b762014-02-08 04:52:46415 }
[email protected]663c4b32013-04-18 05:52:54416
417 return res;
418}
419#endif // defined(OS_LINUX)
420
421#if defined(OS_WIN)
422bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) {
fdorayf30bf3a2015-10-28 21:47:00423 TRACE_EVENT0("gpu,startup", "Lower token");
[email protected]663c4b32013-04-18 05:52:54424
425 // For Windows, if the target_services interface is not zero, the process
426 // is sandboxed and we must call LowerToken() before rendering untrusted
427 // content.
428 sandbox::TargetServices* target_services = sandbox_info->target_services;
429 if (target_services) {
430 target_services->LowerToken();
431 return true;
432 }
433
434 return false;
435}
436#endif // defined(OS_WIN)
437
[email protected]6ec3a572012-08-17 02:09:51438} // namespace.
439
[email protected]eb398192012-10-22 20:16:19440} // namespace content