OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/gpu/gpu_thread.h" | 5 #include "chrome/gpu/gpu_thread.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/gfx/gl/gl_context.h" | 10 #include "app/gfx/gl/gl_context.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/worker_pool.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "chrome/common/child_process.h" | 14 #include "chrome/common/child_process.h" |
14 #include "chrome/common/child_process_logging.h" | 15 #include "chrome/common/child_process_logging.h" |
15 #include "chrome/common/gpu_messages.h" | 16 #include "chrome/common/gpu_messages.h" |
16 #include "chrome/gpu/gpu_info_collector.h" | 17 #include "chrome/gpu/gpu_info_collector.h" |
17 #include "ipc/ipc_channel_handle.h" | 18 #include "ipc/ipc_channel_handle.h" |
18 | 19 |
| 20 #if defined(OS_WIN) |
| 21 #include "app/win_util.h" |
| 22 #endif |
| 23 |
19 #if defined(TOOLKIT_USES_GTK) | 24 #if defined(TOOLKIT_USES_GTK) |
20 #include <gtk/gtk.h> | 25 #include <gtk/gtk.h> |
21 #include "app/x11_util.h" | 26 #include "app/x11_util.h" |
22 #include "gfx/gtk_util.h" | 27 #include "gfx/gtk_util.h" |
23 #endif | 28 #endif |
24 | 29 |
25 GpuThread::GpuThread() { | 30 GpuThread::GpuThread() { |
26 #if defined(OS_LINUX) | 31 #if defined(OS_LINUX) |
27 { | 32 { |
28 // The X11 port of the command buffer code assumes it can access the X | 33 // The X11 port of the command buffer code assumes it can access the X |
29 // display via the macro GDK_DISPLAY(), which implies that Gtk has been | 34 // display via the macro GDK_DISPLAY(), which implies that Gtk has been |
30 // initialized. This code was taken from PluginThread. TODO(kbr): | 35 // initialized. This code was taken from PluginThread. TODO(kbr): |
31 // rethink whether initializing Gtk is really necessary or whether we | 36 // rethink whether initializing Gtk is really necessary or whether we |
32 // should just send a raw display connection down to the GPUProcessor. | 37 // should just send a raw display connection down to the GPUProcessor. |
33 g_thread_init(NULL); | 38 g_thread_init(NULL); |
34 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 39 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
35 x11_util::SetDefaultX11ErrorHandlers(); | 40 x11_util::SetDefaultX11ErrorHandlers(); |
36 } | 41 } |
37 #endif | 42 #endif |
38 } | 43 } |
39 | 44 |
40 GpuThread::~GpuThread() { | 45 GpuThread::~GpuThread() { |
41 } | 46 } |
42 | 47 |
43 void GpuThread::Init(const base::Time& process_start_time) { | 48 void GpuThread::Init(const base::Time& process_start_time) { |
44 gpu_info_collector::CollectGraphicsInfo(&gpu_info_); | 49 gpu_info_collector::CollectGraphicsInfo(&gpu_info_); |
45 child_process_logging::SetGpuInfo(gpu_info_); | 50 child_process_logging::SetGpuInfo(gpu_info_); |
46 | 51 |
| 52 #if defined(OS_WIN) |
| 53 // Asynchronously collect the DirectX diagnostics because this can take a |
| 54 // couple of seconds. |
| 55 if (!WorkerPool::PostTask( |
| 56 FROM_HERE, |
| 57 NewRunnableFunction(&GpuThread::CollectDxDiagnostics, this), |
| 58 true)) { |
| 59 // Flag GPU info as complete if the DirectX diagnostics cannot be collected. |
| 60 gpu_info_.SetProgress(GPUInfo::kComplete); |
| 61 } |
| 62 #endif |
| 63 |
47 // Record initialization only after collecting the GPU info because that can | 64 // Record initialization only after collecting the GPU info because that can |
48 // take a significant amount of time. | 65 // take a significant amount of time. |
49 gpu_info_.SetInitializationTime(base::Time::Now() - process_start_time); | 66 gpu_info_.SetInitializationTime(base::Time::Now() - process_start_time); |
50 } | 67 } |
51 | 68 |
52 void GpuThread::RemoveChannel(int renderer_id) { | 69 void GpuThread::RemoveChannel(int renderer_id) { |
53 gpu_channels_.erase(renderer_id); | 70 gpu_channels_.erase(renderer_id); |
54 } | 71 } |
55 | 72 |
56 void GpuThread::OnControlMessageReceived(const IPC::Message& msg) { | 73 void GpuThread::OnControlMessageReceived(const IPC::Message& msg) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 void GpuThread::OnCrash() { | 128 void GpuThread::OnCrash() { |
112 // Good bye, cruel world. | 129 // Good bye, cruel world. |
113 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; | 130 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; |
114 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; | 131 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; |
115 } | 132 } |
116 | 133 |
117 void GpuThread::OnHang() { | 134 void GpuThread::OnHang() { |
118 for (;;) | 135 for (;;) |
119 PlatformThread::Sleep(1000); | 136 PlatformThread::Sleep(1000); |
120 } | 137 } |
| 138 |
| 139 #if defined(OS_WIN) |
| 140 |
| 141 // Runs on a worker thread. The GpuThread never terminates voluntarily so it is |
| 142 // safe to assume that its message loop is valid. |
| 143 void GpuThread::CollectDxDiagnostics(GpuThread* thread) { |
| 144 win_util::ScopedCOMInitializer com_initializer; |
| 145 |
| 146 DxDiagNode node; |
| 147 gpu_info_collector::GetDxDiagnostics(&node); |
| 148 |
| 149 thread->message_loop()->PostTask( |
| 150 FROM_HERE, |
| 151 NewRunnableFunction(&GpuThread::SetDxDiagnostics, thread, node)); |
| 152 } |
| 153 |
| 154 // Runs on the GPU thread. |
| 155 void GpuThread::SetDxDiagnostics(GpuThread* thread, const DxDiagNode& node) { |
| 156 thread->gpu_info_.SetDxDiagnostics(node); |
| 157 thread->gpu_info_.SetProgress(GPUInfo::kComplete); |
| 158 } |
| 159 |
| 160 #endif |
OLD | NEW |