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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 base::Bind(&GpuProcessHostUIShim::Destroy, | 539 base::Bind(&GpuProcessHostUIShim::Destroy, |
540 host_id_, | 540 host_id_, |
541 message)); | 541 message)); |
542 } | 542 } |
543 | 543 |
544 bool GpuProcessHost::Init() { | 544 bool GpuProcessHost::Init() { |
545 init_start_time_ = base::TimeTicks::Now(); | 545 init_start_time_ = base::TimeTicks::Now(); |
546 | 546 |
547 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 547 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
548 | 548 |
549 std::string channel_id = process_->GetHost()->CreateChannel(); | 549 const std::string mojo_channel_token = |
550 if (channel_id.empty()) | 550 process_->GetHost()->CreateChannelMojo(child_token_); |
| 551 if (mojo_channel_token.empty()) |
551 return false; | 552 return false; |
552 | 553 |
553 DCHECK(!mojo_application_host_); | 554 DCHECK(!mojo_application_host_); |
554 mojo_application_host_.reset(new MojoApplicationHost(child_token_)); | 555 mojo_application_host_.reset(new MojoApplicationHost(child_token_)); |
555 | 556 |
556 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); | 557 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); |
557 if (in_process_) { | 558 if (in_process_) { |
558 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 559 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
559 DCHECK(g_gpu_main_thread_factory); | 560 DCHECK(g_gpu_main_thread_factory); |
560 in_process_gpu_thread_.reset(g_gpu_main_thread_factory( | 561 in_process_gpu_thread_.reset(g_gpu_main_thread_factory( |
561 InProcessChildThreadParams( | 562 InProcessChildThreadParams( |
562 channel_id, base::ThreadTaskRunnerHandle::Get(), std::string(), | 563 std::string(), base::ThreadTaskRunnerHandle::Get(), |
563 mojo_application_host_->GetToken()), | 564 mojo_channel_token, mojo_application_host_->GetToken()), |
564 gpu_preferences)); | 565 gpu_preferences)); |
565 base::Thread::Options options; | 566 base::Thread::Options options; |
566 #if defined(OS_WIN) | 567 #if defined(OS_WIN) |
567 // WGL needs to create its own window and pump messages on it. | 568 // WGL needs to create its own window and pump messages on it. |
568 options.message_loop_type = base::MessageLoop::TYPE_UI; | 569 options.message_loop_type = base::MessageLoop::TYPE_UI; |
569 #endif | 570 #endif |
570 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 571 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
571 options.priority = base::ThreadPriority::DISPLAY; | 572 options.priority = base::ThreadPriority::DISPLAY; |
572 #endif | 573 #endif |
573 in_process_gpu_thread_->StartWithOptions(options); | 574 in_process_gpu_thread_->StartWithOptions(options); |
574 | 575 |
575 OnProcessLaunched(); // Fake a callback that the process is ready. | 576 OnProcessLaunched(); // Fake a callback that the process is ready. |
576 } else if (!LaunchGpuProcess(channel_id, &gpu_preferences)) { | 577 } else if (!LaunchGpuProcess(mojo_channel_token, &gpu_preferences)) { |
577 return false; | 578 return false; |
578 } | 579 } |
579 | 580 |
580 if (!Send(new GpuMsg_Initialize(gpu_preferences))) | 581 if (!Send(new GpuMsg_Initialize(gpu_preferences))) |
581 return false; | 582 return false; |
582 | 583 |
583 return true; | 584 return true; |
584 } | 585 } |
585 | 586 |
586 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { | 587 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 RouteOnUIThread(GpuHostMsg_OnLogMessage( | 823 RouteOnUIThread(GpuHostMsg_OnLogMessage( |
823 logging::LOG_WARNING, "WARNING", | 824 logging::LOG_WARNING, "WARNING", |
824 "Received a ChannelEstablished message but no requests in queue.")); | 825 "Received a ChannelEstablished message but no requests in queue.")); |
825 return; | 826 return; |
826 } | 827 } |
827 EstablishChannelRequest request = channel_requests_.front(); | 828 EstablishChannelRequest request = channel_requests_.front(); |
828 channel_requests_.pop(); | 829 channel_requests_.pop(); |
829 | 830 |
830 // Currently if any of the GPU features are blacklisted, we don't establish a | 831 // Currently if any of the GPU features are blacklisted, we don't establish a |
831 // GPU channel. | 832 // GPU channel. |
832 if (!channel_handle.name.empty() && | 833 if (channel_handle.mojo_handle.is_valid() && |
833 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { | 834 !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { |
834 Send(new GpuMsg_CloseChannel(request.client_id)); | 835 Send(new GpuMsg_CloseChannel(request.client_id)); |
835 request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 836 request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
836 RouteOnUIThread( | 837 RouteOnUIThread( |
837 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", | 838 GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", |
838 "Hardware acceleration is unavailable.")); | 839 "Hardware acceleration is unavailable.")); |
839 return; | 840 return; |
840 } | 841 } |
841 | 842 |
842 request.callback.Run(channel_handle, gpu_info_); | 843 request.callback.Run(channel_handle, gpu_info_); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 if (g_gpu_process_hosts[kind_] == this) | 960 if (g_gpu_process_hosts[kind_] == this) |
960 g_gpu_process_hosts[kind_] = NULL; | 961 g_gpu_process_hosts[kind_] = NULL; |
961 | 962 |
962 process_->ForceShutdown(); | 963 process_->ForceShutdown(); |
963 } | 964 } |
964 | 965 |
965 void GpuProcessHost::StopGpuProcess() { | 966 void GpuProcessHost::StopGpuProcess() { |
966 Send(new GpuMsg_Finalize()); | 967 Send(new GpuMsg_Finalize()); |
967 } | 968 } |
968 | 969 |
969 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id, | 970 bool GpuProcessHost::LaunchGpuProcess(const std::string& mojo_channel_token, |
970 gpu::GpuPreferences* gpu_preferences) { | 971 gpu::GpuPreferences* gpu_preferences) { |
971 if (!(gpu_enabled_ && | 972 if (!(gpu_enabled_ && |
972 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) && | 973 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) && |
973 !hardware_gpu_enabled_) { | 974 !hardware_gpu_enabled_) { |
974 SendOutstandingReplies(); | 975 SendOutstandingReplies(); |
975 return false; | 976 return false; |
976 } | 977 } |
977 | 978 |
978 const base::CommandLine& browser_command_line = | 979 const base::CommandLine& browser_command_line = |
979 *base::CommandLine::ForCurrentProcess(); | 980 *base::CommandLine::ForCurrentProcess(); |
(...skipping 15 matching lines...) Expand all Loading... |
995 int child_flags = ChildProcessHost::CHILD_NORMAL; | 996 int child_flags = ChildProcessHost::CHILD_NORMAL; |
996 #endif | 997 #endif |
997 | 998 |
998 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 999 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
999 if (exe_path.empty()) | 1000 if (exe_path.empty()) |
1000 return false; | 1001 return false; |
1001 | 1002 |
1002 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 1003 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
1003 #endif | 1004 #endif |
1004 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 1005 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
1005 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 1006 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
1006 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, | 1007 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
1007 mojo_application_host_->GetToken()); | 1008 mojo_application_host_->GetToken()); |
1008 BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(cmd_line); | 1009 BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(cmd_line); |
1009 | 1010 |
1010 #if defined(OS_WIN) | 1011 #if defined(OS_WIN) |
1011 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); | 1012 cmd_line->AppendArg(switches::kPrefetchArgumentGpu); |
1012 #endif // defined(OS_WIN) | 1013 #endif // defined(OS_WIN) |
1013 | 1014 |
1014 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) | 1015 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) |
1015 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); | 1016 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1192 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1192 ClientIdToShaderCacheMap::iterator iter = | 1193 ClientIdToShaderCacheMap::iterator iter = |
1193 client_id_to_shader_cache_.find(client_id); | 1194 client_id_to_shader_cache_.find(client_id); |
1194 // If the cache doesn't exist then this is an off the record profile. | 1195 // If the cache doesn't exist then this is an off the record profile. |
1195 if (iter == client_id_to_shader_cache_.end()) | 1196 if (iter == client_id_to_shader_cache_.end()) |
1196 return; | 1197 return; |
1197 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1198 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1198 } | 1199 } |
1199 | 1200 |
1200 } // namespace content | 1201 } // namespace content |
OLD | NEW |