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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 GpuProcessHost* host = g_gpu_process_hosts[i]; | 260 GpuProcessHost* host = g_gpu_process_hosts[i]; |
261 if (host && host->host_id_ == host_id && HostIsValid(host)) | 261 if (host && host->host_id_ == host_id && HostIsValid(host)) |
262 return host; | 262 return host; |
263 } | 263 } |
264 | 264 |
265 return NULL; | 265 return NULL; |
266 } | 266 } |
267 | 267 |
268 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 268 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
269 : host_id_(host_id), | 269 : host_id_(host_id), |
| 270 gpu_process_(base::kNullProcessHandle), |
270 in_process_(false), | 271 in_process_(false), |
271 software_rendering_(false), | 272 software_rendering_(false), |
272 kind_(kind), | 273 kind_(kind), |
273 process_launched_(false) { | 274 process_launched_(false) { |
274 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 275 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
275 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) | 276 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) |
276 in_process_ = true; | 277 in_process_ = true; |
277 | 278 |
278 // If the 'single GPU process' policy ever changes, we still want to maintain | 279 // If the 'single GPU process' policy ever changes, we still want to maintain |
279 // it for 'gpu thread' mode and only create one instance of host and thread. | 280 // it for 'gpu thread' mode and only create one instance of host and thread. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 status, | 331 status, |
331 base::TERMINATION_STATUS_MAX_ENUM); | 332 base::TERMINATION_STATUS_MAX_ENUM); |
332 | 333 |
333 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION || | 334 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION || |
334 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { | 335 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { |
335 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessExitCode", | 336 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessExitCode", |
336 exit_code, | 337 exit_code, |
337 content::RESULT_CODE_LAST_CODE); | 338 content::RESULT_CODE_LAST_CODE); |
338 } | 339 } |
339 | 340 |
| 341 #if defined(OS_WIN) |
| 342 if (gpu_process_) |
| 343 CloseHandle(gpu_process_); |
| 344 #endif |
| 345 |
340 // In case we never started, clean up. | 346 // In case we never started, clean up. |
341 while (!queued_messages_.empty()) { | 347 while (!queued_messages_.empty()) { |
342 delete queued_messages_.front(); | 348 delete queued_messages_.front(); |
343 queued_messages_.pop(); | 349 queued_messages_.pop(); |
344 } | 350 } |
345 | 351 |
346 // This is only called on the IO thread so no race against the constructor | 352 // This is only called on the IO thread so no race against the constructor |
347 // for another GpuProcessHost. | 353 // for another GpuProcessHost. |
348 if (g_gpu_process_hosts[kind_] == this) | 354 if (g_gpu_process_hosts[kind_] == this) |
349 g_gpu_process_hosts[kind_] = NULL; | 355 g_gpu_process_hosts[kind_] = NULL; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 #if defined(TOOLKIT_GTK) | 491 #if defined(TOOLKIT_GTK) |
486 surface_refs_.insert(std::make_pair(surface_id, surface_ref)); | 492 surface_refs_.insert(std::make_pair(surface_id, surface_ref)); |
487 #endif | 493 #endif |
488 } else { | 494 } else { |
489 CreateCommandBufferError(callback, MSG_ROUTING_NONE); | 495 CreateCommandBufferError(callback, MSG_ROUTING_NONE); |
490 } | 496 } |
491 } | 497 } |
492 | 498 |
493 void GpuProcessHost::OnChannelEstablished( | 499 void GpuProcessHost::OnChannelEstablished( |
494 const IPC::ChannelHandle& channel_handle) { | 500 const IPC::ChannelHandle& channel_handle) { |
| 501 // The GPU process should have launched at this point and this object should |
| 502 // have been notified of its process handle. |
| 503 DCHECK(gpu_process_); |
| 504 |
495 EstablishChannelCallback callback = channel_requests_.front(); | 505 EstablishChannelCallback callback = channel_requests_.front(); |
496 channel_requests_.pop(); | 506 channel_requests_.pop(); |
497 | 507 |
498 // Currently if any of the GPU features are blacklisted, we don't establish a | 508 // Currently if any of the GPU features are blacklisted, we don't establish a |
499 // GPU channel. | 509 // GPU channel. |
500 if (!channel_handle.name.empty() && | 510 if (!channel_handle.name.empty() && |
501 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { | 511 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { |
502 Send(new GpuMsg_CloseChannel(channel_handle)); | 512 Send(new GpuMsg_CloseChannel(channel_handle)); |
503 EstablishChannelError(callback, | 513 EstablishChannelError(callback, |
504 IPC::ChannelHandle(), | 514 IPC::ChannelHandle(), |
505 base::kNullProcessHandle, | 515 base::kNullProcessHandle, |
506 content::GPUInfo()); | 516 content::GPUInfo()); |
507 RouteOnUIThread(GpuHostMsg_OnLogMessage( | 517 RouteOnUIThread(GpuHostMsg_OnLogMessage( |
508 logging::LOG_WARNING, | 518 logging::LOG_WARNING, |
509 "WARNING", | 519 "WARNING", |
510 "Hardware acceleration is unavailable.")); | 520 "Hardware acceleration is unavailable.")); |
511 return; | 521 return; |
512 } | 522 } |
513 | 523 |
514 callback.Run(channel_handle, | 524 callback.Run(channel_handle, gpu_process_, |
515 GpuDataManagerImpl::GetInstance()->GetGPUInfo()); | 525 GpuDataManagerImpl::GetInstance()->GetGPUInfo()); |
516 } | 526 } |
517 | 527 |
518 void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { | 528 void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { |
519 if (!create_command_buffer_requests_.empty()) { | 529 if (!create_command_buffer_requests_.empty()) { |
520 CreateCommandBufferCallback callback = | 530 CreateCommandBufferCallback callback = |
521 create_command_buffer_requests_.front(); | 531 create_command_buffer_requests_.front(); |
522 create_command_buffer_requests_.pop(); | 532 create_command_buffer_requests_.pop(); |
523 if (route_id == MSG_ROUTING_NONE) | 533 if (route_id == MSG_ROUTING_NONE) |
524 CreateCommandBufferError(callback, route_id); | 534 CreateCommandBufferError(callback, route_id); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 AcceleratedPresenter::GetForWindow(handle.handle)); | 616 AcceleratedPresenter::GetForWindow(handle.handle)); |
607 if (!presenter) | 617 if (!presenter) |
608 return; | 618 return; |
609 | 619 |
610 presenter->ReleaseSurface(); | 620 presenter->ReleaseSurface(); |
611 } | 621 } |
612 | 622 |
613 #endif // OS_WIN && !USE_AURA | 623 #endif // OS_WIN && !USE_AURA |
614 | 624 |
615 void GpuProcessHost::OnProcessLaunched() { | 625 void GpuProcessHost::OnProcessLaunched() { |
| 626 // Send the GPU process handle to the UI thread before it has to |
| 627 // respond to any requests to establish a GPU channel. The response |
| 628 // to such requests require that the GPU process handle be known. |
| 629 |
| 630 base::ProcessHandle child_handle = in_process_ ? |
| 631 base::GetCurrentProcessHandle() : process_->GetData().handle; |
| 632 |
| 633 #if defined(OS_WIN) |
| 634 DuplicateHandle(base::GetCurrentProcessHandle(), |
| 635 child_handle, |
| 636 base::GetCurrentProcessHandle(), |
| 637 &gpu_process_, |
| 638 PROCESS_DUP_HANDLE, |
| 639 FALSE, |
| 640 0); |
| 641 #else |
| 642 gpu_process_ = child_handle; |
| 643 #endif |
| 644 |
616 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", | 645 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", |
617 base::TimeTicks::Now() - init_start_time_); | 646 base::TimeTicks::Now() - init_start_time_); |
618 } | 647 } |
619 | 648 |
620 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 649 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
621 SendOutstandingReplies(); | 650 SendOutstandingReplies(); |
622 } | 651 } |
623 | 652 |
624 bool GpuProcessHost::software_rendering() { | 653 bool GpuProcessHost::software_rendering() { |
625 return software_rendering_; | 654 return software_rendering_; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 base::kNullProcessHandle, | 767 base::kNullProcessHandle, |
739 content::GPUInfo()); | 768 content::GPUInfo()); |
740 } | 769 } |
741 } | 770 } |
742 | 771 |
743 void GpuProcessHost::EstablishChannelError( | 772 void GpuProcessHost::EstablishChannelError( |
744 const EstablishChannelCallback& callback, | 773 const EstablishChannelCallback& callback, |
745 const IPC::ChannelHandle& channel_handle, | 774 const IPC::ChannelHandle& channel_handle, |
746 base::ProcessHandle renderer_process_for_gpu, | 775 base::ProcessHandle renderer_process_for_gpu, |
747 const content::GPUInfo& gpu_info) { | 776 const content::GPUInfo& gpu_info) { |
748 callback.Run(channel_handle, gpu_info); | 777 callback.Run(channel_handle, renderer_process_for_gpu, gpu_info); |
749 } | 778 } |
750 | 779 |
751 void GpuProcessHost::CreateCommandBufferError( | 780 void GpuProcessHost::CreateCommandBufferError( |
752 const CreateCommandBufferCallback& callback, int32 route_id) { | 781 const CreateCommandBufferCallback& callback, int32 route_id) { |
753 callback.Run(route_id); | 782 callback.Run(route_id); |
754 } | 783 } |
OLD | NEW |