Chromium Code Reviews| 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> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 14 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 15 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 16 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
| 17 #include "content/browser/gpu/gpu_surface_tracker.h" | 17 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 18 #include "content/common/child_process_host_impl.h" | 18 #include "content/common/child_process_host_impl.h" |
| 19 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | |
| 19 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 20 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 20 #include "content/common/gpu/gpu_messages.h" | 21 #include "content/common/gpu/gpu_messages.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/gpu_data_manager.h" | 23 #include "content/public/browser/gpu_data_manager.h" |
| 23 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 24 #include "gpu/GLES2/gl2extchromium.h" | 25 #include "gpu/GLES2/gl2extchromium.h" |
| 25 #include "ipc/ipc_channel_handle.h" | 26 #include "ipc/ipc_channel_handle.h" |
| 26 #include "ipc/ipc_forwarding_message_filter.h" | 27 #include "ipc/ipc_forwarding_message_filter.h" |
| 27 #include "ipc/message_filter.h" | 28 #include "ipc/message_filter.h" |
| 28 | 29 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 g_enabled_gpu_memory_buffer_usages.Get().insert(usage); | 248 g_enabled_gpu_memory_buffer_usages.Get().insert(usage); |
| 248 } | 249 } |
| 249 | 250 |
| 250 // static | 251 // static |
| 251 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled( | 252 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled( |
| 252 gfx::GpuMemoryBuffer::Usage usage) { | 253 gfx::GpuMemoryBuffer::Usage usage) { |
| 253 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0; | 254 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0; |
| 254 } | 255 } |
| 255 | 256 |
| 256 // static | 257 // static |
| 257 uint32 BrowserGpuChannelHostFactory::GetImageTextureTarget() { | 258 uint32 BrowserGpuChannelHostFactory::GetImageTextureTarget( |
| 258 if (!IsGpuMemoryBufferFactoryUsageEnabled(gfx::GpuMemoryBuffer::MAP)) | 259 gfx::GpuMemoryBuffer::Format format, |
| 260 gfx::GpuMemoryBuffer::Usage usage) { | |
| 261 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) | |
| 259 return GL_TEXTURE_2D; | 262 return GL_TEXTURE_2D; |
| 260 | 263 |
| 261 std::vector<gfx::GpuMemoryBufferType> supported_types; | 264 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 262 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 265 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| 263 DCHECK(!supported_types.empty()); | 266 DCHECK(!supported_types.empty()); |
| 264 | 267 |
| 265 // The GPU service will always use the preferred type. | 268 // The GPU service will always use the preferred type, if the |format| and |
| 269 // |usage| allows. | |
| 266 gfx::GpuMemoryBufferType type = supported_types[0]; | 270 gfx::GpuMemoryBufferType type = supported_types[0]; |
| 271 // If the native buffer type does not support the |format| and |usage| then | |
| 272 // we must fallback to shared memory buffers, which do support them. | |
|
reveman
2015/05/20 14:26:07
The condition for |format| and |usage| not being s
danakj
2015/05/20 17:51:14
Done.
| |
| 273 if (!IsGpuMemoryBufferConfigurationSupportedInternal(format, usage)) { | |
| 274 DCHECK(GpuMemoryBufferImplSharedMemory::IsFormatSupported(format)); | |
| 275 DCHECK(GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)); | |
| 276 type = gfx::SHARED_MEMORY_BUFFER; | |
|
reveman
2015/05/20 14:26:08
I don't see a good reason for handling this differ
danakj
2015/05/20 17:51:14
Done.
| |
| 277 } | |
| 267 | 278 |
| 268 switch (type) { | 279 switch (type) { |
| 269 case gfx::SURFACE_TEXTURE_BUFFER: | 280 case gfx::SURFACE_TEXTURE_BUFFER: |
| 270 case gfx::OZONE_NATIVE_BUFFER: | 281 case gfx::OZONE_NATIVE_BUFFER: |
| 271 // GPU memory buffers that are shared with the GL using EGLImages require | 282 // GPU memory buffers that are shared with the GL using EGLImages require |
| 272 // TEXTURE_EXTERNAL_OES. | 283 // TEXTURE_EXTERNAL_OES. |
| 273 return GL_TEXTURE_EXTERNAL_OES; | 284 return GL_TEXTURE_EXTERNAL_OES; |
| 274 case gfx::IO_SURFACE_BUFFER: | 285 case gfx::IO_SURFACE_BUFFER: |
| 275 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. | 286 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. |
| 276 return GL_TEXTURE_RECTANGLE_ARB; | 287 return GL_TEXTURE_RECTANGLE_ARB; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 471 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 461 | 472 |
| 462 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 473 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
| 463 if (host) | 474 if (host) |
| 464 host->AddFilter(filter.get()); | 475 host->AddFilter(filter.get()); |
| 465 } | 476 } |
| 466 | 477 |
| 467 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( | 478 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( |
| 468 gfx::GpuMemoryBuffer::Format format, | 479 gfx::GpuMemoryBuffer::Format format, |
| 469 gfx::GpuMemoryBuffer::Usage usage) { | 480 gfx::GpuMemoryBuffer::Usage usage) { |
| 481 return IsGpuMemoryBufferConfigurationSupportedInternal(format, usage); | |
| 482 } | |
| 483 | |
| 484 // static | |
| 485 bool BrowserGpuChannelHostFactory:: | |
| 486 IsGpuMemoryBufferConfigurationSupportedInternal( | |
| 487 gfx::GpuMemoryBuffer::Format format, | |
| 488 gfx::GpuMemoryBuffer::Usage usage) { | |
| 470 // Return early if usage is not enabled. | 489 // Return early if usage is not enabled. |
| 471 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) | 490 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) |
|
reveman
2015/05/20 14:26:07
Please remove this check from this helper function
danakj
2015/05/20 17:51:14
Done.
| |
| 472 return false; | 491 return false; |
| 473 | 492 |
| 474 // Preferred type is always used by factory. | |
| 475 std::vector<gfx::GpuMemoryBufferType> supported_types; | 493 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 476 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 494 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
|
reveman
2015/05/20 14:26:07
Please pass the type as a parameter to this helper
danakj
2015/05/20 17:51:14
Done.
| |
| 477 DCHECK(!supported_types.empty()); | 495 DCHECK(!supported_types.empty()); |
| 478 switch (supported_types[0]) { | 496 switch (supported_types[0]) { |
| 479 case gfx::SHARED_MEMORY_BUFFER: | 497 case gfx::SHARED_MEMORY_BUFFER: |
| 480 // Shared memory buffers must be created in-process. | 498 // Shared memory buffers must be created in-process. |
| 481 return false; | 499 return false; |
| 482 #if defined(OS_MACOSX) | 500 #if defined(OS_MACOSX) |
| 483 case gfx::IO_SURFACE_BUFFER: | 501 case gfx::IO_SURFACE_BUFFER: |
| 484 return GpuMemoryBufferFactoryIOSurface:: | 502 return GpuMemoryBufferFactoryIOSurface:: |
| 485 IsGpuMemoryBufferConfigurationSupported(format, usage); | 503 IsGpuMemoryBufferConfigurationSupported(format, usage); |
| 486 #endif | 504 #endif |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 576 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 559 | 577 |
| 560 CreateGpuMemoryBufferCallbackMap::iterator iter = | 578 CreateGpuMemoryBufferCallbackMap::iterator iter = |
| 561 create_gpu_memory_buffer_requests_.find(request_id); | 579 create_gpu_memory_buffer_requests_.find(request_id); |
| 562 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 580 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
| 563 iter->second.Run(handle); | 581 iter->second.Run(handle); |
| 564 create_gpu_memory_buffer_requests_.erase(iter); | 582 create_gpu_memory_buffer_requests_.erase(iter); |
| 565 } | 583 } |
| 566 | 584 |
| 567 } // namespace content | 585 } // namespace content |
| OLD | NEW |