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/browser/gpu/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 // static | 234 // static |
235 bool GpuProcessHost::HostIsValid(GpuProcessHost* host) { | 235 bool GpuProcessHost::HostIsValid(GpuProcessHost* host) { |
236 if (!host) | 236 if (!host) |
237 return false; | 237 return false; |
238 | 238 |
239 // The Gpu process is invalid if it's not using software, the card is | 239 // The Gpu process is invalid if it's not using software, the card is |
240 // blacklisted, and we can kill it and start over. | 240 // blacklisted, and we can kill it and start over. |
241 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 241 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
242 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || | 242 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || |
243 host->software_rendering() || | 243 (host->valid_ && |
244 !GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) { | 244 (host->software_rendering() || |
| 245 !GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()))) { |
245 return true; | 246 return true; |
246 } | 247 } |
247 | 248 |
248 host->ForceShutdown(); | 249 host->ForceShutdown(); |
249 return false; | 250 return false; |
250 } | 251 } |
251 | 252 |
252 // static | 253 // static |
253 GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind, | 254 GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind, |
254 content::CauseForGpuLaunch cause) { | 255 content::CauseForGpuLaunch cause) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 GpuProcessHost* host = g_gpu_process_hosts[i]; | 301 GpuProcessHost* host = g_gpu_process_hosts[i]; |
301 if (host && host->host_id_ == host_id && HostIsValid(host)) | 302 if (host && host->host_id_ == host_id && HostIsValid(host)) |
302 return host; | 303 return host; |
303 } | 304 } |
304 | 305 |
305 return NULL; | 306 return NULL; |
306 } | 307 } |
307 | 308 |
308 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 309 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
309 : host_id_(host_id), | 310 : host_id_(host_id), |
| 311 valid_(true), |
310 in_process_(false), | 312 in_process_(false), |
311 software_rendering_(false), | 313 software_rendering_(false), |
312 kind_(kind), | 314 kind_(kind), |
313 process_launched_(false) { | 315 process_launched_(false) { |
314 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 316 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
315 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) | 317 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) |
316 in_process_ = true; | 318 in_process_ = true; |
317 | 319 |
318 // If the 'single GPU process' policy ever changes, we still want to maintain | 320 // If the 'single GPU process' policy ever changes, we still want to maintain |
319 // it for 'gpu thread' mode and only create one instance of host and thread. | 321 // it for 'gpu thread' mode and only create one instance of host and thread. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); | 438 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); |
437 } | 439 } |
438 | 440 |
439 bool GpuProcessHost::Send(IPC::Message* msg) { | 441 bool GpuProcessHost::Send(IPC::Message* msg) { |
440 DCHECK(CalledOnValidThread()); | 442 DCHECK(CalledOnValidThread()); |
441 if (process_->GetHost()->IsChannelOpening()) { | 443 if (process_->GetHost()->IsChannelOpening()) { |
442 queued_messages_.push(msg); | 444 queued_messages_.push(msg); |
443 return true; | 445 return true; |
444 } | 446 } |
445 | 447 |
446 return process_->Send(msg); | 448 bool result = process_->Send(msg); |
| 449 if (!result) |
| 450 valid_ = false; |
| 451 return result; |
447 } | 452 } |
448 | 453 |
449 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 454 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
450 DCHECK(CalledOnValidThread()); | 455 DCHECK(CalledOnValidThread()); |
451 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 456 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
452 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) | 457 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
453 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) | 458 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) |
454 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) | 459 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) |
455 #if defined(OS_MACOSX) | 460 #if defined(OS_MACOSX) |
456 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 461 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 const IPC::ChannelHandle& channel_handle, | 867 const IPC::ChannelHandle& channel_handle, |
863 base::ProcessHandle renderer_process_for_gpu, | 868 base::ProcessHandle renderer_process_for_gpu, |
864 const content::GPUInfo& gpu_info) { | 869 const content::GPUInfo& gpu_info) { |
865 callback.Run(channel_handle, gpu_info); | 870 callback.Run(channel_handle, gpu_info); |
866 } | 871 } |
867 | 872 |
868 void GpuProcessHost::CreateCommandBufferError( | 873 void GpuProcessHost::CreateCommandBufferError( |
869 const CreateCommandBufferCallback& callback, int32 route_id) { | 874 const CreateCommandBufferCallback& callback, int32 route_id) { |
870 callback.Run(route_id); | 875 callback.Run(route_id); |
871 } | 876 } |
OLD | NEW |