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