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 GetIOThreadTaskRunner()->PostTask( | |
247 FROM_HERE, | |
248 base::Bind(&BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO, | |
249 base::Unretained(this))); | |
piman
2015/08/07 19:33:59
Unretained seems unsafe.
How about testing the co
Jamie Madill
2015/08/07 20:07:58
Done.
| |
250 } | |
242 | 251 |
243 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 252 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
244 DCHECK(IsMainThread()); | 253 DCHECK(IsMainThread()); |
245 if (pending_request_.get()) | 254 if (pending_request_.get()) |
246 pending_request_->Cancel(); | 255 pending_request_->Cancel(); |
247 for (size_t n = 0; n < established_callbacks_.size(); n++) | 256 for (size_t n = 0; n < established_callbacks_.size(); n++) |
248 established_callbacks_[n].Run(); | 257 established_callbacks_[n].Run(); |
249 shutdown_event_->Signal(); | 258 shutdown_event_->Signal(); |
250 if (gpu_channel_) { | 259 if (gpu_channel_) { |
251 gpu_channel_->DestroyChannel(); | 260 gpu_channel_->DestroyChannel(); |
252 gpu_channel_ = NULL; | 261 gpu_channel_ = NULL; |
253 } | 262 } |
254 } | 263 } |
255 | 264 |
265 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO() { | |
266 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
267 switches::kDisableGpuShaderDiskCache)) { | |
268 base::FilePath cache_dir = | |
269 GetContentClient()->browser()->GetShaderDiskCacheDirectory(); | |
270 if (!cache_dir.empty()) { | |
271 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id_, | |
272 cache_dir); | |
273 } else { | |
274 LOG(ERROR) << "Failed to init browser shader disk cache."; | |
275 } | |
276 } | |
277 } | |
278 | |
256 bool BrowserGpuChannelHostFactory::IsMainThread() { | 279 bool BrowserGpuChannelHostFactory::IsMainThread() { |
257 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 280 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
258 } | 281 } |
259 | 282 |
260 scoped_refptr<base::SingleThreadTaskRunner> | 283 scoped_refptr<base::SingleThreadTaskRunner> |
261 BrowserGpuChannelHostFactory::GetIOThreadTaskRunner() { | 284 BrowserGpuChannelHostFactory::GetIOThreadTaskRunner() { |
262 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 285 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
263 } | 286 } |
264 | 287 |
265 scoped_ptr<base::SharedMemory> | 288 scoped_ptr<base::SharedMemory> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 int host_id, | 436 int host_id, |
414 scoped_refptr<IPC::MessageFilter> filter) { | 437 scoped_refptr<IPC::MessageFilter> filter) { |
415 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 438 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
416 | 439 |
417 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 440 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
418 if (host) | 441 if (host) |
419 host->AddFilter(filter.get()); | 442 host->AddFilter(filter.get()); |
420 } | 443 } |
421 | 444 |
422 } // namespace content | 445 } // namespace content |
OLD | NEW |