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/browser_gpu_channel_host_factory.h" | 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
8 #include "base/location.h" | 9 #include "base/location.h" |
9 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
14 #include "base/trace_event/memory_dump_manager.h" | 15 #include "base/trace_event/memory_dump_manager.h" |
15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
16 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 17 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
17 #include "content/browser/gpu/gpu_data_manager_impl.h" | 18 #include "content/browser/gpu/gpu_data_manager_impl.h" |
18 #include "content/browser/gpu/gpu_process_host.h" | 19 #include "content/browser/gpu/gpu_process_host.h" |
19 #include "content/browser/gpu/gpu_surface_tracker.h" | 20 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 21 #include "content/browser/gpu/shader_disk_cache.h" |
20 #include "content/common/child_process_host_impl.h" | 22 #include "content/common/child_process_host_impl.h" |
21 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/browser/gpu_data_manager.h" | 26 #include "content/public/browser/gpu_data_manager.h" |
24 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
| 28 #include "gpu/command_buffer/service/gpu_switches.h" |
25 #include "ipc/ipc_channel_handle.h" | 29 #include "ipc/ipc_channel_handle.h" |
26 #include "ipc/message_filter.h" | 30 #include "ipc/message_filter.h" |
27 | 31 |
28 namespace content { | 32 namespace content { |
29 | 33 |
30 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 34 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
31 | 35 |
32 struct BrowserGpuChannelHostFactory::CreateRequest { | 36 struct BrowserGpuChannelHostFactory::CreateRequest { |
33 CreateRequest(int32 route_id) | 37 CreateRequest(int32 route_id) |
34 : event(true, false), | 38 : event(true, false), |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 instance_ = NULL; | 235 instance_ = NULL; |
232 } | 236 } |
233 | 237 |
234 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 238 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
235 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 239 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
236 gpu_client_tracing_id_(ChildProcessHost::kBrowserTracingProcessId), | 240 gpu_client_tracing_id_(ChildProcessHost::kBrowserTracingProcessId), |
237 shutdown_event_(new base::WaitableEvent(true, false)), | 241 shutdown_event_(new base::WaitableEvent(true, false)), |
238 gpu_memory_buffer_manager_( | 242 gpu_memory_buffer_manager_( |
239 new BrowserGpuMemoryBufferManager(gpu_client_id_, | 243 new BrowserGpuMemoryBufferManager(gpu_client_id_, |
240 gpu_client_tracing_id_)), | 244 gpu_client_tracing_id_)), |
241 gpu_host_id_(0) {} | 245 gpu_host_id_(0) { |
| 246 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 247 switches::kDisableGpuShaderDiskCache)) { |
| 248 DCHECK(GetContentClient()); |
| 249 base::FilePath cache_dir = |
| 250 GetContentClient()->browser()->GetShaderDiskCacheDirectory(); |
| 251 if (!cache_dir.empty()) { |
| 252 GetIOThreadTaskRunner()->PostTask( |
| 253 FROM_HERE, |
| 254 base::Bind( |
| 255 &BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO, |
| 256 gpu_client_id_, cache_dir)); |
| 257 } else { |
| 258 LOG(ERROR) << "Failed to init browser shader disk cache."; |
| 259 } |
| 260 } |
| 261 } |
242 | 262 |
243 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 263 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
244 DCHECK(IsMainThread()); | 264 DCHECK(IsMainThread()); |
245 if (pending_request_.get()) | 265 if (pending_request_.get()) |
246 pending_request_->Cancel(); | 266 pending_request_->Cancel(); |
247 for (size_t n = 0; n < established_callbacks_.size(); n++) | 267 for (size_t n = 0; n < established_callbacks_.size(); n++) |
248 established_callbacks_[n].Run(); | 268 established_callbacks_[n].Run(); |
249 shutdown_event_->Signal(); | 269 shutdown_event_->Signal(); |
250 if (gpu_channel_) { | 270 if (gpu_channel_) { |
251 gpu_channel_->DestroyChannel(); | 271 gpu_channel_->DestroyChannel(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 void BrowserGpuChannelHostFactory::AddFilterOnIO( | 432 void BrowserGpuChannelHostFactory::AddFilterOnIO( |
413 int host_id, | 433 int host_id, |
414 scoped_refptr<IPC::MessageFilter> filter) { | 434 scoped_refptr<IPC::MessageFilter> filter) { |
415 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 435 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
416 | 436 |
417 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 437 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
418 if (host) | 438 if (host) |
419 host->AddFilter(filter.get()); | 439 host->AddFilter(filter.get()); |
420 } | 440 } |
421 | 441 |
| 442 // static |
| 443 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( |
| 444 int gpu_client_id, |
| 445 const base::FilePath& cache_dir) { |
| 446 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir); |
| 447 } |
| 448 |
422 } // namespace content | 449 } // namespace content |
OLD | NEW |