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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "content/public/common/mojo_channel_switches.h" | 45 #include "content/public/common/mojo_channel_switches.h" |
46 #include "content/public/common/result_codes.h" | 46 #include "content/public/common/result_codes.h" |
47 #include "content/public/common/sandbox_type.h" | 47 #include "content/public/common/sandbox_type.h" |
48 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 48 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
49 #include "gpu/command_buffer/service/gpu_preferences.h" | 49 #include "gpu/command_buffer/service/gpu_preferences.h" |
50 #include "gpu/command_buffer/service/gpu_switches.h" | 50 #include "gpu/command_buffer/service/gpu_switches.h" |
51 #include "ipc/ipc_channel_handle.h" | 51 #include "ipc/ipc_channel_handle.h" |
52 #include "ipc/ipc_switches.h" | 52 #include "ipc/ipc_switches.h" |
53 #include "ipc/message_filter.h" | 53 #include "ipc/message_filter.h" |
54 #include "media/base/media_switches.h" | 54 #include "media/base/media_switches.h" |
| 55 #include "mojo/edk/embedder/embedder.h" |
55 #include "ui/base/ui_base_switches.h" | 56 #include "ui/base/ui_base_switches.h" |
56 #include "ui/events/latency_info.h" | 57 #include "ui/events/latency_info.h" |
57 #include "ui/gl/gl_switches.h" | 58 #include "ui/gl/gl_switches.h" |
58 | 59 |
59 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
60 #include "base/android/build_info.h" | 61 #include "base/android/build_info.h" |
61 #endif | 62 #endif |
62 | 63 |
63 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
64 #include "base/win/windows_version.h" | 65 #include "base/win/windows_version.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 401 } |
401 | 402 |
402 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 403 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
403 : host_id_(host_id), | 404 : host_id_(host_id), |
404 valid_(true), | 405 valid_(true), |
405 in_process_(false), | 406 in_process_(false), |
406 swiftshader_rendering_(false), | 407 swiftshader_rendering_(false), |
407 kind_(kind), | 408 kind_(kind), |
408 process_launched_(false), | 409 process_launched_(false), |
409 initialized_(false), | 410 initialized_(false), |
410 uma_memory_stats_received_(false) { | 411 uma_memory_stats_received_(false), |
| 412 child_token_(mojo::edk::GenerateRandomToken()) { |
411 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 413 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
412 switches::kSingleProcess) || | 414 switches::kSingleProcess) || |
413 base::CommandLine::ForCurrentProcess()->HasSwitch( | 415 base::CommandLine::ForCurrentProcess()->HasSwitch( |
414 switches::kInProcessGPU)) { | 416 switches::kInProcessGPU)) { |
415 in_process_ = true; | 417 in_process_ = true; |
416 } | 418 } |
417 | 419 |
418 // If the 'single GPU process' policy ever changes, we still want to maintain | 420 // If the 'single GPU process' policy ever changes, we still want to maintain |
419 // it for 'gpu thread' mode and only create one instance of host and thread. | 421 // it for 'gpu thread' mode and only create one instance of host and thread. |
420 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); | 422 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); |
421 | 423 |
422 g_gpu_process_hosts[kind] = this; | 424 g_gpu_process_hosts[kind] = this; |
423 | 425 |
424 // Post a task to create the corresponding GpuProcessHostUIShim. The | 426 // Post a task to create the corresponding GpuProcessHostUIShim. The |
425 // GpuProcessHostUIShim will be destroyed if either the browser exits, | 427 // GpuProcessHostUIShim will be destroyed if either the browser exits, |
426 // in which case it calls GpuProcessHostUIShim::DestroyAll, or the | 428 // in which case it calls GpuProcessHostUIShim::DestroyAll, or the |
427 // GpuProcessHost is destroyed, which happens when the corresponding GPU | 429 // GpuProcessHost is destroyed, which happens when the corresponding GPU |
428 // process terminates or fails to launch. | 430 // process terminates or fails to launch. |
429 BrowserThread::PostTask( | 431 BrowserThread::PostTask( |
430 BrowserThread::UI, | 432 BrowserThread::UI, |
431 FROM_HERE, | 433 FROM_HERE, |
432 base::Bind(base::IgnoreResult(&GpuProcessHostUIShim::Create), host_id)); | 434 base::Bind(base::IgnoreResult(&GpuProcessHostUIShim::Create), host_id)); |
433 | 435 |
434 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_GPU, this)); | 436 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_GPU, this, |
| 437 child_token_)); |
435 } | 438 } |
436 | 439 |
437 GpuProcessHost::~GpuProcessHost() { | 440 GpuProcessHost::~GpuProcessHost() { |
438 DCHECK(CalledOnValidThread()); | 441 DCHECK(CalledOnValidThread()); |
439 | 442 |
440 SendOutstandingReplies(); | 443 SendOutstandingReplies(); |
441 | 444 |
442 // In case we never started, clean up. | 445 // In case we never started, clean up. |
443 while (!queued_messages_.empty()) { | 446 while (!queued_messages_.empty()) { |
444 delete queued_messages_.front(); | 447 delete queued_messages_.front(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 bool GpuProcessHost::Init() { | 540 bool GpuProcessHost::Init() { |
538 init_start_time_ = base::TimeTicks::Now(); | 541 init_start_time_ = base::TimeTicks::Now(); |
539 | 542 |
540 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 543 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
541 | 544 |
542 std::string channel_id = process_->GetHost()->CreateChannel(); | 545 std::string channel_id = process_->GetHost()->CreateChannel(); |
543 if (channel_id.empty()) | 546 if (channel_id.empty()) |
544 return false; | 547 return false; |
545 | 548 |
546 DCHECK(!mojo_application_host_); | 549 DCHECK(!mojo_application_host_); |
547 mojo_application_host_.reset(new MojoApplicationHost); | 550 mojo_application_host_.reset(new MojoApplicationHost(child_token_)); |
548 | 551 |
549 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); | 552 gpu::GpuPreferences gpu_preferences = GetGpuPreferencesFromCommandLine(); |
550 if (in_process_) { | 553 if (in_process_) { |
551 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 554 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
552 DCHECK(g_gpu_main_thread_factory); | 555 DCHECK(g_gpu_main_thread_factory); |
553 in_process_gpu_thread_.reset( | 556 in_process_gpu_thread_.reset( |
554 g_gpu_main_thread_factory(InProcessChildThreadParams( | 557 g_gpu_main_thread_factory(InProcessChildThreadParams( |
555 channel_id, base::MessageLoop::current()->task_runner(), | 558 channel_id, base::MessageLoop::current()->task_runner(), |
556 std::string(), mojo_application_host_->GetToken()), | 559 std::string(), mojo_application_host_->GetToken()), |
557 gpu_preferences)); | 560 gpu_preferences)); |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1181 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1179 ClientIdToShaderCacheMap::iterator iter = | 1182 ClientIdToShaderCacheMap::iterator iter = |
1180 client_id_to_shader_cache_.find(client_id); | 1183 client_id_to_shader_cache_.find(client_id); |
1181 // If the cache doesn't exist then this is an off the record profile. | 1184 // If the cache doesn't exist then this is an off the record profile. |
1182 if (iter == client_id_to_shader_cache_.end()) | 1185 if (iter == client_id_to_shader_cache_.end()) |
1183 return; | 1186 return; |
1184 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1187 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1185 } | 1188 } |
1186 | 1189 |
1187 } // namespace content | 1190 } // namespace content |
OLD | NEW |