| 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 base::Bind(&GpuProcessHostUIShim::Destroy, | 552 base::Bind(&GpuProcessHostUIShim::Destroy, |
| 553 host_id_, | 553 host_id_, |
| 554 message)); | 554 message)); |
| 555 } | 555 } |
| 556 | 556 |
| 557 bool GpuProcessHost::Init() { | 557 bool GpuProcessHost::Init() { |
| 558 init_start_time_ = base::TimeTicks::Now(); | 558 init_start_time_ = base::TimeTicks::Now(); |
| 559 | 559 |
| 560 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 560 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
| 561 | 561 |
| 562 std::string channel_id = process_->GetHost()->CreateChannel(); | 562 const std::string mojo_channel_token = |
| 563 if (channel_id.empty()) | 563 process_->GetHost()->CreateChannelMojo(child_token_); |
| 564 if (mojo_channel_token.empty()) |
| 564 return false; | 565 return false; |
| 565 | 566 |
| 566 DCHECK(!mojo_child_connection_); | 567 DCHECK(!mojo_child_connection_); |
| 567 mojo_child_connection_.reset(new MojoChildConnection( | 568 mojo_child_connection_.reset(new MojoChildConnection( |
| 568 kGpuMojoApplicationName, | 569 kGpuMojoApplicationName, |
| 569 "", | 570 "", |
| 570 child_token_, | 571 child_token_, |
| 571 MojoShellContext::GetConnectorForIOThread())); | 572 MojoShellContext::GetConnectorForIOThread())); |
| 572 | 573 |
| 573 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); | 574 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); |
| 574 if (in_process_) { | 575 if (in_process_) { |
| 575 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 576 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 576 DCHECK(g_gpu_main_thread_factory); | 577 DCHECK(g_gpu_main_thread_factory); |
| 577 in_process_gpu_thread_.reset(g_gpu_main_thread_factory( | 578 in_process_gpu_thread_.reset(g_gpu_main_thread_factory( |
| 578 InProcessChildThreadParams( | 579 InProcessChildThreadParams( |
| 579 channel_id, base::ThreadTaskRunnerHandle::Get(), std::string(), | 580 std::string(), base::ThreadTaskRunnerHandle::Get(), |
| 580 mojo_child_connection_->service_token()), | 581 mojo_channel_token, mojo_child_connection_->service_token()), |
| 581 gpu_preferences)); | 582 gpu_preferences)); |
| 582 base::Thread::Options options; | 583 base::Thread::Options options; |
| 583 #if defined(OS_WIN) | 584 #if defined(OS_WIN) |
| 584 // WGL needs to create its own window and pump messages on it. | 585 // WGL needs to create its own window and pump messages on it. |
| 585 options.message_loop_type = base::MessageLoop::TYPE_UI; | 586 options.message_loop_type = base::MessageLoop::TYPE_UI; |
| 586 #endif | 587 #endif |
| 587 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 588 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 588 options.priority = base::ThreadPriority::DISPLAY; | 589 options.priority = base::ThreadPriority::DISPLAY; |
| 589 #endif | 590 #endif |
| 590 in_process_gpu_thread_->StartWithOptions(options); | 591 in_process_gpu_thread_->StartWithOptions(options); |
| 591 | 592 |
| 592 OnProcessLaunched(); // Fake a callback that the process is ready. | 593 OnProcessLaunched(); // Fake a callback that the process is ready. |
| 593 } else if (!LaunchGpuProcess(channel_id, &gpu_preferences)) { | 594 } else if (!LaunchGpuProcess(mojo_channel_token, &gpu_preferences)) { |
| 594 return false; | 595 return false; |
| 595 } | 596 } |
| 596 | 597 |
| 597 if (!Send(new GpuMsg_Initialize(gpu_preferences))) | 598 if (!Send(new GpuMsg_Initialize(gpu_preferences))) |
| 598 return false; | 599 return false; |
| 599 | 600 |
| 600 return true; | 601 return true; |
| 601 } | 602 } |
| 602 | 603 |
| 603 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { | 604 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 if (g_gpu_process_hosts[kind_] == this) | 957 if (g_gpu_process_hosts[kind_] == this) |
| 957 g_gpu_process_hosts[kind_] = NULL; | 958 g_gpu_process_hosts[kind_] = NULL; |
| 958 | 959 |
| 959 process_->ForceShutdown(); | 960 process_->ForceShutdown(); |
| 960 } | 961 } |
| 961 | 962 |
| 962 void GpuProcessHost::StopGpuProcess() { | 963 void GpuProcessHost::StopGpuProcess() { |
| 963 Send(new GpuMsg_Finalize()); | 964 Send(new GpuMsg_Finalize()); |
| 964 } | 965 } |
| 965 | 966 |
| 966 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id, | 967 bool GpuProcessHost::LaunchGpuProcess(const std::string& mojo_channel_token, |
| 967 gpu::GpuPreferences* gpu_preferences) { | 968 gpu::GpuPreferences* gpu_preferences) { |
| 968 if (!(gpu_enabled_ && | 969 if (!(gpu_enabled_ && |
| 969 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) && | 970 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) && |
| 970 !hardware_gpu_enabled_) { | 971 !hardware_gpu_enabled_) { |
| 971 SendOutstandingReplies(); | 972 SendOutstandingReplies(); |
| 972 return false; | 973 return false; |
| 973 } | 974 } |
| 974 | 975 |
| 975 const base::CommandLine& browser_command_line = | 976 const base::CommandLine& browser_command_line = |
| 976 *base::CommandLine::ForCurrentProcess(); | 977 *base::CommandLine::ForCurrentProcess(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 992 int child_flags = ChildProcessHost::CHILD_NORMAL; | 993 int child_flags = ChildProcessHost::CHILD_NORMAL; |
| 993 #endif | 994 #endif |
| 994 | 995 |
| 995 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 996 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
| 996 if (exe_path.empty()) | 997 if (exe_path.empty()) |
| 997 return false; | 998 return false; |
| 998 | 999 |
| 999 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 1000 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
| 1000 #endif | 1001 #endif |
| 1001 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 1002 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
| 1002 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 1003 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
| 1003 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, | 1004 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
| 1004 mojo_child_connection_->service_token()); | 1005 mojo_child_connection_->service_token()); |
| 1005 BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(cmd_line); | 1006 BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(cmd_line); |
| 1006 | 1007 |
| 1007 #if defined(OS_WIN) | 1008 #if defined(OS_WIN) |
| 1008 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); | 1009 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); |
| 1009 #endif // defined(OS_WIN) | 1010 #endif // defined(OS_WIN) |
| 1010 | 1011 |
| 1011 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) | 1012 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) |
| 1012 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); | 1013 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1189 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1189 ClientIdToShaderCacheMap::iterator iter = | 1190 ClientIdToShaderCacheMap::iterator iter = |
| 1190 client_id_to_shader_cache_.find(client_id); | 1191 client_id_to_shader_cache_.find(client_id); |
| 1191 // If the cache doesn't exist then this is an off the record profile. | 1192 // If the cache doesn't exist then this is an off the record profile. |
| 1192 if (iter == client_id_to_shader_cache_.end()) | 1193 if (iter == client_id_to_shader_cache_.end()) |
| 1193 return; | 1194 return; |
| 1194 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1195 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1195 } | 1196 } |
| 1196 | 1197 |
| 1197 } // namespace content | 1198 } // namespace content |
| OLD | NEW |