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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 GpuProcessHost* host = g_hosts_by_id.Pointer()->Lookup(host_id); | 275 GpuProcessHost* host = g_hosts_by_id.Pointer()->Lookup(host_id); |
276 if (HostIsValid(host)) | 276 if (HostIsValid(host)) |
277 return host; | 277 return host; |
278 | 278 |
279 return NULL; | 279 return NULL; |
280 } | 280 } |
281 | 281 |
282 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 282 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
283 : host_id_(host_id), | 283 : host_id_(host_id), |
284 gpu_process_(base::kNullProcessHandle), | |
285 in_process_(false), | 284 in_process_(false), |
286 software_rendering_(false), | 285 software_rendering_(false), |
287 kind_(kind), | 286 kind_(kind), |
288 process_launched_(false) { | 287 process_launched_(false) { |
289 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
290 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) | 289 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) |
291 in_process_ = true; | 290 in_process_ = true; |
292 | 291 |
293 // If the 'single GPU process' policy ever changes, we still want to maintain | 292 // If the 'single GPU process' policy ever changes, we still want to maintain |
294 // it for 'gpu thread' mode and only create one instance of host and thread. | 293 // 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... |
345 status, | 344 status, |
346 base::TERMINATION_STATUS_MAX_ENUM); | 345 base::TERMINATION_STATUS_MAX_ENUM); |
347 | 346 |
348 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION || | 347 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION || |
349 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { | 348 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { |
350 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessExitCode", | 349 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessExitCode", |
351 exit_code, | 350 exit_code, |
352 content::RESULT_CODE_LAST_CODE); | 351 content::RESULT_CODE_LAST_CODE); |
353 } | 352 } |
354 | 353 |
355 #if defined(OS_WIN) | |
356 if (gpu_process_) | |
357 CloseHandle(gpu_process_); | |
358 #endif | |
359 | |
360 // In case we never started, clean up. | 354 // In case we never started, clean up. |
361 while (!queued_messages_.empty()) { | 355 while (!queued_messages_.empty()) { |
362 delete queued_messages_.front(); | 356 delete queued_messages_.front(); |
363 queued_messages_.pop(); | 357 queued_messages_.pop(); |
364 } | 358 } |
365 | 359 |
366 g_hosts_by_id.Pointer()->Remove(host_id_); | 360 g_hosts_by_id.Pointer()->Remove(host_id_); |
367 | 361 |
368 BrowserThread::PostTask(BrowserThread::UI, | 362 BrowserThread::PostTask(BrowserThread::UI, |
369 FROM_HERE, | 363 FROM_HERE, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 #if defined(TOOLKIT_GTK) | 494 #if defined(TOOLKIT_GTK) |
501 surface_refs_.insert(std::make_pair(surface_id, surface_ref)); | 495 surface_refs_.insert(std::make_pair(surface_id, surface_ref)); |
502 #endif | 496 #endif |
503 } else { | 497 } else { |
504 CreateCommandBufferError(callback, MSG_ROUTING_NONE); | 498 CreateCommandBufferError(callback, MSG_ROUTING_NONE); |
505 } | 499 } |
506 } | 500 } |
507 | 501 |
508 void GpuProcessHost::OnChannelEstablished( | 502 void GpuProcessHost::OnChannelEstablished( |
509 const IPC::ChannelHandle& channel_handle) { | 503 const IPC::ChannelHandle& channel_handle) { |
510 // The GPU process should have launched at this point and this object should | |
511 // have been notified of its process handle. | |
512 DCHECK(gpu_process_); | |
513 | |
514 EstablishChannelCallback callback = channel_requests_.front(); | 504 EstablishChannelCallback callback = channel_requests_.front(); |
515 channel_requests_.pop(); | 505 channel_requests_.pop(); |
516 | 506 |
517 // Currently if any of the GPU features are blacklisted, we don't establish a | 507 // Currently if any of the GPU features are blacklisted, we don't establish a |
518 // GPU channel. | 508 // GPU channel. |
519 if (!channel_handle.name.empty() && | 509 if (!channel_handle.name.empty() && |
520 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { | 510 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { |
521 Send(new GpuMsg_CloseChannel(channel_handle)); | 511 Send(new GpuMsg_CloseChannel(channel_handle)); |
522 EstablishChannelError(callback, | 512 EstablishChannelError(callback, |
523 IPC::ChannelHandle(), | 513 IPC::ChannelHandle(), |
524 base::kNullProcessHandle, | 514 base::kNullProcessHandle, |
525 content::GPUInfo()); | 515 content::GPUInfo()); |
526 RouteOnUIThread(GpuHostMsg_OnLogMessage( | 516 RouteOnUIThread(GpuHostMsg_OnLogMessage( |
527 logging::LOG_WARNING, | 517 logging::LOG_WARNING, |
528 "WARNING", | 518 "WARNING", |
529 "Hardware acceleration is unavailable.")); | 519 "Hardware acceleration is unavailable.")); |
530 return; | 520 return; |
531 } | 521 } |
532 | 522 |
533 callback.Run(channel_handle, gpu_process_, | 523 callback.Run(channel_handle, |
534 GpuDataManagerImpl::GetInstance()->GetGPUInfo()); | 524 GpuDataManagerImpl::GetInstance()->GetGPUInfo()); |
535 } | 525 } |
536 | 526 |
537 void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { | 527 void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { |
538 if (!create_command_buffer_requests_.empty()) { | 528 if (!create_command_buffer_requests_.empty()) { |
539 CreateCommandBufferCallback callback = | 529 CreateCommandBufferCallback callback = |
540 create_command_buffer_requests_.front(); | 530 create_command_buffer_requests_.front(); |
541 create_command_buffer_requests_.pop(); | 531 create_command_buffer_requests_.pop(); |
542 if (route_id == MSG_ROUTING_NONE) | 532 if (route_id == MSG_ROUTING_NONE) |
543 CreateCommandBufferError(callback, route_id); | 533 CreateCommandBufferError(callback, route_id); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 scoped_refptr<AcceleratedPresenter> presenter( | 614 scoped_refptr<AcceleratedPresenter> presenter( |
625 AcceleratedPresenter::GetForWindow(handle.handle)); | 615 AcceleratedPresenter::GetForWindow(handle.handle)); |
626 if (!presenter) | 616 if (!presenter) |
627 return; | 617 return; |
628 | 618 |
629 presenter->ReleaseSurface(); | 619 presenter->ReleaseSurface(); |
630 } | 620 } |
631 | 621 |
632 #endif // OS_WIN && !USE_AURA | 622 #endif // OS_WIN && !USE_AURA |
633 | 623 |
634 void GpuProcessHost::OnProcessLaunched() { | |
635 // Send the GPU process handle to the UI thread before it has to | |
636 // respond to any requests to establish a GPU channel. The response | |
637 // to such requests require that the GPU process handle be known. | |
638 | |
639 base::ProcessHandle child_handle = in_process_ ? | |
640 base::GetCurrentProcessHandle() : process_->GetData().handle; | |
641 | |
642 #if defined(OS_WIN) | |
643 DuplicateHandle(base::GetCurrentProcessHandle(), | |
644 child_handle, | |
645 base::GetCurrentProcessHandle(), | |
646 &gpu_process_, | |
647 PROCESS_DUP_HANDLE, | |
648 FALSE, | |
649 0); | |
650 #else | |
651 gpu_process_ = child_handle; | |
652 #endif | |
653 } | |
654 | |
655 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 624 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
656 SendOutstandingReplies(); | 625 SendOutstandingReplies(); |
657 } | 626 } |
658 | 627 |
659 bool GpuProcessHost::software_rendering() { | 628 bool GpuProcessHost::software_rendering() { |
660 return software_rendering_; | 629 return software_rendering_; |
661 } | 630 } |
662 | 631 |
663 GpuProcessHost::GpuProcessKind GpuProcessHost::kind() { | 632 GpuProcessHost::GpuProcessKind GpuProcessHost::kind() { |
664 return kind_; | 633 return kind_; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 base::kNullProcessHandle, | 741 base::kNullProcessHandle, |
773 content::GPUInfo()); | 742 content::GPUInfo()); |
774 } | 743 } |
775 } | 744 } |
776 | 745 |
777 void GpuProcessHost::EstablishChannelError( | 746 void GpuProcessHost::EstablishChannelError( |
778 const EstablishChannelCallback& callback, | 747 const EstablishChannelCallback& callback, |
779 const IPC::ChannelHandle& channel_handle, | 748 const IPC::ChannelHandle& channel_handle, |
780 base::ProcessHandle renderer_process_for_gpu, | 749 base::ProcessHandle renderer_process_for_gpu, |
781 const content::GPUInfo& gpu_info) { | 750 const content::GPUInfo& gpu_info) { |
782 callback.Run(channel_handle, renderer_process_for_gpu, gpu_info); | 751 callback.Run(channel_handle, gpu_info); |
783 } | 752 } |
784 | 753 |
785 void GpuProcessHost::CreateCommandBufferError( | 754 void GpuProcessHost::CreateCommandBufferError( |
786 const CreateCommandBufferCallback& callback, int32 route_id) { | 755 const CreateCommandBufferCallback& callback, int32 route_id) { |
787 callback.Run(route_id); | 756 callback.Run(route_id); |
788 } | 757 } |
OLD | NEW |