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_client.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_sync_message_filter.h" | 21 #include "ipc/ipc_sync_message_filter.h" |
22 #include "ui/gl/gl_implementation.h" | 22 #include "ui/gl/gl_implementation.h" |
23 | 23 |
24 const int kGpuTimeout = 10000; | 24 const int kGpuTimeout = 10000; |
25 | 25 |
| 26 namespace content { |
26 namespace { | 27 namespace { |
27 | 28 |
28 bool GpuProcessLogMessageHandler(int severity, | 29 bool GpuProcessLogMessageHandler(int severity, |
29 const char* file, int line, | 30 const char* file, int line, |
30 size_t message_start, | 31 size_t message_start, |
31 const std::string& str) { | 32 const std::string& str) { |
32 std::string header = str.substr(0, message_start); | 33 std::string header = str.substr(0, message_start); |
33 std::string message = str.substr(message_start); | 34 std::string message = str.substr(message_start); |
34 | 35 |
35 // If we are not on main thread in child process, send through | 36 // If we are not on main thread in child process, send through |
36 // the sync_message_filter; otherwise send directly. | 37 // the sync_message_filter; otherwise send directly. |
37 if (MessageLoop::current() != | 38 if (MessageLoop::current() != |
38 ChildProcess::current()->main_thread()->message_loop()) { | 39 ChildProcess::current()->main_thread()->message_loop()) { |
39 ChildProcess::current()->main_thread()->sync_message_filter()->Send( | 40 ChildProcess::current()->main_thread()->sync_message_filter()->Send( |
40 new GpuHostMsg_OnLogMessage(severity, header, message)); | 41 new GpuHostMsg_OnLogMessage(severity, header, message)); |
41 } else { | 42 } else { |
42 ChildThread::current()->Send(new GpuHostMsg_OnLogMessage(severity, header, | 43 ChildThread::current()->Send(new GpuHostMsg_OnLogMessage(severity, header, |
43 message)); | 44 message)); |
44 } | 45 } |
45 | 46 |
46 return false; | 47 return false; |
47 } | 48 } |
48 | 49 |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 GpuChildThread::GpuChildThread(bool dead_on_arrival, | 52 GpuChildThread::GpuChildThread(bool dead_on_arrival, const GPUInfo& gpu_info) |
52 const content::GPUInfo& gpu_info) | |
53 : dead_on_arrival_(dead_on_arrival), | 53 : dead_on_arrival_(dead_on_arrival), |
54 gpu_info_(gpu_info) { | 54 gpu_info_(gpu_info) { |
55 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
56 target_services_ = NULL; | 56 target_services_ = NULL; |
57 collecting_dx_diagnostics_ = false; | 57 collecting_dx_diagnostics_ = false; |
58 #endif | 58 #endif |
59 } | 59 } |
60 | 60 |
61 GpuChildThread::GpuChildThread(const std::string& channel_id) | 61 GpuChildThread::GpuChildThread(const std::string& channel_id) |
62 : ChildThread(channel_id), | 62 : ChildThread(channel_id), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void GpuChildThread::OnCollectGraphicsInfo() { | 182 void GpuChildThread::OnCollectGraphicsInfo() { |
183 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 183 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
184 if (command_line->HasSwitch(switches::kDisableGpuSandbox) || | 184 if (command_line->HasSwitch(switches::kDisableGpuSandbox) || |
185 command_line->ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 185 command_line->ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
186 command_line->ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) { | 186 command_line->ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) { |
187 // GPU full info collection should only happen on un-sandboxed GPU process | 187 // GPU full info collection should only happen on un-sandboxed GPU process |
188 // or single process/in-process gpu mode. | 188 // or single process/in-process gpu mode. |
189 | 189 |
190 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info_)) | 190 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info_)) |
191 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; | 191 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; |
192 content::GetContentClient()->SetGpuInfo(gpu_info_); | 192 GetContentClient()->SetGpuInfo(gpu_info_); |
193 | 193 |
194 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
195 if (!collecting_dx_diagnostics_) { | 195 if (!collecting_dx_diagnostics_) { |
196 // Prevent concurrent collection of DirectX diagnostics. | 196 // Prevent concurrent collection of DirectX diagnostics. |
197 collecting_dx_diagnostics_ = true; | 197 collecting_dx_diagnostics_ = true; |
198 | 198 |
199 // Asynchronously collect the DirectX diagnostics because this can take a | 199 // Asynchronously collect the DirectX diagnostics because this can take a |
200 // couple of seconds. | 200 // couple of seconds. |
201 if (!base::WorkerPool::PostTask( | 201 if (!base::WorkerPool::PostTask( |
202 FROM_HERE, base::Bind(&GpuChildThread::CollectDxDiagnostics, this), | 202 FROM_HERE, base::Bind(&GpuChildThread::CollectDxDiagnostics, this), |
203 true)) { | 203 true)) { |
204 // Flag GPU info as complete if the DirectX diagnostics cannot be | 204 // Flag GPU info as complete if the DirectX diagnostics cannot be |
205 // collected. | 205 // collected. |
206 collecting_dx_diagnostics_ = false; | 206 collecting_dx_diagnostics_ = false; |
207 gpu_info_.finalized = true; | 207 gpu_info_.finalized = true; |
208 } | 208 } |
209 } | 209 } |
210 #endif | 210 #endif |
211 } | 211 } |
212 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); | 212 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_)); |
213 } | 213 } |
214 | 214 |
215 void GpuChildThread::OnGetVideoMemoryUsageStats() { | 215 void GpuChildThread::OnGetVideoMemoryUsageStats() { |
216 content::GPUVideoMemoryUsageStats video_memory_usage_stats; | 216 GPUVideoMemoryUsageStats video_memory_usage_stats; |
217 if (gpu_channel_manager_.get()) | 217 if (gpu_channel_manager_.get()) |
218 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( | 218 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( |
219 video_memory_usage_stats); | 219 video_memory_usage_stats); |
220 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats)); | 220 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats)); |
221 } | 221 } |
222 | 222 |
223 void GpuChildThread::OnSetVideoMemoryWindowCount(uint32 window_count) { | 223 void GpuChildThread::OnSetVideoMemoryWindowCount(uint32 window_count) { |
224 if (gpu_channel_manager_.get()) | 224 if (gpu_channel_manager_.get()) |
225 gpu_channel_manager_->gpu_memory_manager()->SetWindowCount(window_count); | 225 gpu_channel_manager_->gpu_memory_manager()->SetWindowCount(window_count); |
226 } | 226 } |
(...skipping 17 matching lines...) Expand all Loading... |
244 // Do not sleep here. The GPU watchdog timer tracks the amount of user | 244 // Do not sleep here. The GPU watchdog timer tracks the amount of user |
245 // time this thread is using and it doesn't use much while calling Sleep. | 245 // time this thread is using and it doesn't use much while calling Sleep. |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 #if defined(OS_WIN) | 249 #if defined(OS_WIN) |
250 | 250 |
251 // Runs on a worker thread. The GPU process never terminates voluntarily so | 251 // Runs on a worker thread. The GPU process never terminates voluntarily so |
252 // it is safe to assume that its message loop is valid. | 252 // it is safe to assume that its message loop is valid. |
253 void GpuChildThread::CollectDxDiagnostics(GpuChildThread* thread) { | 253 void GpuChildThread::CollectDxDiagnostics(GpuChildThread* thread) { |
254 content::DxDiagNode node; | 254 DxDiagNode node; |
255 gpu_info_collector::GetDxDiagnostics(&node); | 255 gpu_info_collector::GetDxDiagnostics(&node); |
256 | 256 |
257 thread->message_loop()->PostTask( | 257 thread->message_loop()->PostTask( |
258 FROM_HERE, base::Bind(&GpuChildThread::SetDxDiagnostics, thread, node)); | 258 FROM_HERE, base::Bind(&GpuChildThread::SetDxDiagnostics, thread, node)); |
259 } | 259 } |
260 | 260 |
261 // Runs on the main thread. | 261 // Runs on the main thread. |
262 void GpuChildThread::SetDxDiagnostics(GpuChildThread* thread, | 262 void GpuChildThread::SetDxDiagnostics(GpuChildThread* thread, |
263 const content::DxDiagNode& node) { | 263 const DxDiagNode& node) { |
264 thread->gpu_info_.dx_diagnostics = node; | 264 thread->gpu_info_.dx_diagnostics = node; |
265 thread->gpu_info_.finalized = true; | 265 thread->gpu_info_.finalized = true; |
266 thread->collecting_dx_diagnostics_ = false; | 266 thread->collecting_dx_diagnostics_ = false; |
267 thread->Send(new GpuHostMsg_GraphicsInfoCollected(thread->gpu_info_)); | 267 thread->Send(new GpuHostMsg_GraphicsInfoCollected(thread->gpu_info_)); |
268 } | 268 } |
269 | 269 |
270 #endif | 270 #endif |
| 271 |
| 272 } // namespace content |
| 273 |
OLD | NEW |