| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 GetIOLoopProxy()->PostTask( | 435 GetIOLoopProxy()->PostTask( |
| 417 FROM_HERE, | 436 FROM_HERE, |
| 418 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, | 437 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, |
| 419 gpu_host_id_, | 438 gpu_host_id_, |
| 420 filter)); | 439 filter)); |
| 421 } | 440 } |
| 422 | 441 |
| 423 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( | 442 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( |
| 424 gfx::GpuMemoryBuffer::Format format, | 443 gfx::GpuMemoryBuffer::Format format, |
| 425 gfx::GpuMemoryBuffer::Usage usage) { | 444 gfx::GpuMemoryBuffer::Usage usage) { |
| 445 // Return early if usage is not enabled. |
| 446 if (IsGpuMemoryBufferFactoryUsageEnabled(usage)) |
| 447 return false; |
| 448 |
| 426 // Preferred type is always used by factory. | 449 // Preferred type is always used by factory. |
| 427 std::vector<gfx::GpuMemoryBufferType> supported_types; | 450 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 428 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 451 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| 429 DCHECK(!supported_types.empty()); | 452 DCHECK(!supported_types.empty()); |
| 430 switch (supported_types[0]) { | 453 switch (supported_types[0]) { |
| 431 case gfx::SHARED_MEMORY_BUFFER: | 454 case gfx::SHARED_MEMORY_BUFFER: |
| 432 // Shared memory buffers must be created in-process. | 455 // Shared memory buffers must be created in-process. |
| 433 return false; | 456 return false; |
| 434 #if defined(OS_MACOSX) | 457 #if defined(OS_MACOSX) |
| 435 case gfx::IO_SURFACE_BUFFER: | 458 case gfx::IO_SURFACE_BUFFER: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 515 | 538 |
| 516 CreateGpuMemoryBufferCallbackMap::iterator iter = | 539 CreateGpuMemoryBufferCallbackMap::iterator iter = |
| 517 create_gpu_memory_buffer_requests_.find(request_id); | 540 create_gpu_memory_buffer_requests_.find(request_id); |
| 518 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 541 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
| 519 iter->second.Run(handle); | 542 iter->second.Run(handle); |
| 520 create_gpu_memory_buffer_requests_.erase(iter); | 543 create_gpu_memory_buffer_requests_.erase(iter); |
| 521 } | 544 } |
| 522 | 545 |
| 523 } // namespace content | 546 } // namespace content |
| OLD | NEW |