Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 void GpuProcessHost::SendOnIO(GpuProcessKind kind, | 418 void GpuProcessHost::SendOnIO(GpuProcessKind kind, |
| 419 bool force_create, | 419 bool force_create, |
| 420 IPC::Message* message) { | 420 IPC::Message* message) { |
| 421 if (!BrowserThread::PostTask( | 421 if (!BrowserThread::PostTask( |
| 422 BrowserThread::IO, FROM_HERE, | 422 BrowserThread::IO, FROM_HERE, |
| 423 base::Bind(&SendGpuProcessMessage, kind, force_create, message))) { | 423 base::Bind(&SendGpuProcessMessage, kind, force_create, message))) { |
| 424 delete message; | 424 delete message; |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 | 427 |
| 428 GpuProcessHost::EstablishChannelRequest::EstablishChannelRequest() | |
| 429 : client_id(0) {} | |
| 430 | |
| 431 GpuProcessHost::EstablishChannelRequest::EstablishChannelRequest( | |
| 432 const EstablishChannelRequest& other) = default; | |
| 433 | |
| 434 GpuProcessHost::EstablishChannelRequest::~EstablishChannelRequest() {} | |
| 435 | |
| 436 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { | 428 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { |
| 437 return process_->child_connection()->GetRemoteInterfaces(); | 429 return process_->child_connection()->GetRemoteInterfaces(); |
| 438 } | 430 } |
| 439 | 431 |
| 440 // static | 432 // static |
| 441 GpuProcessHost* GpuProcessHost::FromID(int host_id) { | 433 GpuProcessHost* GpuProcessHost::FromID(int host_id) { |
| 442 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 434 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 443 | 435 |
| 444 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { | 436 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { |
| 445 GpuProcessHost* host = g_gpu_process_hosts[i]; | 437 GpuProcessHost* host = g_gpu_process_hosts[i]; |
| 446 if (host && host->host_id_ == host_id && ValidateHost(host)) | 438 if (host && host->host_id_ == host_id && ValidateHost(host)) |
| 447 return host; | 439 return host; |
| 448 } | 440 } |
| 449 | 441 |
| 450 return NULL; | 442 return NULL; |
| 451 } | 443 } |
| 452 | 444 |
| 453 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 445 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
| 454 : host_id_(host_id), | 446 : host_id_(host_id), |
| 455 valid_(true), | 447 valid_(true), |
| 456 in_process_(false), | 448 in_process_(false), |
| 457 swiftshader_rendering_(false), | 449 swiftshader_rendering_(false), |
| 458 kind_(kind), | 450 kind_(kind), |
| 459 process_launched_(false), | 451 process_launched_(false), |
| 460 initialized_(false), | 452 initialized_(false), |
| 461 gpu_host_binding_(this) { | 453 gpu_host_binding_(this), |
| 454 weak_ptr_factory_(this) { | |
| 462 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 455 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 463 switches::kSingleProcess) || | 456 switches::kSingleProcess) || |
| 464 base::CommandLine::ForCurrentProcess()->HasSwitch( | 457 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 465 switches::kInProcessGPU)) { | 458 switches::kInProcessGPU)) { |
| 466 in_process_ = true; | 459 in_process_ = true; |
| 467 } | 460 } |
| 468 | 461 |
| 469 // If the 'single GPU process' policy ever changes, we still want to maintain | 462 // If the 'single GPU process' policy ever changes, we still want to maintain |
| 470 // it for 'gpu thread' mode and only create one instance of host and thread. | 463 // it for 'gpu thread' mode and only create one instance of host and thread. |
| 471 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); | 464 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 | 653 |
| 661 void GpuProcessHost::AddFilter(IPC::MessageFilter* filter) { | 654 void GpuProcessHost::AddFilter(IPC::MessageFilter* filter) { |
| 662 DCHECK(CalledOnValidThread()); | 655 DCHECK(CalledOnValidThread()); |
| 663 process_->GetHost()->AddFilter(filter); | 656 process_->GetHost()->AddFilter(filter); |
| 664 } | 657 } |
| 665 | 658 |
| 666 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 659 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 667 DCHECK(CalledOnValidThread()); | 660 DCHECK(CalledOnValidThread()); |
| 668 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 661 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| 669 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) | 662 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) |
| 670 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) | |
| 671 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, | 663 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, |
| 672 OnGpuMemoryBufferCreated) | 664 OnGpuMemoryBufferCreated) |
| 673 #if defined(OS_ANDROID) | 665 #if defined(OS_ANDROID) |
| 674 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyingVideoSurfaceAck, | 666 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyingVideoSurfaceAck, |
| 675 OnDestroyingVideoSurfaceAck) | 667 OnDestroyingVideoSurfaceAck) |
| 676 #endif | 668 #endif |
| 677 IPC_MESSAGE_HANDLER(GpuHostMsg_FieldTrialActivated, OnFieldTrialActivated); | 669 IPC_MESSAGE_HANDLER(GpuHostMsg_FieldTrialActivated, OnFieldTrialActivated); |
| 678 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 670 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
| 679 IPC_END_MESSAGE_MAP() | 671 IPC_END_MESSAGE_MAP() |
| 680 | 672 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 700 DCHECK(CalledOnValidThread()); | 692 DCHECK(CalledOnValidThread()); |
| 701 TRACE_EVENT0("gpu", "GpuProcessHost::EstablishGpuChannel"); | 693 TRACE_EVENT0("gpu", "GpuProcessHost::EstablishGpuChannel"); |
| 702 | 694 |
| 703 // If GPU features are already blacklisted, no need to establish the channel. | 695 // If GPU features are already blacklisted, no need to establish the channel. |
| 704 if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { | 696 if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { |
| 705 DVLOG(1) << "GPU blacklisted, refusing to open a GPU channel."; | 697 DVLOG(1) << "GPU blacklisted, refusing to open a GPU channel."; |
| 706 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 698 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 707 return; | 699 return; |
| 708 } | 700 } |
| 709 | 701 |
| 710 EstablishChannelParams params; | 702 DCHECK_EQ(preempts, allow_view_command_buffers); |
| 711 params.client_id = client_id; | 703 DCHECK_EQ(preempts, allow_real_time_streams); |
| 712 params.client_tracing_id = client_tracing_id; | 704 bool is_gpu_host = preempts; |
| 713 params.preempts = preempts; | 705 |
| 714 params.allow_view_command_buffers = allow_view_command_buffers; | 706 channel_requests_.push(callback); |
| 715 params.allow_real_time_streams = allow_real_time_streams; | 707 gpu_service_ptr_->EstablishGpuChannel( |
| 716 if (Send(new GpuMsg_EstablishChannel(params))) { | 708 client_id, client_tracing_id, is_gpu_host, |
| 717 EstablishChannelRequest request; | 709 base::Bind(&GpuProcessHost::OnChannelEstablished, |
| 718 request.client_id = client_id; | 710 weak_ptr_factory_.GetWeakPtr(), client_id, callback)); |
| 719 request.callback = callback; | |
| 720 channel_requests_.push(request); | |
| 721 } else { | |
| 722 DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; | |
|
Fady Samuel
2017/02/13 15:52:27
What happens if the MessagePipe has a connection e
sadrul
2017/02/13 15:57:23
That would be when the gpu process has crashed or
| |
| 723 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | |
| 724 } | |
| 725 | 711 |
| 726 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 712 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 727 switches::kDisableGpuShaderDiskCache)) { | 713 switches::kDisableGpuShaderDiskCache)) { |
| 728 CreateChannelCache(client_id); | 714 CreateChannelCache(client_id); |
| 729 } | 715 } |
| 730 } | 716 } |
| 731 | 717 |
| 732 void GpuProcessHost::CreateGpuMemoryBuffer( | 718 void GpuProcessHost::CreateGpuMemoryBuffer( |
| 733 gfx::GpuMemoryBufferId id, | 719 gfx::GpuMemoryBufferId id, |
| 734 const gfx::Size& size, | 720 const gfx::Size& size, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 | 775 |
| 790 if (!initialized_) { | 776 if (!initialized_) { |
| 791 GpuDataManagerImpl::GetInstance()->OnGpuProcessInitFailure(); | 777 GpuDataManagerImpl::GetInstance()->OnGpuProcessInitFailure(); |
| 792 return; | 778 return; |
| 793 } | 779 } |
| 794 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); | 780 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); |
| 795 GpuDataManagerImpl::GetInstance()->UpdateGpuFeatureInfo(gpu_feature_info); | 781 GpuDataManagerImpl::GetInstance()->UpdateGpuFeatureInfo(gpu_feature_info); |
| 796 } | 782 } |
| 797 | 783 |
| 798 void GpuProcessHost::OnChannelEstablished( | 784 void GpuProcessHost::OnChannelEstablished( |
| 799 const IPC::ChannelHandle& channel_handle) { | 785 int client_id, |
| 786 const EstablishChannelCallback& callback, | |
| 787 mojo::ScopedMessagePipeHandle channel_handle) { | |
| 800 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); | 788 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); |
| 801 | 789 DCHECK(!channel_requests_.empty()); |
| 802 if (channel_requests_.empty()) { | 790 DCHECK(channel_requests_.front().Equals(callback)); |
| 803 // This happens when GPU process is compromised. | |
| 804 RouteOnUIThread(GpuHostMsg_OnLogMessage( | |
| 805 logging::LOG_WARNING, "WARNING", | |
| 806 "Received a ChannelEstablished message but no requests in queue.")); | |
| 807 return; | |
| 808 } | |
| 809 EstablishChannelRequest request = channel_requests_.front(); | |
| 810 channel_requests_.pop(); | 791 channel_requests_.pop(); |
| 811 | 792 |
| 812 // Currently if any of the GPU features are blacklisted, we don't establish a | 793 // Currently if any of the GPU features are blacklisted, we don't establish a |
| 813 // GPU channel. | 794 // GPU channel. |
| 814 if (channel_handle.mojo_handle.is_valid() && | 795 if (channel_handle.is_valid() && |
| 815 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { | 796 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(nullptr)) { |
| 816 Send(new GpuMsg_CloseChannel(request.client_id)); | 797 Send(new GpuMsg_CloseChannel(client_id)); |
| 817 request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 798 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 818 RouteOnUIThread( | 799 RouteOnUIThread( |
| 819 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", | 800 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", |
| 820 "Hardware acceleration is unavailable.")); | 801 "Hardware acceleration is unavailable.")); |
| 821 return; | 802 return; |
| 822 } | 803 } |
| 823 | 804 |
| 824 request.callback.Run(channel_handle, gpu_info_); | 805 callback.Run(IPC::ChannelHandle(channel_handle.release()), gpu_info_); |
| 825 } | 806 } |
| 826 | 807 |
| 827 void GpuProcessHost::OnGpuMemoryBufferCreated( | 808 void GpuProcessHost::OnGpuMemoryBufferCreated( |
| 828 const gfx::GpuMemoryBufferHandle& handle) { | 809 const gfx::GpuMemoryBufferHandle& handle) { |
| 829 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); | 810 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); |
| 830 | 811 |
| 831 if (create_gpu_memory_buffer_requests_.empty()) | 812 if (create_gpu_memory_buffer_requests_.empty()) |
| 832 return; | 813 return; |
| 833 | 814 |
| 834 CreateGpuMemoryBufferCallback callback = | 815 CreateGpuMemoryBufferCallback callback = |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 process_->Launch(std::move(delegate), std::move(cmd_line), true); | 1050 process_->Launch(std::move(delegate), std::move(cmd_line), true); |
| 1070 process_launched_ = true; | 1051 process_launched_ = true; |
| 1071 | 1052 |
| 1072 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", | 1053 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", |
| 1073 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); | 1054 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); |
| 1074 return true; | 1055 return true; |
| 1075 } | 1056 } |
| 1076 | 1057 |
| 1077 void GpuProcessHost::SendOutstandingReplies() { | 1058 void GpuProcessHost::SendOutstandingReplies() { |
| 1078 valid_ = false; | 1059 valid_ = false; |
| 1060 | |
| 1079 // First send empty channel handles for all EstablishChannel requests. | 1061 // First send empty channel handles for all EstablishChannel requests. |
| 1080 while (!channel_requests_.empty()) { | 1062 while (!channel_requests_.empty()) { |
| 1081 EstablishChannelRequest request = channel_requests_.front(); | 1063 auto callback = channel_requests_.front(); |
| 1082 channel_requests_.pop(); | 1064 channel_requests_.pop(); |
| 1083 request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 1065 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 1084 } | 1066 } |
| 1085 | 1067 |
| 1086 while (!create_gpu_memory_buffer_requests_.empty()) { | 1068 while (!create_gpu_memory_buffer_requests_.empty()) { |
| 1087 CreateGpuMemoryBufferCallback callback = | 1069 CreateGpuMemoryBufferCallback callback = |
| 1088 create_gpu_memory_buffer_requests_.front(); | 1070 create_gpu_memory_buffer_requests_.front(); |
| 1089 create_gpu_memory_buffer_requests_.pop(); | 1071 create_gpu_memory_buffer_requests_.pop(); |
| 1090 callback.Run(gfx::GpuMemoryBufferHandle()); | 1072 callback.Run(gfx::GpuMemoryBufferHandle()); |
| 1091 } | 1073 } |
| 1092 | 1074 |
| 1093 if (!send_destroying_video_surface_done_cb_.is_null()) | 1075 if (!send_destroying_video_surface_done_cb_.is_null()) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 GetShaderCacheFactorySingleton()->Get(client_id); | 1185 GetShaderCacheFactorySingleton()->Get(client_id); |
| 1204 if (!cache.get()) | 1186 if (!cache.get()) |
| 1205 return; | 1187 return; |
| 1206 | 1188 |
| 1207 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); | 1189 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); |
| 1208 | 1190 |
| 1209 client_id_to_shader_cache_[client_id] = cache; | 1191 client_id_to_shader_cache_[client_id] = cache; |
| 1210 } | 1192 } |
| 1211 | 1193 |
| 1212 } // namespace content | 1194 } // namespace content |
| OLD | NEW |