[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 5 | #include <stdlib.h> |
6 | |||||
[email protected] | cafd0b6 | 2011-01-19 01:22:05 | [diff] [blame] | 7 | #if defined(OS_WIN) |
8 | #include <windows.h> | ||||
9 | #endif | ||||
10 | |||||
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 11 | #include "base/environment.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 13 | #include "base/stringprintf.h" |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 14 | #include "base/threading/platform_thread.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 15 | #include "base/win/scoped_com_initializer.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 17 | #include "content/common/gpu/gpu_config.h" |
[email protected] | 415c2cd | 2011-03-11 21:56:11 | [diff] [blame] | 18 | #include "content/common/main_function_params.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 19 | #include "content/public/common/content_switches.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 20 | #include "content/gpu/gpu_child_thread.h" |
[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 21 | #include "content/gpu/gpu_process.h" |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 22 | #include "ui/gfx/gl/gl_surface.h" |
[email protected] | d2a6c0e3 | 2011-08-08 21:53:16 | [diff] [blame] | 23 | #include "ui/gfx/gl/gl_switches.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 24 | |
[email protected] | 802a13a0 | 2010-12-02 01:48:37 | [diff] [blame] | 25 | #if defined(OS_MACOSX) |
[email protected] | 415c2cd | 2011-03-11 21:56:11 | [diff] [blame] | 26 | #include "content/common/chrome_application_mac.h" |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 27 | #elif defined(OS_WIN) |
28 | #include "sandbox/src/sandbox.h" | ||||
[email protected] | 802a13a0 | 2010-12-02 01:48:37 | [diff] [blame] | 29 | #endif |
30 | |||||
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 31 | #if defined(USE_X11) |
[email protected] | 57b5d7dc | 2011-03-09 14:11:34 | [diff] [blame] | 32 | #include "ui/base/x/x11_util.h" |
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 33 | #endif |
34 | |||||
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 35 | // Main function for starting the Gpu process. |
36 | int GpuMain(const MainFunctionParams& parameters) { | ||||
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 37 | base::Time start_time = base::Time::Now(); |
38 | |||||
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame^] | 39 | const CommandLine& command_line = parameters.command_line; |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 40 | if (command_line.HasSwitch(switches::kGpuStartupDialog)) { |
[email protected] | 75fcc27 | 2011-03-08 20:50:48 | [diff] [blame] | 41 | ChildProcess::WaitForDebugger("Gpu"); |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 42 | } |
43 | |||||
[email protected] | 23f4656 | 2011-09-07 01:42:39 | [diff] [blame] | 44 | if (!command_line.HasSwitch(switches::kSingleProcess)) { |
45 | #if defined(OS_WIN) | ||||
46 | // Prevent Windows from displaying a modal dialog on failures like not being | ||||
47 | // able to load a DLL. | ||||
48 | SetErrorMode( | ||||
49 | SEM_FAILCRITICALERRORS | | ||||
50 | SEM_NOGPFAULTERRORBOX | | ||||
51 | SEM_NOOPENFILEERRORBOX); | ||||
52 | #elif defined(USE_X11) | ||||
53 | ui::SetDefaultX11ErrorHandlers(); | ||||
54 | #endif | ||||
55 | } | ||||
56 | |||||
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 57 | // Initialization of the OpenGL bindings may fail, in which case we |
58 | // will need to tear down this process. However, we can not do so | ||||
59 | // safely until the IPC channel is set up, because the detection of | ||||
60 | // early return of a child process is implemented using an IPC | ||||
61 | // channel error. If the IPC channel is not fully set up between the | ||||
62 | // browser and GPU process, and the GPU process crashes or exits | ||||
63 | // early, the browser process will never detect it. For this reason | ||||
64 | // we defer tearing down the GPU process until receiving the | ||||
65 | // GpuMsg_Initialize message from the browser. | ||||
66 | bool dead_on_arrival = false; | ||||
67 | |||||
[email protected] | 4a2a4d2 | 2011-07-25 23:20:34 | [diff] [blame] | 68 | // Load the GL implementation and locate the bindings before starting the GPU |
69 | // watchdog because this can take a lot of time and the GPU watchdog might | ||||
70 | // terminate the GPU process. | ||||
71 | if (!gfx::GLSurface::InitializeOneOff()) { | ||||
[email protected] | 51dd1b48 | 2011-10-18 19:35:19 | [diff] [blame] | 72 | LOG(INFO) << "gfx::GLSurface::InitializeOneOff failed"; |
[email protected] | 4a2a4d2 | 2011-07-25 23:20:34 | [diff] [blame] | 73 | dead_on_arrival = true; |
74 | } | ||||
75 | |||||
[email protected] | bccf36e | 2011-08-16 16:41:06 | [diff] [blame] | 76 | base::win::ScopedCOMInitializer com_initializer; |
77 | |||||
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 78 | #if defined(OS_WIN) |
79 | sandbox::TargetServices* target_services = | ||||
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame^] | 80 | parameters.sandbox_info->target_services; |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 81 | // For windows, if the target_services interface is not zero, the process |
82 | // is sandboxed and we must call LowerToken() before rendering untrusted | ||||
83 | // content. | ||||
84 | if (target_services) | ||||
85 | target_services->LowerToken(); | ||||
86 | #endif | ||||
87 | |||||
[email protected] | de9e0b5 | 2010-12-23 22:01:17 | [diff] [blame] | 88 | #if defined(OS_MACOSX) |
89 | chrome_application_mac::RegisterCrApp(); | ||||
90 | #endif | ||||
91 | |||||
[email protected] | d2a6c0e3 | 2011-08-08 21:53:16 | [diff] [blame] | 92 | MessageLoop::Type message_loop_type = MessageLoop::TYPE_UI; |
93 | #if defined(OS_WIN) | ||||
94 | // Unless we're running on desktop GL, we don't need a UI message | ||||
95 | // loop, so avoid its use to work around apparent problems with some | ||||
96 | // third-party software. | ||||
97 | message_loop_type = MessageLoop::TYPE_IO; | ||||
98 | if (command_line.HasSwitch(switches::kUseGL) && | ||||
99 | command_line.GetSwitchValueASCII(switches::kUseGL) == | ||||
100 | gfx::kGLImplementationDesktopName) { | ||||
101 | message_loop_type = MessageLoop::TYPE_UI; | ||||
102 | } | ||||
103 | #endif | ||||
104 | |||||
105 | MessageLoop main_message_loop(message_loop_type); | ||||
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 106 | base::PlatformThread::SetName("CrGpuMain"); |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 107 | |
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 108 | GpuProcess gpu_process; |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 109 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 110 | GpuChildThread* child_thread = new GpuChildThread(dead_on_arrival); |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 111 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 112 | child_thread->Init(start_time); |
[email protected] | 995a7f1 | 2011-02-11 23:07:17 | [diff] [blame] | 113 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 114 | gpu_process.set_main_thread(child_thread); |
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 115 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 116 | main_message_loop.Run(); |
117 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 118 | child_thread->StopWatchdog(); |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 119 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 120 | return 0; |
121 | } |