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