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" |
46 #include "content/public/common/result_codes.h" | 47 #include "content/public/common/result_codes.h" |
47 #include "content/public/common/sandbox_type.h" | 48 #include "content/public/common/sandbox_type.h" |
48 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 49 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
49 #include "gpu/command_buffer/service/gpu_preferences.h" | 50 #include "gpu/command_buffer/service/gpu_preferences.h" |
50 #include "gpu/command_buffer/service/gpu_switches.h" | 51 #include "gpu/command_buffer/service/gpu_switches.h" |
51 #include "ipc/ipc_channel_handle.h" | 52 #include "ipc/ipc_channel_handle.h" |
52 #include "ipc/ipc_switches.h" | 53 #include "ipc/ipc_switches.h" |
53 #include "ipc/message_filter.h" | 54 #include "ipc/message_filter.h" |
54 #include "media/base/media_switches.h" | 55 #include "media/base/media_switches.h" |
55 #include "ui/base/ui_base_switches.h" | 56 #include "ui/base/ui_base_switches.h" |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 531 |
531 bool GpuProcessHost::Init() { | 532 bool GpuProcessHost::Init() { |
532 init_start_time_ = base::TimeTicks::Now(); | 533 init_start_time_ = base::TimeTicks::Now(); |
533 | 534 |
534 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 535 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
535 | 536 |
536 std::string channel_id = process_->GetHost()->CreateChannel(); | 537 std::string channel_id = process_->GetHost()->CreateChannel(); |
537 if (channel_id.empty()) | 538 if (channel_id.empty()) |
538 return false; | 539 return false; |
539 | 540 |
540 if (!SetupMojo()) | 541 DCHECK(!mojo_application_host_); |
541 return false; | 542 mojo_application_host_.reset(new MojoApplicationHost); |
542 | 543 |
543 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); | 544 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); |
544 if (in_process_) { | 545 if (in_process_) { |
545 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 546 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
546 DCHECK(g_gpu_main_thread_factory); | 547 DCHECK(g_gpu_main_thread_factory); |
547 in_process_gpu_thread_.reset( | 548 in_process_gpu_thread_.reset( |
548 g_gpu_main_thread_factory(InProcessChildThreadParams( | 549 g_gpu_main_thread_factory(InProcessChildThreadParams( |
549 channel_id, base::MessageLoop::current()->task_runner()), | 550 channel_id, base::MessageLoop::current()->task_runner(), |
| 551 std::string(), mojo_application_host_->GetToken()), |
550 gpu_preferences)); | 552 gpu_preferences)); |
551 base::Thread::Options options; | 553 base::Thread::Options options; |
552 #if defined(OS_WIN) | 554 #if defined(OS_WIN) |
553 // WGL needs to create its own window and pump messages on it. | 555 // WGL needs to create its own window and pump messages on it. |
554 options.message_loop_type = base::MessageLoop::TYPE_UI; | 556 options.message_loop_type = base::MessageLoop::TYPE_UI; |
555 #endif | 557 #endif |
556 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 558 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
557 options.priority = base::ThreadPriority::DISPLAY; | 559 options.priority = base::ThreadPriority::DISPLAY; |
558 #endif | 560 #endif |
559 in_process_gpu_thread_->StartWithOptions(options); | 561 in_process_gpu_thread_->StartWithOptions(options); |
560 | 562 |
561 OnProcessLaunched(); // Fake a callback that the process is ready. | 563 OnProcessLaunched(); // Fake a callback that the process is ready. |
562 } else if (!LaunchGpuProcess(channel_id, &gpu_preferences)) { | 564 } else if (!LaunchGpuProcess(channel_id, &gpu_preferences)) { |
563 return false; | 565 return false; |
564 } | 566 } |
565 | 567 |
566 if (!Send(new GpuMsg_Initialize(gpu_preferences))) | 568 if (!Send(new GpuMsg_Initialize(gpu_preferences))) |
567 return false; | 569 return false; |
568 | 570 |
569 return true; | 571 return true; |
570 } | 572 } |
571 | 573 |
572 bool GpuProcessHost::SetupMojo() { | |
573 DCHECK(!mojo_application_host_); | |
574 mojo_application_host_.reset(new MojoApplicationHost); | |
575 return mojo_application_host_->Init(); | |
576 } | |
577 | |
578 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { | 574 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
579 BrowserThread::PostTask( | 575 BrowserThread::PostTask( |
580 BrowserThread::UI, | 576 BrowserThread::UI, |
581 FROM_HERE, | 577 FROM_HERE, |
582 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); | 578 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); |
583 } | 579 } |
584 | 580 |
585 bool GpuProcessHost::Send(IPC::Message* msg) { | 581 bool GpuProcessHost::Send(IPC::Message* msg) { |
586 DCHECK(CalledOnValidThread()); | 582 DCHECK(CalledOnValidThread()); |
587 if (process_->GetHost()->IsChannelOpening()) { | 583 if (process_->GetHost()->IsChannelOpening()) { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 #if defined(OS_MACOSX) | 887 #if defined(OS_MACOSX) |
892 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 888 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
893 const IPC::Message& message) { | 889 const IPC::Message& message) { |
894 RenderWidgetResizeHelper::PostGpuProcessMsg(host_id_, message); | 890 RenderWidgetResizeHelper::PostGpuProcessMsg(host_id_, message); |
895 } | 891 } |
896 #endif | 892 #endif |
897 | 893 |
898 void GpuProcessHost::OnProcessLaunched() { | 894 void GpuProcessHost::OnProcessLaunched() { |
899 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", | 895 UMA_HISTOGRAM_TIMES("GPU.GPUProcessLaunchTime", |
900 base::TimeTicks::Now() - init_start_time_); | 896 base::TimeTicks::Now() - init_start_time_); |
901 | |
902 base::ProcessHandle handle; | |
903 if (in_process_) | |
904 handle = base::GetCurrentProcessHandle(); | |
905 else | |
906 handle = process_->GetData().handle; | |
907 | |
908 mojo_application_host_->Activate(this, handle); | |
909 } | 897 } |
910 | 898 |
911 void GpuProcessHost::OnProcessLaunchFailed() { | 899 void GpuProcessHost::OnProcessLaunchFailed() { |
912 RecordProcessCrash(); | 900 RecordProcessCrash(); |
913 } | 901 } |
914 | 902 |
915 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 903 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
916 SendOutstandingReplies(); | 904 SendOutstandingReplies(); |
917 RecordProcessCrash(); | 905 RecordProcessCrash(); |
918 GpuDataManagerImpl::GetInstance()->ProcessCrashed( | 906 GpuDataManagerImpl::GetInstance()->ProcessCrashed( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 #endif | 958 #endif |
971 | 959 |
972 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 960 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
973 if (exe_path.empty()) | 961 if (exe_path.empty()) |
974 return false; | 962 return false; |
975 | 963 |
976 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 964 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
977 #endif | 965 #endif |
978 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 966 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
979 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 967 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 968 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
| 969 mojo_application_host_->GetToken()); |
980 | 970 |
981 #if defined(OS_WIN) | 971 #if defined(OS_WIN) |
982 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) | 972 if (GetContentClient()->browser()->ShouldUseWindowsPrefetchArgument()) |
983 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); | 973 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); |
984 #endif // defined(OS_WIN) | 974 #endif // defined(OS_WIN) |
985 | 975 |
986 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) | 976 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) |
987 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); | 977 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
988 | 978 |
989 // TODO(penghuang): Replace all GPU related switches with GpuPreferences. | 979 // 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"); | 1150 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1161 ClientIdToShaderCacheMap::iterator iter = | 1151 ClientIdToShaderCacheMap::iterator iter = |
1162 client_id_to_shader_cache_.find(client_id); | 1152 client_id_to_shader_cache_.find(client_id); |
1163 // If the cache doesn't exist then this is an off the record profile. | 1153 // If the cache doesn't exist then this is an off the record profile. |
1164 if (iter == client_id_to_shader_cache_.end()) | 1154 if (iter == client_id_to_shader_cache_.end()) |
1165 return; | 1155 return; |
1166 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1156 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1167 } | 1157 } |
1168 | 1158 |
1169 } // namespace content | 1159 } // namespace content |
OLD | NEW |