| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 #if defined(USE_OZONE) | 37 #if defined(USE_OZONE) |
| 38 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" | 38 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace content { | 41 namespace content { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 base::LazyInstance<std::set<gfx::GpuMemoryBuffer::Usage>> | 44 base::LazyInstance<std::set<gfx::GpuMemoryBuffer::Usage>> |
| 45 g_enabled_gpu_memory_buffer_usages; | 45 g_enabled_gpu_memory_buffer_usages; |
| 46 | |
| 47 bool IsGpuMemoryBufferFactoryConfigurationSupported( | |
| 48 gfx::GpuMemoryBuffer::Format format, | |
| 49 gfx::GpuMemoryBuffer::Usage usage, | |
| 50 gfx::GpuMemoryBufferType type) { | |
| 51 switch (type) { | |
| 52 case gfx::SHARED_MEMORY_BUFFER: | |
| 53 // Shared memory buffers must be created in-process. | |
| 54 return false; | |
| 55 #if defined(OS_MACOSX) | |
| 56 case gfx::IO_SURFACE_BUFFER: | |
| 57 return GpuMemoryBufferFactoryIOSurface:: | |
| 58 IsGpuMemoryBufferConfigurationSupported(format, usage); | |
| 59 #endif | |
| 60 #if defined(OS_ANDROID) | |
| 61 case gfx::SURFACE_TEXTURE_BUFFER: | |
| 62 return GpuMemoryBufferFactorySurfaceTexture:: | |
| 63 IsGpuMemoryBufferConfigurationSupported(format, usage); | |
| 64 #endif | |
| 65 #if defined(USE_OZONE) | |
| 66 case gfx::OZONE_NATIVE_BUFFER: | |
| 67 return GpuMemoryBufferFactoryOzoneNativeBuffer:: | |
| 68 IsGpuMemoryBufferConfigurationSupported(format, usage); | |
| 69 #endif | |
| 70 default: | |
| 71 NOTREACHED(); | |
| 72 return false; | |
| 73 } | |
| 74 } | 46 } |
| 75 | 47 |
| 76 } // namespace | |
| 77 | |
| 78 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 48 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
| 79 | 49 |
| 80 struct BrowserGpuChannelHostFactory::CreateRequest { | 50 struct BrowserGpuChannelHostFactory::CreateRequest { |
| 81 CreateRequest(int32 route_id) | 51 CreateRequest(int32 route_id) |
| 82 : event(true, false), | 52 : event(true, false), |
| 83 gpu_host_id(0), | 53 gpu_host_id(0), |
| 84 route_id(route_id), | 54 route_id(route_id), |
| 85 result(CREATE_COMMAND_BUFFER_FAILED) {} | 55 result(CREATE_COMMAND_BUFFER_FAILED) {} |
| 86 ~CreateRequest() {} | 56 ~CreateRequest() {} |
| 87 base::WaitableEvent event; | 57 base::WaitableEvent event; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 g_enabled_gpu_memory_buffer_usages.Get().insert(usage); | 247 g_enabled_gpu_memory_buffer_usages.Get().insert(usage); |
| 278 } | 248 } |
| 279 | 249 |
| 280 // static | 250 // static |
| 281 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled( | 251 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled( |
| 282 gfx::GpuMemoryBuffer::Usage usage) { | 252 gfx::GpuMemoryBuffer::Usage usage) { |
| 283 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0; | 253 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0; |
| 284 } | 254 } |
| 285 | 255 |
| 286 // static | 256 // static |
| 287 uint32 BrowserGpuChannelHostFactory::GetImageTextureTarget( | 257 uint32 BrowserGpuChannelHostFactory::GetImageTextureTarget() { |
| 288 gfx::GpuMemoryBuffer::Format format, | 258 if (!IsGpuMemoryBufferFactoryUsageEnabled(gfx::GpuMemoryBuffer::MAP)) |
| 289 gfx::GpuMemoryBuffer::Usage usage) { | |
| 290 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) | |
| 291 return GL_TEXTURE_2D; | 259 return GL_TEXTURE_2D; |
| 292 | 260 |
| 293 std::vector<gfx::GpuMemoryBufferType> supported_types; | 261 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 294 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 262 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| 295 DCHECK(!supported_types.empty()); | 263 DCHECK(!supported_types.empty()); |
| 296 | 264 |
| 297 // The GPU service will always use the preferred type, if the |format| and | 265 // The GPU service will always use the preferred type. |
| 298 // |usage| allows. | |
| 299 gfx::GpuMemoryBufferType type = supported_types[0]; | 266 gfx::GpuMemoryBufferType type = supported_types[0]; |
| 300 | 267 |
| 301 if (!IsGpuMemoryBufferFactoryConfigurationSupported(format, usage, type)) | |
| 302 return GL_TEXTURE_2D; | |
| 303 | |
| 304 switch (type) { | 268 switch (type) { |
| 305 case gfx::SURFACE_TEXTURE_BUFFER: | 269 case gfx::SURFACE_TEXTURE_BUFFER: |
| 306 case gfx::OZONE_NATIVE_BUFFER: | 270 case gfx::OZONE_NATIVE_BUFFER: |
| 307 // GPU memory buffers that are shared with the GL using EGLImages require | 271 // GPU memory buffers that are shared with the GL using EGLImages require |
| 308 // TEXTURE_EXTERNAL_OES. | 272 // TEXTURE_EXTERNAL_OES. |
| 309 return GL_TEXTURE_EXTERNAL_OES; | 273 return GL_TEXTURE_EXTERNAL_OES; |
| 310 case gfx::IO_SURFACE_BUFFER: | 274 case gfx::IO_SURFACE_BUFFER: |
| 311 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. | 275 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. |
| 312 return GL_TEXTURE_RECTANGLE_ARB; | 276 return GL_TEXTURE_RECTANGLE_ARB; |
| 313 default: | 277 default: |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 host->AddFilter(filter.get()); | 464 host->AddFilter(filter.get()); |
| 501 } | 465 } |
| 502 | 466 |
| 503 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( | 467 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( |
| 504 gfx::GpuMemoryBuffer::Format format, | 468 gfx::GpuMemoryBuffer::Format format, |
| 505 gfx::GpuMemoryBuffer::Usage usage) { | 469 gfx::GpuMemoryBuffer::Usage usage) { |
| 506 // Return early if usage is not enabled. | 470 // Return early if usage is not enabled. |
| 507 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) | 471 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) |
| 508 return false; | 472 return false; |
| 509 | 473 |
| 474 // Preferred type is always used by factory. |
| 510 std::vector<gfx::GpuMemoryBufferType> supported_types; | 475 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 511 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 476 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| 512 DCHECK(!supported_types.empty()); | 477 DCHECK(!supported_types.empty()); |
| 513 | 478 switch (supported_types[0]) { |
| 514 // The GPU service will always use the preferred type, if the |format| and | 479 case gfx::SHARED_MEMORY_BUFFER: |
| 515 // |usage| allows. | 480 // Shared memory buffers must be created in-process. |
| 516 gfx::GpuMemoryBufferType type = supported_types[0]; | 481 return false; |
| 517 | 482 #if defined(OS_MACOSX) |
| 518 return IsGpuMemoryBufferFactoryConfigurationSupported(format, usage, type); | 483 case gfx::IO_SURFACE_BUFFER: |
| 484 return GpuMemoryBufferFactoryIOSurface:: |
| 485 IsGpuMemoryBufferConfigurationSupported(format, usage); |
| 486 #endif |
| 487 #if defined(OS_ANDROID) |
| 488 case gfx::SURFACE_TEXTURE_BUFFER: |
| 489 return GpuMemoryBufferFactorySurfaceTexture:: |
| 490 IsGpuMemoryBufferConfigurationSupported(format, usage); |
| 491 #endif |
| 492 #if defined(USE_OZONE) |
| 493 case gfx::OZONE_NATIVE_BUFFER: |
| 494 return GpuMemoryBufferFactoryOzoneNativeBuffer:: |
| 495 IsGpuMemoryBufferConfigurationSupported(format, usage); |
| 496 #endif |
| 497 default: |
| 498 NOTREACHED(); |
| 499 return false; |
| 500 } |
| 519 } | 501 } |
| 520 | 502 |
| 521 void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( | 503 void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( |
| 522 gfx::GpuMemoryBufferId id, | 504 gfx::GpuMemoryBufferId id, |
| 523 const gfx::Size& size, | 505 const gfx::Size& size, |
| 524 gfx::GpuMemoryBuffer::Format format, | 506 gfx::GpuMemoryBuffer::Format format, |
| 525 gfx::GpuMemoryBuffer::Usage usage, | 507 gfx::GpuMemoryBuffer::Usage usage, |
| 526 int client_id, | 508 int client_id, |
| 527 int32 surface_id, | 509 int32 surface_id, |
| 528 const CreateGpuMemoryBufferCallback& callback) { | 510 const CreateGpuMemoryBufferCallback& callback) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 558 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 577 | 559 |
| 578 CreateGpuMemoryBufferCallbackMap::iterator iter = | 560 CreateGpuMemoryBufferCallbackMap::iterator iter = |
| 579 create_gpu_memory_buffer_requests_.find(request_id); | 561 create_gpu_memory_buffer_requests_.find(request_id); |
| 580 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 562 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
| 581 iter->second.Run(handle); | 563 iter->second.Run(handle); |
| 582 create_gpu_memory_buffer_requests_.erase(iter); | 564 create_gpu_memory_buffer_requests_.erase(iter); |
| 583 } | 565 } |
| 584 | 566 |
| 585 } // namespace content | 567 } // namespace content |
| OLD | NEW |