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