blob: 422175cf71ed7fe2783c2f99826de22ad94f107c [file] [log] [blame]
[email protected]623c0bd2011-03-12 01:00:411// Copyright (c) 2011 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
[email protected]e09cee42010-11-09 01:50:085#include <stdlib.h>
6
[email protected]cafd0b62011-01-19 01:22:057#if defined(OS_WIN)
8#include <windows.h>
9#endif
10
[email protected]fd85ad62010-12-31 20:39:0211#include "app/win/scoped_com_initializer.h"
[email protected]e09cee42010-11-09 01:50:0812#include "base/environment.h"
[email protected]c0fc0942010-01-13 00:55:3713#include "base/message_loop.h"
[email protected]e09cee42010-11-09 01:50:0814#include "base/stringprintf.h"
[email protected]ce072a72010-12-31 20:02:1615#include "base/threading/platform_thread.h"
[email protected]c0fc0942010-01-13 00:55:3716#include "build/build_config.h"
[email protected]6b7a5e32011-03-11 18:34:1017#include "content/common/content_switches.h"
[email protected]f24a1e2b2011-04-08 01:48:4818#include "content/common/gpu/gpu_config.h"
[email protected]415c2cd2011-03-11 21:56:1119#include "content/common/main_function_params.h"
[email protected]7a31f7c2011-03-21 23:22:0420#include "content/gpu/gpu_child_thread.h"
[email protected]623c0bd2011-03-12 01:00:4121#include "content/gpu/gpu_process.h"
[email protected]c0fc0942010-01-13 00:55:3722
[email protected]802a13a02010-12-02 01:48:3723#if defined(OS_MACOSX)
[email protected]415c2cd2011-03-11 21:56:1124#include "content/common/chrome_application_mac.h"
[email protected]802a13a02010-12-02 01:48:3725#endif
26
[email protected]02ec37a2010-09-20 22:32:1627#if defined(USE_X11)
[email protected]57b5d7dc2011-03-09 14:11:3428#include "ui/base/x/x11_util.h"
[email protected]02ec37a2010-09-20 22:32:1629#endif
30
[email protected]c0fc0942010-01-13 00:55:3731// Main function for starting the Gpu process.
32int GpuMain(const MainFunctionParams& parameters) {
[email protected]e09cee42010-11-09 01:50:0833 base::Time start_time = base::Time::Now();
34
[email protected]6b889fb2010-03-23 20:09:4935 const CommandLine& command_line = parameters.command_line_;
36 if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
[email protected]75fcc272011-03-08 20:50:4837 ChildProcess::WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:4938 }
39
[email protected]de9e0b52010-12-23 22:01:1740#if defined(OS_MACOSX)
41 chrome_application_mac::RegisterCrApp();
42#endif
43
[email protected]c0fc0942010-01-13 00:55:3744 MessageLoop main_message_loop(MessageLoop::TYPE_UI);
[email protected]ce072a72010-12-31 20:02:1645 base::PlatformThread::SetName("CrGpuMain");
[email protected]c0fc0942010-01-13 00:55:3746
[email protected]57b5d7dc2011-03-09 14:11:3447 if (!command_line.HasSwitch(switches::kSingleProcess)) {
[email protected]cafd0b62011-01-19 01:22:0548#if defined(OS_WIN)
[email protected]57b5d7dc2011-03-09 14:11:3449 // Prevent Windows from displaying a modal dialog on failures like not being
50 // able to load a DLL.
51 SetErrorMode(
52 SEM_FAILCRITICALERRORS |
53 SEM_NOGPFAULTERRORBOX |
54 SEM_NOOPENFILEERRORBOX);
55#elif defined(USE_X11)
56 ui::SetDefaultX11ErrorHandlers();
[email protected]cafd0b62011-01-19 01:22:0557#endif
[email protected]57b5d7dc2011-03-09 14:11:3458 }
[email protected]cafd0b62011-01-19 01:22:0559
[email protected]fd85ad62010-12-31 20:39:0260 app::win::ScopedCOMInitializer com_initializer;
[email protected]c0fc0942010-01-13 00:55:3761
[email protected]7709e712011-01-07 17:57:3162 // We can not tolerate early returns from this code, because the
63 // detection of early return of a child process is implemented using
64 // an IPC channel error. If the IPC channel is not fully set up
65 // between the browser and GPU process, and the GPU process crashes
66 // or exits early, the browser process will never detect it. For
67 // this reason we defer all work related to the GPU until receiving
68 // the GpuMsg_Initialize message from the browser.
[email protected]983c33d2010-11-16 22:38:4469 GpuProcess gpu_process;
[email protected]8fe0ec522011-03-03 00:31:3370
[email protected]7a31f7c2011-03-21 23:22:0471 GpuChildThread* child_thread =
[email protected]8fe0ec522011-03-03 00:31:3372#if defined(OS_WIN)
[email protected]7a31f7c2011-03-21 23:22:0473 new GpuChildThread(parameters.sandbox_info_.TargetServices());
[email protected]8fe0ec522011-03-03 00:31:3374#else
[email protected]7a31f7c2011-03-21 23:22:0475 new GpuChildThread;
[email protected]8fe0ec522011-03-03 00:31:3376#endif
77
[email protected]7a31f7c2011-03-21 23:22:0478 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:1779
[email protected]7a31f7c2011-03-21 23:22:0480 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:4481
[email protected]c0fc0942010-01-13 00:55:3782 main_message_loop.Run();
83
[email protected]7a31f7c2011-03-21 23:22:0484 child_thread->StopWatchdog();
[email protected]e09cee42010-11-09 01:50:0885
[email protected]c0fc0942010-01-13 00:55:3786 return 0;
87}