| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/gpu/gpu_child_thread.h" | 5 #include "content/gpu/gpu_child_thread.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/common/child_process.h" | 14 #include "content/common/child_process.h" |
| 15 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
| 16 #include "content/gpu/gpu_info_collector.h" | 16 #include "content/gpu/gpu_info_collector.h" |
| 17 #include "content/gpu/gpu_watchdog_thread.h" | 17 #include "content/gpu/gpu_watchdog_thread.h" |
| 18 #include "content/public/common/content_client.h" |
| 18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 19 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
| 20 #include "ipc/ipc_sync_message_filter.h" | 21 #include "ipc/ipc_sync_message_filter.h" |
| 21 #include "ui/gl/gl_implementation.h" | 22 #include "ui/gl/gl_implementation.h" |
| 22 | 23 |
| 23 const int kGpuTimeout = 10000; | 24 const int kGpuTimeout = 10000; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool GpuProcessLogMessageHandler(int severity, | 28 bool GpuProcessLogMessageHandler(int severity, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 57 #endif | 58 #endif |
| 58 } | 59 } |
| 59 | 60 |
| 60 GpuChildThread::GpuChildThread(const std::string& channel_id) | 61 GpuChildThread::GpuChildThread(const std::string& channel_id) |
| 61 : ChildThread(channel_id), | 62 : ChildThread(channel_id), |
| 62 dead_on_arrival_(false) { | 63 dead_on_arrival_(false) { |
| 63 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 64 target_services_ = NULL; | 65 target_services_ = NULL; |
| 65 collecting_dx_diagnostics_ = false; | 66 collecting_dx_diagnostics_ = false; |
| 66 #endif | 67 #endif |
| 67 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info_)) { | |
| 68 LOG(INFO) << "gpu_info_collector::CollectGraphicsInfo failed"; | |
| 69 } | |
| 70 } | 68 } |
| 71 | 69 |
| 72 | 70 |
| 73 GpuChildThread::~GpuChildThread() { | 71 GpuChildThread::~GpuChildThread() { |
| 74 logging::SetLogMessageHandler(NULL); | 72 logging::SetLogMessageHandler(NULL); |
| 75 } | 73 } |
| 76 | 74 |
| 77 void GpuChildThread::Init(const base::Time& process_start_time) { | 75 void GpuChildThread::Init(const base::Time& process_start_time) { |
| 78 process_start_time_ = process_start_time; | 76 process_start_time_ = process_start_time; |
| 79 } | 77 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 | 98 |
| 101 if (handled) | 99 if (handled) |
| 102 return true; | 100 return true; |
| 103 | 101 |
| 104 return gpu_channel_manager_.get() && | 102 return gpu_channel_manager_.get() && |
| 105 gpu_channel_manager_->OnMessageReceived(msg); | 103 gpu_channel_manager_->OnMessageReceived(msg); |
| 106 } | 104 } |
| 107 | 105 |
| 108 void GpuChildThread::OnInitialize() { | 106 void GpuChildThread::OnInitialize() { |
| 109 if (dead_on_arrival_) { | 107 if (dead_on_arrival_) { |
| 110 LOG(INFO) << "Exiting GPU process due to errors during initialization"; | 108 VLOG(1) << "Exiting GPU process due to errors during initialization"; |
| 111 MessageLoop::current()->Quit(); | 109 MessageLoop::current()->Quit(); |
| 112 return; | 110 return; |
| 113 } | 111 } |
| 114 | 112 |
| 115 // We don't need to pipe log messages if we are running the GPU thread in | 113 // We don't need to pipe log messages if we are running the GPU thread in |
| 116 // the browser process. | 114 // the browser process. |
| 117 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && | 115 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && |
| 118 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) | 116 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) |
| 119 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 117 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
| 120 | 118 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 154 |
| 157 // Defer creation of the render thread. This is to prevent it from handling | 155 // Defer creation of the render thread. This is to prevent it from handling |
| 158 // IPC messages before the sandbox has been enabled and all other necessary | 156 // IPC messages before the sandbox has been enabled and all other necessary |
| 159 // initialization has succeeded. | 157 // initialization has succeeded. |
| 160 gpu_channel_manager_.reset(new GpuChannelManager( | 158 gpu_channel_manager_.reset(new GpuChannelManager( |
| 161 this, | 159 this, |
| 162 watchdog_thread_, | 160 watchdog_thread_, |
| 163 ChildProcess::current()->io_message_loop_proxy(), | 161 ChildProcess::current()->io_message_loop_proxy(), |
| 164 ChildProcess::current()->GetShutDownEvent())); | 162 ChildProcess::current()->GetShutDownEvent())); |
| 165 | 163 |
| 164 #if defined(OS_LINUX) |
| 166 // Ensure the browser process receives the GPU info before a reply to any | 165 // Ensure the browser process receives the GPU info before a reply to any |
| 167 // subsequent IPC it might send. | 166 // subsequent IPC it might send. |
| 168 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); | 167 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); |
| 168 #endif |
| 169 } | 169 } |
| 170 | 170 |
| 171 void GpuChildThread::StopWatchdog() { | 171 void GpuChildThread::StopWatchdog() { |
| 172 if (watchdog_thread_.get()) { | 172 if (watchdog_thread_.get()) { |
| 173 watchdog_thread_->Stop(); | 173 watchdog_thread_->Stop(); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 void GpuChildThread::OnCollectGraphicsInfo() { | 177 void GpuChildThread::OnCollectGraphicsInfo() { |
| 178 if (!gpu_info_.finalized && |
| 179 CommandLine::ForCurrentProcess()->HasSwitch( |
| 180 switches::kDisableGpuSandbox)) { |
| 181 // GPU full info collection should only happen on un-sandboxed GPU process. |
| 182 |
| 183 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info_)) |
| 184 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; |
| 185 content::GetContentClient()->SetGpuInfo(gpu_info_); |
| 186 |
| 178 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
| 179 if (!gpu_info_.finalized && !collecting_dx_diagnostics_) { | 188 if (!collecting_dx_diagnostics_) { |
| 180 // Prevent concurrent collection of DirectX diagnostics. | 189 // Prevent concurrent collection of DirectX diagnostics. |
| 181 collecting_dx_diagnostics_ = true; | 190 collecting_dx_diagnostics_ = true; |
| 182 | 191 |
| 183 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 184 switches::kDisableGpuSandbox)) { | |
| 185 // Asynchronously collect the DirectX diagnostics because this can take a | 192 // Asynchronously collect the DirectX diagnostics because this can take a |
| 186 // couple of seconds. | 193 // couple of seconds. |
| 187 if (!base::WorkerPool::PostTask( | 194 if (!base::WorkerPool::PostTask( |
| 188 FROM_HERE, base::Bind(&GpuChildThread::CollectDxDiagnostics, this), | 195 FROM_HERE, base::Bind(&GpuChildThread::CollectDxDiagnostics, this), |
| 189 true)) { | 196 true)) { |
| 190 // Flag GPU info as complete if the DirectX diagnostics cannot be | 197 // Flag GPU info as complete if the DirectX diagnostics cannot be |
| 191 // collected. | 198 // collected. |
| 192 collecting_dx_diagnostics_ = false; | 199 collecting_dx_diagnostics_ = false; |
| 193 gpu_info_.finalized = true; | 200 gpu_info_.finalized = true; |
| 194 } else { | |
| 195 // Do not send response if we are still completing the GPUInfo struct | |
| 196 return; | |
| 197 } | 201 } |
| 198 } | 202 } |
| 203 #endif |
| 199 } | 204 } |
| 200 #endif | |
| 201 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); | 205 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); |
| 202 } | 206 } |
| 203 | 207 |
| 204 void GpuChildThread::OnClean() { | 208 void GpuChildThread::OnClean() { |
| 205 LOG(INFO) << "GPU: Removing all contexts"; | 209 VLOG(1) << "GPU: Removing all contexts"; |
| 206 if (gpu_channel_manager_.get()) | 210 if (gpu_channel_manager_.get()) |
| 207 gpu_channel_manager_->LoseAllContexts(); | 211 gpu_channel_manager_->LoseAllContexts(); |
| 208 } | 212 } |
| 209 | 213 |
| 210 void GpuChildThread::OnCrash() { | 214 void GpuChildThread::OnCrash() { |
| 211 LOG(INFO) << "GPU: Simulating GPU crash"; | 215 VLOG(1) << "GPU: Simulating GPU crash"; |
| 212 // Good bye, cruel world. | 216 // Good bye, cruel world. |
| 213 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; | 217 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; |
| 214 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; | 218 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; |
| 215 } | 219 } |
| 216 | 220 |
| 217 void GpuChildThread::OnHang() { | 221 void GpuChildThread::OnHang() { |
| 218 LOG(INFO) << "GPU: Simulating GPU hang"; | 222 VLOG(1) << "GPU: Simulating GPU hang"; |
| 219 for (;;) { | 223 for (;;) { |
| 220 // Do not sleep here. The GPU watchdog timer tracks the amount of user | 224 // Do not sleep here. The GPU watchdog timer tracks the amount of user |
| 221 // time this thread is using and it doesn't use much while calling Sleep. | 225 // time this thread is using and it doesn't use much while calling Sleep. |
| 222 } | 226 } |
| 223 } | 227 } |
| 224 | 228 |
| 225 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
| 226 | 230 |
| 227 // Runs on a worker thread. The GPU process never terminates voluntarily so | 231 // Runs on a worker thread. The GPU process never terminates voluntarily so |
| 228 // it is safe to assume that its message loop is valid. | 232 // it is safe to assume that its message loop is valid. |
| 229 void GpuChildThread::CollectDxDiagnostics(GpuChildThread* thread) { | 233 void GpuChildThread::CollectDxDiagnostics(GpuChildThread* thread) { |
| 230 content::DxDiagNode node; | 234 content::DxDiagNode node; |
| 231 gpu_info_collector::GetDxDiagnostics(&node); | 235 gpu_info_collector::GetDxDiagnostics(&node); |
| 232 | 236 |
| 233 thread->message_loop()->PostTask( | 237 thread->message_loop()->PostTask( |
| 234 FROM_HERE, base::Bind(&GpuChildThread::SetDxDiagnostics, thread, node)); | 238 FROM_HERE, base::Bind(&GpuChildThread::SetDxDiagnostics, thread, node)); |
| 235 } | 239 } |
| 236 | 240 |
| 237 // Runs on the main thread. | 241 // Runs on the main thread. |
| 238 void GpuChildThread::SetDxDiagnostics(GpuChildThread* thread, | 242 void GpuChildThread::SetDxDiagnostics(GpuChildThread* thread, |
| 239 const content::DxDiagNode& node) { | 243 const content::DxDiagNode& node) { |
| 240 thread->gpu_info_.dx_diagnostics = node; | 244 thread->gpu_info_.dx_diagnostics = node; |
| 241 thread->gpu_info_.finalized = true; | 245 thread->gpu_info_.finalized = true; |
| 242 thread->collecting_dx_diagnostics_ = false; | 246 thread->collecting_dx_diagnostics_ = false; |
| 243 thread->Send(new GpuHostMsg_GraphicsInfoCollected(thread->gpu_info_)); | 247 thread->Send(new GpuHostMsg_GraphicsInfoCollected(thread->gpu_info_)); |
| 244 } | 248 } |
| 245 | 249 |
| 246 #endif | 250 #endif |
| OLD | NEW |