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 <set> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
9 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
11 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 14 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
13 #include "content/browser/gpu/gpu_data_manager_impl.h" | 15 #include "content/browser/gpu/gpu_data_manager_impl.h" |
14 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
15 #include "content/browser/gpu/gpu_surface_tracker.h" | 17 #include "content/browser/gpu/gpu_surface_tracker.h" |
16 #include "content/common/child_process_host_impl.h" | 18 #include "content/common/child_process_host_impl.h" |
(...skipping 12 matching lines...) Expand all Loading... |
29 | 31 |
30 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
31 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" | 33 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" |
32 #endif | 34 #endif |
33 | 35 |
34 #if defined(USE_OZONE) | 36 #if defined(USE_OZONE) |
35 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" | 37 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" |
36 #endif | 38 #endif |
37 | 39 |
38 namespace content { | 40 namespace content { |
| 41 namespace { |
| 42 |
| 43 base::LazyInstance<std::set<gfx::GpuMemoryBuffer::Usage>> |
| 44 g_enabled_gpu_memory_buffer_usages; |
| 45 } |
39 | 46 |
40 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 47 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
41 | 48 |
42 struct BrowserGpuChannelHostFactory::CreateRequest { | 49 struct BrowserGpuChannelHostFactory::CreateRequest { |
43 CreateRequest(int32 route_id) | 50 CreateRequest(int32 route_id) |
44 : event(true, false), | 51 : event(true, false), |
45 gpu_host_id(0), | 52 gpu_host_id(0), |
46 route_id(route_id), | 53 route_id(route_id), |
47 result(CREATE_COMMAND_BUFFER_FAILED) {} | 54 result(CREATE_COMMAND_BUFFER_FAILED) {} |
48 ~CreateRequest() {} | 55 ~CreateRequest() {} |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 base::Closure()); | 232 base::Closure()); |
226 } | 233 } |
227 } | 234 } |
228 | 235 |
229 void BrowserGpuChannelHostFactory::Terminate() { | 236 void BrowserGpuChannelHostFactory::Terminate() { |
230 DCHECK(instance_); | 237 DCHECK(instance_); |
231 delete instance_; | 238 delete instance_; |
232 instance_ = NULL; | 239 instance_ = NULL; |
233 } | 240 } |
234 | 241 |
| 242 // static |
| 243 void BrowserGpuChannelHostFactory::EnableGpuMemoryBufferFactoryUsage( |
| 244 gfx::GpuMemoryBuffer::Usage usage) { |
| 245 g_enabled_gpu_memory_buffer_usages.Get().insert(usage); |
| 246 } |
| 247 |
| 248 // static |
| 249 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled( |
| 250 gfx::GpuMemoryBuffer::Usage usage) { |
| 251 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0; |
| 252 } |
| 253 |
235 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 254 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
236 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 255 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
237 shutdown_event_(new base::WaitableEvent(true, false)), | 256 shutdown_event_(new base::WaitableEvent(true, false)), |
238 gpu_memory_buffer_manager_( | 257 gpu_memory_buffer_manager_( |
239 new BrowserGpuMemoryBufferManager(this, gpu_client_id_)), | 258 new BrowserGpuMemoryBufferManager(this, gpu_client_id_)), |
240 gpu_host_id_(0), | 259 gpu_host_id_(0), |
241 next_create_gpu_memory_buffer_request_id_(0) { | 260 next_create_gpu_memory_buffer_request_id_(0) { |
242 } | 261 } |
243 | 262 |
244 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 263 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 GetIOLoopProxy()->PostTask( | 440 GetIOLoopProxy()->PostTask( |
422 FROM_HERE, | 441 FROM_HERE, |
423 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, | 442 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, |
424 gpu_host_id_, | 443 gpu_host_id_, |
425 filter)); | 444 filter)); |
426 } | 445 } |
427 | 446 |
428 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( | 447 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( |
429 gfx::GpuMemoryBuffer::Format format, | 448 gfx::GpuMemoryBuffer::Format format, |
430 gfx::GpuMemoryBuffer::Usage usage) { | 449 gfx::GpuMemoryBuffer::Usage usage) { |
| 450 // Return early if usage is not enabled. |
| 451 if (IsGpuMemoryBufferFactoryUsageEnabled(usage)) |
| 452 return false; |
| 453 |
431 // Preferred type is always used by factory. | 454 // Preferred type is always used by factory. |
432 std::vector<gfx::GpuMemoryBufferType> supported_types; | 455 std::vector<gfx::GpuMemoryBufferType> supported_types; |
433 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 456 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
434 DCHECK(!supported_types.empty()); | 457 DCHECK(!supported_types.empty()); |
435 switch (supported_types[0]) { | 458 switch (supported_types[0]) { |
436 case gfx::SHARED_MEMORY_BUFFER: | 459 case gfx::SHARED_MEMORY_BUFFER: |
437 // Shared memory buffers must be created in-process. | 460 // Shared memory buffers must be created in-process. |
438 return false; | 461 return false; |
439 #if defined(OS_MACOSX) | 462 #if defined(OS_MACOSX) |
440 case gfx::IO_SURFACE_BUFFER: | 463 case gfx::IO_SURFACE_BUFFER: |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
520 | 543 |
521 CreateGpuMemoryBufferCallbackMap::iterator iter = | 544 CreateGpuMemoryBufferCallbackMap::iterator iter = |
522 create_gpu_memory_buffer_requests_.find(request_id); | 545 create_gpu_memory_buffer_requests_.find(request_id); |
523 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 546 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
524 iter->second.Run(handle); | 547 iter->second.Run(handle); |
525 create_gpu_memory_buffer_requests_.erase(iter); | 548 create_gpu_memory_buffer_requests_.erase(iter); |
526 } | 549 } |
527 | 550 |
528 } // namespace content | 551 } // namespace content |
OLD | NEW |