| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 BrowserThread::PostTask( | 421 BrowserThread::PostTask( |
| 422 BrowserThread::UI, | 422 BrowserThread::UI, |
| 423 FROM_HERE, | 423 FROM_HERE, |
| 424 base::Bind(callback, handles)); | 424 base::Bind(callback, handles)); |
| 425 } | 425 } |
| 426 | 426 |
| 427 // static | 427 // static |
| 428 void GpuProcessHost::SendOnIO(GpuProcessKind kind, | 428 void GpuProcessHost::SendOnIO(GpuProcessKind kind, |
| 429 bool force_create, | 429 bool force_create, |
| 430 IPC::Message* message) { | 430 IPC::Message* message) { |
| 431 #if !defined(OS_WIN) |
| 432 DCHECK_NE(kind, GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED); |
| 433 #endif |
| 431 if (!BrowserThread::PostTask( | 434 if (!BrowserThread::PostTask( |
| 432 BrowserThread::IO, FROM_HERE, | 435 BrowserThread::IO, FROM_HERE, |
| 433 base::Bind(&SendGpuProcessMessage, kind, force_create, message))) { | 436 base::Bind(&SendGpuProcessMessage, kind, force_create, message))) { |
| 434 delete message; | 437 delete message; |
| 435 } | 438 } |
| 436 } | 439 } |
| 437 | 440 |
| 438 // static | 441 // static |
| 439 void GpuProcessHost::CallOnIO( | 442 void GpuProcessHost::CallOnIO( |
| 440 GpuProcessKind kind, | 443 GpuProcessKind kind, |
| 441 bool force_create, | 444 bool force_create, |
| 442 const base::Callback<void(GpuProcessHost*)>& callback) { | 445 const base::Callback<void(GpuProcessHost*)>& callback) { |
| 446 #if !defined(OS_WIN) |
| 447 DCHECK_NE(kind, GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED); |
| 448 #endif |
| 443 BrowserThread::PostTask( | 449 BrowserThread::PostTask( |
| 444 BrowserThread::IO, FROM_HERE, | 450 BrowserThread::IO, FROM_HERE, |
| 445 base::Bind(&RunCallbackOnIO, kind, force_create, callback)); | 451 base::Bind(&RunCallbackOnIO, kind, force_create, callback)); |
| 446 } | 452 } |
| 447 | 453 |
| 448 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { | 454 service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { |
| 449 return process_->child_connection()->GetRemoteInterfaces(); | 455 return process_->child_connection()->GetRemoteInterfaces(); |
| 450 } | 456 } |
| 451 | 457 |
| 452 // static | 458 // static |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 DCHECK(CalledOnValidThread()); | 681 DCHECK(CalledOnValidThread()); |
| 676 process_->GetHost()->AddFilter(filter); | 682 process_->GetHost()->AddFilter(filter); |
| 677 } | 683 } |
| 678 | 684 |
| 679 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 685 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 680 DCHECK(CalledOnValidThread()); | 686 DCHECK(CalledOnValidThread()); |
| 681 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 687 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| 682 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) | 688 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) |
| 683 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, | 689 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, |
| 684 OnGpuMemoryBufferCreated) | 690 OnGpuMemoryBufferCreated) |
| 685 #if defined(OS_ANDROID) | |
| 686 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyingVideoSurfaceAck, | |
| 687 OnDestroyingVideoSurfaceAck) | |
| 688 #endif | |
| 689 IPC_MESSAGE_HANDLER(GpuHostMsg_FieldTrialActivated, OnFieldTrialActivated); | 691 IPC_MESSAGE_HANDLER(GpuHostMsg_FieldTrialActivated, OnFieldTrialActivated); |
| 690 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 692 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
| 691 IPC_END_MESSAGE_MAP() | 693 IPC_END_MESSAGE_MAP() |
| 692 | 694 |
| 693 return true; | 695 return true; |
| 694 } | 696 } |
| 695 | 697 |
| 696 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { | 698 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { |
| 697 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); | 699 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); |
| 698 | 700 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 772 |
| 771 Send(new GpuMsg_DestroyGpuMemoryBuffer(id, client_id, sync_token)); | 773 Send(new GpuMsg_DestroyGpuMemoryBuffer(id, client_id, sync_token)); |
| 772 } | 774 } |
| 773 | 775 |
| 774 #if defined(OS_ANDROID) | 776 #if defined(OS_ANDROID) |
| 775 void GpuProcessHost::SendDestroyingVideoSurface(int surface_id, | 777 void GpuProcessHost::SendDestroyingVideoSurface(int surface_id, |
| 776 const base::Closure& done_cb) { | 778 const base::Closure& done_cb) { |
| 777 TRACE_EVENT0("gpu", "GpuProcessHost::SendDestroyingVideoSurface"); | 779 TRACE_EVENT0("gpu", "GpuProcessHost::SendDestroyingVideoSurface"); |
| 778 DCHECK(send_destroying_video_surface_done_cb_.is_null()); | 780 DCHECK(send_destroying_video_surface_done_cb_.is_null()); |
| 779 DCHECK(!done_cb.is_null()); | 781 DCHECK(!done_cb.is_null()); |
| 780 if (Send(new GpuMsg_DestroyingVideoSurface(surface_id))) { | 782 send_destroying_video_surface_done_cb_ = done_cb; |
| 781 send_destroying_video_surface_done_cb_ = done_cb; | 783 gpu_service_ptr_->DestroyingVideoSurface( |
| 782 } else { | 784 surface_id, base::Bind(&GpuProcessHost::OnDestroyingVideoSurfaceAck, |
| 783 done_cb.Run(); | 785 weak_ptr_factory_.GetWeakPtr())); |
| 784 } | |
| 785 } | 786 } |
| 786 #endif | 787 #endif |
| 787 | 788 |
| 788 void GpuProcessHost::OnInitialized( | 789 void GpuProcessHost::OnInitialized( |
| 789 bool result, | 790 bool result, |
| 790 const gpu::GPUInfo& gpu_info, | 791 const gpu::GPUInfo& gpu_info, |
| 791 const gpu::GpuFeatureInfo& gpu_feature_info) { | 792 const gpu::GpuFeatureInfo& gpu_feature_info) { |
| 792 UMA_HISTOGRAM_BOOLEAN("GPU.GPUProcessInitialized", result); | 793 UMA_HISTOGRAM_BOOLEAN("GPU.GPUProcessInitialized", result); |
| 793 initialized_ = result; | 794 initialized_ = result; |
| 794 gpu_info_ = gpu_info; | 795 gpu_info_ = gpu_info; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 807 mojo::ScopedMessagePipeHandle channel_handle) { | 808 mojo::ScopedMessagePipeHandle channel_handle) { |
| 808 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); | 809 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); |
| 809 DCHECK(!channel_requests_.empty()); | 810 DCHECK(!channel_requests_.empty()); |
| 810 DCHECK(channel_requests_.front().Equals(callback)); | 811 DCHECK(channel_requests_.front().Equals(callback)); |
| 811 channel_requests_.pop(); | 812 channel_requests_.pop(); |
| 812 | 813 |
| 813 // Currently if any of the GPU features are blacklisted, we don't establish a | 814 // Currently if any of the GPU features are blacklisted, we don't establish a |
| 814 // GPU channel. | 815 // GPU channel. |
| 815 if (channel_handle.is_valid() && | 816 if (channel_handle.is_valid() && |
| 816 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(nullptr)) { | 817 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(nullptr)) { |
| 817 Send(new GpuMsg_CloseChannel(client_id)); | 818 gpu_service_ptr_->CloseChannel(client_id); |
| 818 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 819 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 819 RouteOnUIThread( | 820 RouteOnUIThread( |
| 820 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", | 821 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", |
| 821 "Hardware acceleration is unavailable.")); | 822 "Hardware acceleration is unavailable.")); |
| 822 return; | 823 return; |
| 823 } | 824 } |
| 824 | 825 |
| 825 callback.Run(IPC::ChannelHandle(channel_handle.release()), gpu_info_); | 826 callback.Run(IPC::ChannelHandle(channel_handle.release()), gpu_info_); |
| 826 } | 827 } |
| 827 | 828 |
| 828 void GpuProcessHost::OnGpuMemoryBufferCreated( | 829 void GpuProcessHost::OnGpuMemoryBufferCreated( |
| 829 const gfx::GpuMemoryBufferHandle& handle) { | 830 const gfx::GpuMemoryBufferHandle& handle) { |
| 830 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); | 831 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); |
| 831 | 832 |
| 832 if (create_gpu_memory_buffer_requests_.empty()) | 833 if (create_gpu_memory_buffer_requests_.empty()) |
| 833 return; | 834 return; |
| 834 | 835 |
| 835 CreateGpuMemoryBufferCallback callback = | 836 CreateGpuMemoryBufferCallback callback = |
| 836 create_gpu_memory_buffer_requests_.front(); | 837 create_gpu_memory_buffer_requests_.front(); |
| 837 create_gpu_memory_buffer_requests_.pop(); | 838 create_gpu_memory_buffer_requests_.pop(); |
| 838 callback.Run(handle); | 839 callback.Run(handle); |
| 839 } | 840 } |
| 840 | 841 |
| 841 #if defined(OS_ANDROID) | 842 #if defined(OS_ANDROID) |
| 842 void GpuProcessHost::OnDestroyingVideoSurfaceAck(int surface_id) { | 843 void GpuProcessHost::OnDestroyingVideoSurfaceAck() { |
| 843 TRACE_EVENT0("gpu", "GpuProcessHost::OnDestroyingVideoSurfaceAck"); | 844 TRACE_EVENT0("gpu", "GpuProcessHost::OnDestroyingVideoSurfaceAck"); |
| 844 if (!send_destroying_video_surface_done_cb_.is_null()) | 845 if (!send_destroying_video_surface_done_cb_.is_null()) |
| 845 base::ResetAndReturn(&send_destroying_video_surface_done_cb_).Run(); | 846 base::ResetAndReturn(&send_destroying_video_surface_done_cb_).Run(); |
| 846 } | 847 } |
| 847 #endif | 848 #endif |
| 848 | 849 |
| 849 void GpuProcessHost::OnFieldTrialActivated(const std::string& trial_name) { | 850 void GpuProcessHost::OnFieldTrialActivated(const std::string& trial_name) { |
| 850 // Activate the trial in the browser process to match its state in the | 851 // Activate the trial in the browser process to match its state in the |
| 851 // GPU process. This is done by calling FindFullName which finalizes the group | 852 // GPU process. This is done by calling FindFullName which finalizes the group |
| 852 // and activates the trial. | 853 // and activates the trial. |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 &prefix); | 1194 &prefix); |
| 1194 return prefix; | 1195 return prefix; |
| 1195 } | 1196 } |
| 1196 | 1197 |
| 1197 void GpuProcessHost::LoadedShader(const std::string& key, | 1198 void GpuProcessHost::LoadedShader(const std::string& key, |
| 1198 const std::string& data) { | 1199 const std::string& data) { |
| 1199 std::string prefix = GetShaderPrefixKey(data); | 1200 std::string prefix = GetShaderPrefixKey(data); |
| 1200 bool prefix_ok = !key.compare(0, prefix.length(), prefix); | 1201 bool prefix_ok = !key.compare(0, prefix.length(), prefix); |
| 1201 UMA_HISTOGRAM_BOOLEAN("GPU.ShaderLoadPrefixOK", prefix_ok); | 1202 UMA_HISTOGRAM_BOOLEAN("GPU.ShaderLoadPrefixOK", prefix_ok); |
| 1202 if (prefix_ok) | 1203 if (prefix_ok) |
| 1203 Send(new GpuMsg_LoadedShader(data)); | 1204 gpu_service_ptr_->LoadedShader(data); |
| 1204 } | 1205 } |
| 1205 | 1206 |
| 1206 void GpuProcessHost::CreateChannelCache(int32_t client_id) { | 1207 void GpuProcessHost::CreateChannelCache(int32_t client_id) { |
| 1207 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); | 1208 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); |
| 1208 | 1209 |
| 1209 scoped_refptr<gpu::ShaderDiskCache> cache = | 1210 scoped_refptr<gpu::ShaderDiskCache> cache = |
| 1210 GetShaderCacheFactorySingleton()->Get(client_id); | 1211 GetShaderCacheFactorySingleton()->Get(client_id); |
| 1211 if (!cache.get()) | 1212 if (!cache.get()) |
| 1212 return; | 1213 return; |
| 1213 | 1214 |
| 1214 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); | 1215 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); |
| 1215 | 1216 |
| 1216 client_id_to_shader_cache_[client_id] = cache; | 1217 client_id_to_shader_cache_[client_id] = cache; |
| 1217 } | 1218 } |
| 1218 | 1219 |
| 1219 } // namespace content | 1220 } // namespace content |
| OLD | NEW |