| 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // static | 438 // static |
| 439 void GpuProcessHost::CallOnIO( | 439 void GpuProcessHost::CallOnIO( |
| 440 GpuProcessKind kind, | 440 GpuProcessKind kind, |
| 441 bool force_create, | 441 bool force_create, |
| 442 const base::Callback<void(GpuProcessHost*)>& callback) { | 442 const base::Callback<void(GpuProcessHost*)>& callback) { |
| 443 BrowserThread::PostTask( | 443 BrowserThread::PostTask( |
| 444 BrowserThread::IO, FROM_HERE, | 444 BrowserThread::IO, FROM_HERE, |
| 445 base::Bind(&RunCallbackOnIO, kind, force_create, callback)); | 445 base::Bind(&RunCallbackOnIO, kind, force_create, callback)); |
| 446 } | 446 } |
| 447 | 447 |
| 448 GpuProcessHost::EstablishChannelRequest::EstablishChannelRequest() |
| 449 : client_id(0) {} |
| 450 |
| 451 GpuProcessHost::EstablishChannelRequest::EstablishChannelRequest( |
| 452 const EstablishChannelRequest& other) = default; |
| 453 |
| 454 GpuProcessHost::EstablishChannelRequest::~EstablishChannelRequest() {} |
| 455 |
| 448 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { | 456 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { |
| 449 return process_->child_connection()->GetRemoteInterfaces(); | 457 return process_->child_connection()->GetRemoteInterfaces(); |
| 450 } | 458 } |
| 451 | 459 |
| 452 // static | 460 // static |
| 453 GpuProcessHost* GpuProcessHost::FromID(int host_id) { | 461 GpuProcessHost* GpuProcessHost::FromID(int host_id) { |
| 454 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 462 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 455 | 463 |
| 456 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { | 464 for (int i = 0; i < GPU_PROCESS_KIND_COUNT; ++i) { |
| 457 GpuProcessHost* host = g_gpu_process_hosts[i]; | 465 GpuProcessHost* host = g_gpu_process_hosts[i]; |
| 458 if (host && host->host_id_ == host_id && ValidateHost(host)) | 466 if (host && host->host_id_ == host_id && ValidateHost(host)) |
| 459 return host; | 467 return host; |
| 460 } | 468 } |
| 461 | 469 |
| 462 return NULL; | 470 return NULL; |
| 463 } | 471 } |
| 464 | 472 |
| 465 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 473 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
| 466 : host_id_(host_id), | 474 : host_id_(host_id), |
| 467 valid_(true), | 475 valid_(true), |
| 468 in_process_(false), | 476 in_process_(false), |
| 469 swiftshader_rendering_(false), | 477 swiftshader_rendering_(false), |
| 470 kind_(kind), | 478 kind_(kind), |
| 471 process_launched_(false), | 479 process_launched_(false), |
| 472 initialized_(false), | 480 initialized_(false), |
| 473 gpu_host_binding_(this), | 481 gpu_host_binding_(this) { |
| 474 weak_ptr_factory_(this) { | |
| 475 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 482 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 476 switches::kSingleProcess) || | 483 switches::kSingleProcess) || |
| 477 base::CommandLine::ForCurrentProcess()->HasSwitch( | 484 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 478 switches::kInProcessGPU)) { | 485 switches::kInProcessGPU)) { |
| 479 in_process_ = true; | 486 in_process_ = true; |
| 480 } | 487 } |
| 481 | 488 |
| 482 // If the 'single GPU process' policy ever changes, we still want to maintain | 489 // If the 'single GPU process' policy ever changes, we still want to maintain |
| 483 // it for 'gpu thread' mode and only create one instance of host and thread. | 490 // it for 'gpu thread' mode and only create one instance of host and thread. |
| 484 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); | 491 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 680 |
| 674 void GpuProcessHost::AddFilter(IPC::MessageFilter* filter) { | 681 void GpuProcessHost::AddFilter(IPC::MessageFilter* filter) { |
| 675 DCHECK(CalledOnValidThread()); | 682 DCHECK(CalledOnValidThread()); |
| 676 process_->GetHost()->AddFilter(filter); | 683 process_->GetHost()->AddFilter(filter); |
| 677 } | 684 } |
| 678 | 685 |
| 679 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 686 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 680 DCHECK(CalledOnValidThread()); | 687 DCHECK(CalledOnValidThread()); |
| 681 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 688 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| 682 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) | 689 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) |
| 690 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
| 683 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, | 691 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, |
| 684 OnGpuMemoryBufferCreated) | 692 OnGpuMemoryBufferCreated) |
| 685 #if defined(OS_ANDROID) | 693 #if defined(OS_ANDROID) |
| 686 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyingVideoSurfaceAck, | 694 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyingVideoSurfaceAck, |
| 687 OnDestroyingVideoSurfaceAck) | 695 OnDestroyingVideoSurfaceAck) |
| 688 #endif | 696 #endif |
| 689 IPC_MESSAGE_HANDLER(GpuHostMsg_FieldTrialActivated, OnFieldTrialActivated); | 697 IPC_MESSAGE_HANDLER(GpuHostMsg_FieldTrialActivated, OnFieldTrialActivated); |
| 690 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 698 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
| 691 IPC_END_MESSAGE_MAP() | 699 IPC_END_MESSAGE_MAP() |
| 692 | 700 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 712 DCHECK(CalledOnValidThread()); | 720 DCHECK(CalledOnValidThread()); |
| 713 TRACE_EVENT0("gpu", "GpuProcessHost::EstablishGpuChannel"); | 721 TRACE_EVENT0("gpu", "GpuProcessHost::EstablishGpuChannel"); |
| 714 | 722 |
| 715 // If GPU features are already blacklisted, no need to establish the channel. | 723 // If GPU features are already blacklisted, no need to establish the channel. |
| 716 if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { | 724 if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { |
| 717 DVLOG(1) << "GPU blacklisted, refusing to open a GPU channel."; | 725 DVLOG(1) << "GPU blacklisted, refusing to open a GPU channel."; |
| 718 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 726 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 719 return; | 727 return; |
| 720 } | 728 } |
| 721 | 729 |
| 722 DCHECK_EQ(preempts, allow_view_command_buffers); | 730 EstablishChannelParams params; |
| 723 DCHECK_EQ(preempts, allow_real_time_streams); | 731 params.client_id = client_id; |
| 724 bool is_gpu_host = preempts; | 732 params.client_tracing_id = client_tracing_id; |
| 725 | 733 params.preempts = preempts; |
| 726 channel_requests_.push(callback); | 734 params.allow_view_command_buffers = allow_view_command_buffers; |
| 727 gpu_service_ptr_->EstablishGpuChannel( | 735 params.allow_real_time_streams = allow_real_time_streams; |
| 728 client_id, client_tracing_id, is_gpu_host, | 736 if (Send(new GpuMsg_EstablishChannel(params))) { |
| 729 base::Bind(&GpuProcessHost::OnChannelEstablished, | 737 EstablishChannelRequest request; |
| 730 weak_ptr_factory_.GetWeakPtr(), client_id, callback)); | 738 request.client_id = client_id; |
| 739 request.callback = callback; |
| 740 channel_requests_.push(request); |
| 741 } else { |
| 742 DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; |
| 743 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 744 } |
| 731 | 745 |
| 732 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 746 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 733 switches::kDisableGpuShaderDiskCache)) { | 747 switches::kDisableGpuShaderDiskCache)) { |
| 734 CreateChannelCache(client_id); | 748 CreateChannelCache(client_id); |
| 735 } | 749 } |
| 736 } | 750 } |
| 737 | 751 |
| 738 void GpuProcessHost::CreateGpuMemoryBuffer( | 752 void GpuProcessHost::CreateGpuMemoryBuffer( |
| 739 gfx::GpuMemoryBufferId id, | 753 gfx::GpuMemoryBufferId id, |
| 740 const gfx::Size& size, | 754 const gfx::Size& size, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 809 |
| 796 if (!initialized_) { | 810 if (!initialized_) { |
| 797 GpuDataManagerImpl::GetInstance()->OnGpuProcessInitFailure(); | 811 GpuDataManagerImpl::GetInstance()->OnGpuProcessInitFailure(); |
| 798 return; | 812 return; |
| 799 } | 813 } |
| 800 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); | 814 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); |
| 801 GpuDataManagerImpl::GetInstance()->UpdateGpuFeatureInfo(gpu_feature_info); | 815 GpuDataManagerImpl::GetInstance()->UpdateGpuFeatureInfo(gpu_feature_info); |
| 802 } | 816 } |
| 803 | 817 |
| 804 void GpuProcessHost::OnChannelEstablished( | 818 void GpuProcessHost::OnChannelEstablished( |
| 805 int client_id, | 819 const IPC::ChannelHandle& channel_handle) { |
| 806 const EstablishChannelCallback& callback, | |
| 807 mojo::ScopedMessagePipeHandle channel_handle) { | |
| 808 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); | 820 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); |
| 809 DCHECK(!channel_requests_.empty()); | 821 |
| 810 DCHECK(channel_requests_.front().Equals(callback)); | 822 if (channel_requests_.empty()) { |
| 823 // This happens when GPU process is compromised. |
| 824 RouteOnUIThread(GpuHostMsg_OnLogMessage( |
| 825 logging::LOG_WARNING, "WARNING", |
| 826 "Received a ChannelEstablished message but no requests in queue.")); |
| 827 return; |
| 828 } |
| 829 EstablishChannelRequest request = channel_requests_.front(); |
| 811 channel_requests_.pop(); | 830 channel_requests_.pop(); |
| 812 | 831 |
| 813 // Currently if any of the GPU features are blacklisted, we don't establish a | 832 // Currently if any of the GPU features are blacklisted, we don't establish a |
| 814 // GPU channel. | 833 // GPU channel. |
| 815 if (channel_handle.is_valid() && | 834 if (channel_handle.mojo_handle.is_valid() && |
| 816 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(nullptr)) { | 835 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { |
| 817 Send(new GpuMsg_CloseChannel(client_id)); | 836 Send(new GpuMsg_CloseChannel(request.client_id)); |
| 818 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 837 request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 819 RouteOnUIThread( | 838 RouteOnUIThread( |
| 820 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", | 839 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", |
| 821 "Hardware acceleration is unavailable.")); | 840 "Hardware acceleration is unavailable.")); |
| 822 return; | 841 return; |
| 823 } | 842 } |
| 824 | 843 |
| 825 callback.Run(IPC::ChannelHandle(channel_handle.release()), gpu_info_); | 844 request.callback.Run(channel_handle, gpu_info_); |
| 826 } | 845 } |
| 827 | 846 |
| 828 void GpuProcessHost::OnGpuMemoryBufferCreated( | 847 void GpuProcessHost::OnGpuMemoryBufferCreated( |
| 829 const gfx::GpuMemoryBufferHandle& handle) { | 848 const gfx::GpuMemoryBufferHandle& handle) { |
| 830 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); | 849 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); |
| 831 | 850 |
| 832 if (create_gpu_memory_buffer_requests_.empty()) | 851 if (create_gpu_memory_buffer_requests_.empty()) |
| 833 return; | 852 return; |
| 834 | 853 |
| 835 CreateGpuMemoryBufferCallback callback = | 854 CreateGpuMemoryBufferCallback callback = |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 process_->Launch(std::move(delegate), std::move(cmd_line), true); | 1094 process_->Launch(std::move(delegate), std::move(cmd_line), true); |
| 1076 process_launched_ = true; | 1095 process_launched_ = true; |
| 1077 | 1096 |
| 1078 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", | 1097 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", |
| 1079 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); | 1098 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); |
| 1080 return true; | 1099 return true; |
| 1081 } | 1100 } |
| 1082 | 1101 |
| 1083 void GpuProcessHost::SendOutstandingReplies() { | 1102 void GpuProcessHost::SendOutstandingReplies() { |
| 1084 valid_ = false; | 1103 valid_ = false; |
| 1085 | |
| 1086 // First send empty channel handles for all EstablishChannel requests. | 1104 // First send empty channel handles for all EstablishChannel requests. |
| 1087 while (!channel_requests_.empty()) { | 1105 while (!channel_requests_.empty()) { |
| 1088 auto callback = channel_requests_.front(); | 1106 EstablishChannelRequest request = channel_requests_.front(); |
| 1089 channel_requests_.pop(); | 1107 channel_requests_.pop(); |
| 1090 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 1108 request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 1091 } | 1109 } |
| 1092 | 1110 |
| 1093 while (!create_gpu_memory_buffer_requests_.empty()) { | 1111 while (!create_gpu_memory_buffer_requests_.empty()) { |
| 1094 CreateGpuMemoryBufferCallback callback = | 1112 CreateGpuMemoryBufferCallback callback = |
| 1095 create_gpu_memory_buffer_requests_.front(); | 1113 create_gpu_memory_buffer_requests_.front(); |
| 1096 create_gpu_memory_buffer_requests_.pop(); | 1114 create_gpu_memory_buffer_requests_.pop(); |
| 1097 callback.Run(gfx::GpuMemoryBufferHandle()); | 1115 callback.Run(gfx::GpuMemoryBufferHandle()); |
| 1098 } | 1116 } |
| 1099 | 1117 |
| 1100 if (!send_destroying_video_surface_done_cb_.is_null()) | 1118 if (!send_destroying_video_surface_done_cb_.is_null()) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 GetShaderCacheFactorySingleton()->Get(client_id); | 1227 GetShaderCacheFactorySingleton()->Get(client_id); |
| 1210 if (!cache.get()) | 1228 if (!cache.get()) |
| 1211 return; | 1229 return; |
| 1212 | 1230 |
| 1213 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); | 1231 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); |
| 1214 | 1232 |
| 1215 client_id_to_shader_cache_[client_id] = cache; | 1233 client_id_to_shader_cache_[client_id] = cache; |
| 1216 } | 1234 } |
| 1217 | 1235 |
| 1218 } // namespace content | 1236 } // namespace content |
| OLD | NEW |