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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "content/common/in_process_child_thread_params.h" | 36 #include "content/common/in_process_child_thread_params.h" |
37 #include "content/common/view_messages.h" | 37 #include "content/common/view_messages.h" |
38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/content_browser_client.h" | 39 #include "content/public/browser/content_browser_client.h" |
40 #include "content/public/browser/gpu_utils.h" | 40 #include "content/public/browser/gpu_utils.h" |
41 #include "content/public/browser/render_process_host.h" | 41 #include "content/public/browser/render_process_host.h" |
42 #include "content/public/browser/render_widget_host_view.h" | 42 #include "content/public/browser/render_widget_host_view.h" |
43 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 43 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
44 #include "content/public/common/content_client.h" | 44 #include "content/public/common/content_client.h" |
45 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
46 #include "content/public/common/mojo_channel_switches.h" | |
47 #include "content/public/common/result_codes.h" | 46 #include "content/public/common/result_codes.h" |
48 #include "content/public/common/sandbox_type.h" | 47 #include "content/public/common/sandbox_type.h" |
49 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 48 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
50 #include "gpu/command_buffer/service/gpu_preferences.h" | 49 #include "gpu/command_buffer/service/gpu_preferences.h" |
51 #include "gpu/command_buffer/service/gpu_switches.h" | 50 #include "gpu/command_buffer/service/gpu_switches.h" |
52 #include "ipc/ipc_channel_handle.h" | 51 #include "ipc/ipc_channel_handle.h" |
53 #include "ipc/ipc_switches.h" | 52 #include "ipc/ipc_switches.h" |
54 #include "ipc/message_filter.h" | 53 #include "ipc/message_filter.h" |
55 #include "media/base/media_switches.h" | 54 #include "media/base/media_switches.h" |
56 #include "ui/base/ui_base_switches.h" | 55 #include "ui/base/ui_base_switches.h" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 540 |
542 bool GpuProcessHost::Init() { | 541 bool GpuProcessHost::Init() { |
543 init_start_time_ = base::TimeTicks::Now(); | 542 init_start_time_ = base::TimeTicks::Now(); |
544 | 543 |
545 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 544 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
546 | 545 |
547 std::string channel_id = process_->GetHost()->CreateChannel(); | 546 std::string channel_id = process_->GetHost()->CreateChannel(); |
548 if (channel_id.empty()) | 547 if (channel_id.empty()) |
549 return false; | 548 return false; |
550 | 549 |
551 DCHECK(!mojo_application_host_); | 550 if (!SetupMojo()) |
552 mojo_application_host_.reset(new MojoApplicationHost); | 551 return false; |
553 | 552 |
554 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); | 553 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); |
555 if (in_process_) { | 554 if (in_process_) { |
556 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 555 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
557 DCHECK(g_gpu_main_thread_factory); | 556 DCHECK(g_gpu_main_thread_factory); |
558 in_process_gpu_thread_.reset( | 557 in_process_gpu_thread_.reset( |
559 g_gpu_main_thread_factory(InProcessChildThreadParams( | 558 g_gpu_main_thread_factory(InProcessChildThreadParams( |
560 channel_id, base::MessageLoop::current()->task_runner(), | 559 channel_id, base::MessageLoop::current()->task_runner()), |
561 std::string(), mojo_application_host_->GetToken()), | |
562 gpu_preferences)); | 560 gpu_preferences)); |
563 base::Thread::Options options; | 561 base::Thread::Options options; |
564 #if defined(OS_WIN) | 562 #if defined(OS_WIN) |
565 // WGL needs to create its own window and pump messages on it. | 563 // WGL needs to create its own window and pump messages on it. |
566 options.message_loop_type = base::MessageLoop::TYPE_UI; | 564 options.message_loop_type = base::MessageLoop::TYPE_UI; |
567 #endif | 565 #endif |
568 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 566 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
569 options.priority = base::ThreadPriority::DISPLAY; | 567 options.priority = base::ThreadPriority::DISPLAY; |
570 #endif | 568 #endif |
571 in_process_gpu_thread_->StartWithOptions(options); | 569 in_process_gpu_thread_->StartWithOptions(options); |
572 | 570 |
573 OnProcessLaunched(); // Fake a callback that the process is ready. | 571 OnProcessLaunched(); // Fake a callback that the process is ready. |
574 } else if (!LaunchGpuProcess(channel_id, &gpu_preferences)) { | 572 } else if (!LaunchGpuProcess(channel_id, &gpu_preferences)) { |
575 return false; | 573 return false; |
576 } | 574 } |
577 | 575 |
578 if (!Send(new GpuMsg_Initialize(gpu_preferences))) | 576 if (!Send(new GpuMsg_Initialize(gpu_preferences))) |
579 return false; | 577 return false; |
580 | 578 |
581 return true; | 579 return true; |
582 } | 580 } |
583 | 581 |
| 582 bool GpuProcessHost::SetupMojo() { |
| 583 DCHECK(!mojo_application_host_); |
| 584 mojo_application_host_.reset(new MojoApplicationHost); |
| 585 return mojo_application_host_->Init(); |
| 586 } |
| 587 |
584 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { | 588 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
585 BrowserThread::PostTask( | 589 BrowserThread::PostTask( |
586 BrowserThread::UI, | 590 BrowserThread::UI, |
587 FROM_HERE, | 591 FROM_HERE, |
588 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); | 592 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); |
589 } | 593 } |
590 | 594 |
591 bool GpuProcessHost::Send(IPC::Message* msg) { | 595 bool GpuProcessHost::Send(IPC::Message* msg) { |
592 DCHECK(CalledOnValidThread()); | 596 DCHECK(CalledOnValidThread()); |
593 if (process_->GetHost()->IsChannelOpening()) { | 597 if (process_->GetHost()->IsChannelOpening()) { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 #if defined(OS_MACOSX) | 901 #if defined(OS_MACOSX) |
898 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 902 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
899 const IPC::Message& message) { | 903 const IPC::Message& message) { |
900 RenderWidgetResizeHelper::PostGpuProcessMsg(host_id_, message); | 904 RenderWidgetResizeHelper::PostGpuProcessMsg(host_id_, message); |
901 } | 905 } |
902 #endif | 906 #endif |
903 | 907 |
904 void GpuProcessHost::OnProcessLaunched() { | 908 void GpuProcessHost::OnProcessLaunched() { |
905 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", | 909 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", |
906 base::TimeTicks::Now() - init_start_time_); | 910 base::TimeTicks::Now() - init_start_time_); |
| 911 |
| 912 base::ProcessHandle handle; |
| 913 if (in_process_) |
| 914 handle = base::GetCurrentProcessHandle(); |
| 915 else |
| 916 handle = process_->GetData().handle; |
| 917 |
| 918 mojo_application_host_->Activate(this, handle); |
907 } | 919 } |
908 | 920 |
909 void GpuProcessHost::OnProcessLaunchFailed() { | 921 void GpuProcessHost::OnProcessLaunchFailed() { |
910 RecordProcessCrash(); | 922 RecordProcessCrash(); |
911 } | 923 } |
912 | 924 |
913 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 925 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
914 SendOutstandingReplies(); | 926 SendOutstandingReplies(); |
915 RecordProcessCrash(); | 927 RecordProcessCrash(); |
916 GpuDataManagerImpl::GetInstance()->ProcessCrashed( | 928 GpuDataManagerImpl::GetInstance()->ProcessCrashed( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 #endif | 980 #endif |
969 | 981 |
970 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 982 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
971 if (exe_path.empty()) | 983 if (exe_path.empty()) |
972 return false; | 984 return false; |
973 | 985 |
974 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 986 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
975 #endif | 987 #endif |
976 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 988 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
977 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 989 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
978 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, | |
979 mojo_application_host_->GetToken()); | |
980 | 990 |
981 #if defined(OS_WIN) | 991 #if defined(OS_WIN) |
982 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) | 992 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) |
983 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); | 993 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); |
984 #endif // defined(OS_WIN) | 994 #endif // defined(OS_WIN) |
985 | 995 |
986 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) | 996 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) |
987 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); | 997 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
988 | 998 |
989 // TODO(penghuang): Replace all GPU related switches with GpuPreferences. | 999 // TODO(penghuang): Replace all GPU related switches with GpuPreferences. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1170 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1161 ClientIdToShaderCacheMap::iterator iter = | 1171 ClientIdToShaderCacheMap::iterator iter = |
1162 client_id_to_shader_cache_.find(client_id); | 1172 client_id_to_shader_cache_.find(client_id); |
1163 // If the cache doesn't exist then this is an off the record profile. | 1173 // If the cache doesn't exist then this is an off the record profile. |
1164 if (iter == client_id_to_shader_cache_.end()) | 1174 if (iter == client_id_to_shader_cache_.end()) |
1165 return; | 1175 return; |
1166 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1176 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1167 } | 1177 } |
1168 | 1178 |
1169 } // namespace content | 1179 } // namespace content |
OLD | NEW |