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 16 matching lines...) Expand all Loading... |
27 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "components/tracing/common/tracing_switches.h" | 29 #include "components/tracing/common/tracing_switches.h" |
30 #include "content/browser/browser_child_process_host_impl.h" | 30 #include "content/browser/browser_child_process_host_impl.h" |
31 #include "content/browser/browser_main_loop.h" | 31 #include "content/browser/browser_main_loop.h" |
32 #include "content/browser/gpu/compositor_util.h" | 32 #include "content/browser/gpu/compositor_util.h" |
33 #include "content/browser/gpu/gpu_data_manager_impl.h" | 33 #include "content/browser/gpu/gpu_data_manager_impl.h" |
34 #include "content/browser/gpu/gpu_main_thread_factory.h" | 34 #include "content/browser/gpu/gpu_main_thread_factory.h" |
35 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 35 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
36 #include "content/browser/gpu/shader_cache_factory.h" | 36 #include "content/browser/gpu/shader_cache_factory.h" |
37 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
38 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber
.h" | |
39 #include "content/browser/service_manager/service_manager_context.h" | 37 #include "content/browser/service_manager/service_manager_context.h" |
40 #include "content/common/child_process_host_impl.h" | 38 #include "content/common/child_process_host_impl.h" |
41 #include "content/common/in_process_child_thread_params.h" | 39 #include "content/common/in_process_child_thread_params.h" |
42 #include "content/common/service_manager/child_connection.h" | 40 #include "content/common/service_manager/child_connection.h" |
43 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
44 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
45 #include "content/public/browser/content_browser_client.h" | 43 #include "content/public/browser/content_browser_client.h" |
46 #include "content/public/browser/gpu_utils.h" | 44 #include "content/public/browser/gpu_utils.h" |
47 #include "content/public/browser/render_process_host.h" | |
48 #include "content/public/browser/render_widget_host_view.h" | |
49 #include "content/public/common/connection_filter.h" | 45 #include "content/public/common/connection_filter.h" |
50 #include "content/public/common/content_client.h" | 46 #include "content/public/common/content_client.h" |
51 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
52 #include "content/public/common/mojo_channel_switches.h" | 48 #include "content/public/common/mojo_channel_switches.h" |
53 #include "content/public/common/result_codes.h" | 49 #include "content/public/common/result_codes.h" |
54 #include "content/public/common/sandbox_type.h" | 50 #include "content/public/common/sandbox_type.h" |
55 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 51 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
56 #include "content/public/common/service_manager_connection.h" | 52 #include "content/public/common/service_manager_connection.h" |
57 #include "content/public/common/service_names.mojom.h" | 53 #include "content/public/common/service_names.mojom.h" |
58 #include "gpu/command_buffer/service/gpu_preferences.h" | 54 #include "gpu/command_buffer/service/gpu_preferences.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; | 187 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; |
192 | 188 |
193 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind, | 189 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind, |
194 bool force_create, | 190 bool force_create, |
195 const base::Callback<void(GpuProcessHost*)>& callback) { | 191 const base::Callback<void(GpuProcessHost*)>& callback) { |
196 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create); | 192 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create); |
197 callback.Run(host); | 193 callback.Run(host); |
198 } | 194 } |
199 | 195 |
200 #if defined(USE_OZONE) | 196 #if defined(USE_OZONE) |
201 void SendGpuProcessMessageByHostId(int host_id, IPC::Message* message) { | 197 void SendGpuProcessMessage(base::WeakPtr<GpuProcessHost> host, |
202 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 198 IPC::Message* message) { |
203 if (host) { | 199 if (host) |
204 host->Send(message); | 200 host->Send(message); |
205 } else { | 201 else |
206 delete message; | 202 delete message; |
207 } | |
208 } | 203 } |
209 #endif | 204 #endif // defined(USE_OZONE) |
210 | 205 |
211 // NOTE: changes to this class need to be reviewed by the security team. | 206 // NOTE: changes to this class need to be reviewed by the security team. |
212 class GpuSandboxedProcessLauncherDelegate | 207 class GpuSandboxedProcessLauncherDelegate |
213 : public SandboxedProcessLauncherDelegate { | 208 : public SandboxedProcessLauncherDelegate { |
214 public: | 209 public: |
215 explicit GpuSandboxedProcessLauncherDelegate( | 210 explicit GpuSandboxedProcessLauncherDelegate( |
216 const base::CommandLine& cmd_line) | 211 const base::CommandLine& cmd_line) |
217 #if defined(OS_WIN) | 212 #if defined(OS_WIN) |
218 : cmd_line_(cmd_line) | 213 : cmd_line_(cmd_line) |
219 #endif | 214 #endif |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 SandboxType GetSandboxType() override { | 299 SandboxType GetSandboxType() override { |
305 return SANDBOX_TYPE_GPU; | 300 return SANDBOX_TYPE_GPU; |
306 } | 301 } |
307 | 302 |
308 private: | 303 private: |
309 #if defined(OS_WIN) | 304 #if defined(OS_WIN) |
310 base::CommandLine cmd_line_; | 305 base::CommandLine cmd_line_; |
311 #endif // OS_WIN | 306 #endif // OS_WIN |
312 }; | 307 }; |
313 | 308 |
314 void HostLoadedShader(int host_id, | |
315 const std::string& key, | |
316 const std::string& data) { | |
317 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | |
318 if (host) | |
319 host->LoadedShader(key, data); | |
320 } | |
321 | |
322 } // anonymous namespace | 309 } // anonymous namespace |
323 | 310 |
324 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { | 311 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { |
325 public: | 312 public: |
326 ConnectionFilterImpl() { | 313 ConnectionFilterImpl() { |
327 GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces(®istry_); | 314 GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces(®istry_); |
328 } | 315 } |
329 | 316 |
330 private: | 317 private: |
331 // ConnectionFilter: | 318 // ConnectionFilter: |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 gpu_main_ptr_->CreateGpuService( | 611 gpu_main_ptr_->CreateGpuService( |
625 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(), | 612 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(), |
626 gpu_preferences, activity_flags_.CloneHandle()); | 613 gpu_preferences, activity_flags_.CloneHandle()); |
627 | 614 |
628 #if defined(USE_OZONE) | 615 #if defined(USE_OZONE) |
629 // Ozone needs to send the primary DRM device to GPU process as early as | 616 // Ozone needs to send the primary DRM device to GPU process as early as |
630 // possible to ensure the latter always has a valid device. crbug.com/608839 | 617 // possible to ensure the latter always has a valid device. crbug.com/608839 |
631 ui::OzonePlatform::GetInstance() | 618 ui::OzonePlatform::GetInstance() |
632 ->GetGpuPlatformSupportHost() | 619 ->GetGpuPlatformSupportHost() |
633 ->OnGpuProcessLaunched( | 620 ->OnGpuProcessLaunched( |
634 host_id_, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), | 621 host_id_, base::ThreadTaskRunnerHandle::Get(), |
635 base::Bind(&SendGpuProcessMessageByHostId, host_id_)); | 622 base::Bind(&SendGpuProcessMessage, weak_ptr_factory_.GetWeakPtr())); |
636 #endif | 623 #endif |
637 | 624 |
638 return true; | 625 return true; |
639 } | 626 } |
640 | 627 |
641 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { | 628 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
642 BrowserThread::PostTask( | 629 BrowserThread::PostTask( |
643 BrowserThread::UI, | 630 BrowserThread::UI, |
644 FROM_HERE, | 631 FROM_HERE, |
645 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); | 632 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); |
646 } | 633 } |
647 | 634 |
648 bool GpuProcessHost::Send(IPC::Message* msg) { | 635 bool GpuProcessHost::Send(IPC::Message* msg) { |
649 DCHECK(CalledOnValidThread()); | 636 DCHECK(CalledOnValidThread()); |
650 if (process_->GetHost()->IsChannelOpening()) { | 637 if (process_->GetHost()->IsChannelOpening()) { |
651 queued_messages_.push(msg); | 638 queued_messages_.push(msg); |
652 return true; | 639 return true; |
653 } | 640 } |
654 | 641 |
655 bool result = process_->Send(msg); | 642 bool result = process_->Send(msg); |
656 if (!result) { | 643 if (!result) { |
657 // Channel is hosed, but we may not get destroyed for a while. Send | 644 // Channel is hosed, but we may not get destroyed for a while. Send |
658 // outstanding channel creation failures now so that the caller can restart | 645 // outstanding channel creation failures now so that the caller can restart |
659 // with a new process/channel without waiting. | 646 // with a new process/channel without waiting. |
660 SendOutstandingReplies(); | 647 SendOutstandingReplies(); |
661 } | 648 } |
662 return result; | 649 return result; |
663 } | 650 } |
664 | 651 |
665 void GpuProcessHost::AddFilter(IPC::MessageFilter* filter) { | |
666 DCHECK(CalledOnValidThread()); | |
667 process_->GetHost()->AddFilter(filter); | |
668 } | |
669 | |
670 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 652 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
671 DCHECK(CalledOnValidThread()); | 653 DCHECK(CalledOnValidThread()); |
672 RouteOnUIThread(message); | 654 RouteOnUIThread(message); |
673 return true; | 655 return true; |
674 } | 656 } |
675 | 657 |
676 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { | 658 void GpuProcessHost::OnChannelConnected(int32_t peer_pid) { |
677 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); | 659 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); |
678 | 660 |
679 while (!queued_messages_.empty()) { | 661 while (!queued_messages_.empty()) { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 } | 1168 } |
1187 | 1169 |
1188 void GpuProcessHost::CreateChannelCache(int32_t client_id) { | 1170 void GpuProcessHost::CreateChannelCache(int32_t client_id) { |
1189 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); | 1171 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); |
1190 | 1172 |
1191 scoped_refptr<gpu::ShaderDiskCache> cache = | 1173 scoped_refptr<gpu::ShaderDiskCache> cache = |
1192 GetShaderCacheFactorySingleton()->Get(client_id); | 1174 GetShaderCacheFactorySingleton()->Get(client_id); |
1193 if (!cache.get()) | 1175 if (!cache.get()) |
1194 return; | 1176 return; |
1195 | 1177 |
1196 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); | 1178 cache->set_shader_loaded_callback(base::Bind(&GpuProcessHost::LoadedShader, |
| 1179 weak_ptr_factory_.GetWeakPtr())); |
1197 | 1180 |
1198 client_id_to_shader_cache_[client_id] = cache; | 1181 client_id_to_shader_cache_[client_id] = cache; |
1199 } | 1182 } |
1200 | 1183 |
1201 } // namespace content | 1184 } // namespace content |
OLD | NEW |