| 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 CauseForGpuLaunch cause, | 134 CauseForGpuLaunch cause, |
| 135 IPC::Message* message) { | 135 IPC::Message* message) { |
| 136 GpuProcessHost* host = GpuProcessHost::Get(kind, cause); | 136 GpuProcessHost* host = GpuProcessHost::Get(kind, cause); |
| 137 if (host) { | 137 if (host) { |
| 138 host->Send(message); | 138 host->Send(message); |
| 139 } else { | 139 } else { |
| 140 delete message; | 140 delete message; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SendGpuProcessUpdateValueStateMessage(int client_id, |
| 145 unsigned int target, |
| 146 const gpu::ValueState& state) { |
| 147 GpuProcessHost* host = GpuProcessHost::Get( |
| 148 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| 149 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH); |
| 150 if (host) |
| 151 host->SendUpdateValueState(client_id, target, state); |
| 152 } |
| 153 |
| 144 // NOTE: changes to this class need to be reviewed by the security team. | 154 // NOTE: changes to this class need to be reviewed by the security team. |
| 145 class GpuSandboxedProcessLauncherDelegate | 155 class GpuSandboxedProcessLauncherDelegate |
| 146 : public SandboxedProcessLauncherDelegate { | 156 : public SandboxedProcessLauncherDelegate { |
| 147 public: | 157 public: |
| 148 GpuSandboxedProcessLauncherDelegate(base::CommandLine* cmd_line, | 158 GpuSandboxedProcessLauncherDelegate(base::CommandLine* cmd_line, |
| 149 ChildProcessHost* host) | 159 ChildProcessHost* host) |
| 150 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
| 151 : cmd_line_(cmd_line) {} | 161 : cmd_line_(cmd_line) {} |
| 152 #elif defined(OS_POSIX) | 162 #elif defined(OS_POSIX) |
| 153 : ipc_fd_(host->TakeClientFileDescriptor()) {} | 163 : ipc_fd_(host->TakeClientFileDescriptor()) {} |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 CauseForGpuLaunch cause, | 352 CauseForGpuLaunch cause, |
| 343 IPC::Message* message) { | 353 IPC::Message* message) { |
| 344 if (!BrowserThread::PostTask( | 354 if (!BrowserThread::PostTask( |
| 345 BrowserThread::IO, FROM_HERE, | 355 BrowserThread::IO, FROM_HERE, |
| 346 base::Bind( | 356 base::Bind( |
| 347 &SendGpuProcessMessage, kind, cause, message))) { | 357 &SendGpuProcessMessage, kind, cause, message))) { |
| 348 delete message; | 358 delete message; |
| 349 } | 359 } |
| 350 } | 360 } |
| 351 | 361 |
| 362 //static |
| 363 void GpuProcessHost::SendUpdateValueStateOnIOThread( |
| 364 int client_id, unsigned int target, const gpu::ValueState& state) { |
| 365 BrowserThread::PostTask( |
| 366 BrowserThread::IO, FROM_HERE, |
| 367 base::Bind(&SendGpuProcessUpdateValueStateMessage, |
| 368 client_id, target, state)); |
| 369 } |
| 370 |
| 352 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; | 371 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; |
| 353 | 372 |
| 354 void GpuProcessHost::RegisterGpuMainThreadFactory( | 373 void GpuProcessHost::RegisterGpuMainThreadFactory( |
| 355 GpuMainThreadFactoryFunction create) { | 374 GpuMainThreadFactoryFunction create) { |
| 356 g_gpu_main_thread_factory = create; | 375 g_gpu_main_thread_factory = create; |
| 357 } | 376 } |
| 358 | 377 |
| 359 // static | 378 // static |
| 360 GpuProcessHost* GpuProcessHost::FromID(int host_id) { | 379 GpuProcessHost* GpuProcessHost::FromID(int host_id) { |
| 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, | 594 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, |
| 576 OnGpuMemoryUmaStatsReceived) | 595 OnGpuMemoryUmaStatsReceived) |
| 577 #if defined(OS_MACOSX) | 596 #if defined(OS_MACOSX) |
| 578 IPC_MESSAGE_HANDLER_GENERIC(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 597 IPC_MESSAGE_HANDLER_GENERIC(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 579 OnAcceleratedSurfaceBuffersSwapped(message)) | 598 OnAcceleratedSurfaceBuffersSwapped(message)) |
| 580 #endif | 599 #endif |
| 581 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyChannel, | 600 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyChannel, |
| 582 OnDestroyChannel) | 601 OnDestroyChannel) |
| 583 IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader, | 602 IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader, |
| 584 OnCacheShader) | 603 OnCacheShader) |
| 585 | 604 IPC_MESSAGE_HANDLER(GpuHostMsg_AddSubscription, OnAddSubscription) |
| 605 IPC_MESSAGE_HANDLER(GpuHostMsg_RemoveSubscription, OnRemoveSubscription) |
| 586 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 606 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
| 587 IPC_END_MESSAGE_MAP() | 607 IPC_END_MESSAGE_MAP() |
| 588 | 608 |
| 589 return true; | 609 return true; |
| 590 } | 610 } |
| 591 | 611 |
| 592 void GpuProcessHost::OnChannelConnected(int32 peer_pid) { | 612 void GpuProcessHost::OnChannelConnected(int32 peer_pid) { |
| 593 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); | 613 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); |
| 594 | 614 |
| 595 while (!queued_messages_.empty()) { | 615 while (!queued_messages_.empty()) { |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 return shader_prefix_key_; | 1052 return shader_prefix_key_; |
| 1033 } | 1053 } |
| 1034 | 1054 |
| 1035 void GpuProcessHost::LoadedShader(const std::string& key, | 1055 void GpuProcessHost::LoadedShader(const std::string& key, |
| 1036 const std::string& data) { | 1056 const std::string& data) { |
| 1037 std::string prefix = GetShaderPrefixKey(); | 1057 std::string prefix = GetShaderPrefixKey(); |
| 1038 if (!key.compare(0, prefix.length(), prefix)) | 1058 if (!key.compare(0, prefix.length(), prefix)) |
| 1039 Send(new GpuMsg_LoadedShader(data)); | 1059 Send(new GpuMsg_LoadedShader(data)); |
| 1040 } | 1060 } |
| 1041 | 1061 |
| 1062 void GpuProcessHost::SendUpdateValueState(int client_id, |
| 1063 unsigned int target, |
| 1064 const gpu::ValueState& state) { |
| 1065 // Only send data if a valuebuffer is subscribed to the target |
| 1066 if (subscription_set_.find(target) != subscription_set_.end()) { |
| 1067 Send(new GpuMsg_UpdateValueState(client_id, target, state)); |
| 1068 } |
| 1069 } |
| 1070 |
| 1042 void GpuProcessHost::CreateChannelCache(int32 client_id) { | 1071 void GpuProcessHost::CreateChannelCache(int32 client_id) { |
| 1043 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); | 1072 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); |
| 1044 | 1073 |
| 1045 scoped_refptr<ShaderDiskCache> cache = | 1074 scoped_refptr<ShaderDiskCache> cache = |
| 1046 ShaderCacheFactory::GetInstance()->Get(client_id); | 1075 ShaderCacheFactory::GetInstance()->Get(client_id); |
| 1047 if (!cache.get()) | 1076 if (!cache.get()) |
| 1048 return; | 1077 return; |
| 1049 | 1078 |
| 1050 cache->set_host_id(host_id_); | 1079 cache->set_host_id(host_id_); |
| 1051 | 1080 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1062 const std::string& shader) { | 1091 const std::string& shader) { |
| 1063 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1092 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1064 ClientIdToShaderCacheMap::iterator iter = | 1093 ClientIdToShaderCacheMap::iterator iter = |
| 1065 client_id_to_shader_cache_.find(client_id); | 1094 client_id_to_shader_cache_.find(client_id); |
| 1066 // If the cache doesn't exist then this is an off the record profile. | 1095 // If the cache doesn't exist then this is an off the record profile. |
| 1067 if (iter == client_id_to_shader_cache_.end()) | 1096 if (iter == client_id_to_shader_cache_.end()) |
| 1068 return; | 1097 return; |
| 1069 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1098 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1070 } | 1099 } |
| 1071 | 1100 |
| 1101 void GpuProcessHost::OnAddSubscription(unsigned int target) { |
| 1102 subscription_set_.insert(target); |
| 1103 } |
| 1104 |
| 1105 void GpuProcessHost::OnRemoveSubscription(unsigned int target) { |
| 1106 subscription_set_.erase(target); |
| 1107 } |
| 1108 |
| 1072 } // namespace content | 1109 } // namespace content |
| OLD | NEW |