OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 itr != resources_.end(); ++itr) { | 361 itr != resources_.end(); ++itr) { |
362 DCHECK(!IsGpuResourceType(itr->second.type)); | 362 DCHECK(!IsGpuResourceType(itr->second.type)); |
363 } | 363 } |
364 #endif // DCHECK_IS_ON() | 364 #endif // DCHECK_IS_ON() |
365 | 365 |
366 texture_id_allocator_ = nullptr; | 366 texture_id_allocator_ = nullptr; |
367 buffer_id_allocator_ = nullptr; | 367 buffer_id_allocator_ = nullptr; |
368 gl->Finish(); | 368 gl->Finish(); |
369 } | 369 } |
370 | 370 |
| 371 bool ResourceProvider::IsResourceFormatSupported(ResourceFormat format) const { |
| 372 const ContextProvider::Capabilities& caps = |
| 373 output_surface_->context_provider()->ContextCapabilities(); |
| 374 |
| 375 switch (format) { |
| 376 case ALPHA_8: |
| 377 case RGBA_4444: |
| 378 case RGBA_8888: |
| 379 case RGB_565: |
| 380 case LUMINANCE_8: |
| 381 return true; |
| 382 case BGRA_8888: |
| 383 return caps.gpu.texture_format_bgra8888; |
| 384 case ETC1: |
| 385 return caps.gpu.texture_format_etc1; |
| 386 case RED_8: |
| 387 return caps.gpu.texture_rg; |
| 388 } |
| 389 |
| 390 NOTREACHED(); |
| 391 return false; |
| 392 } |
| 393 |
371 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 394 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
372 Resource* resource = GetResource(id); | 395 Resource* resource = GetResource(id); |
373 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 396 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
374 resource->lost; | 397 resource->lost; |
375 } | 398 } |
376 | 399 |
377 bool ResourceProvider::IsLost(ResourceId id) { | 400 bool ResourceProvider::IsLost(ResourceId id) { |
378 Resource* resource = GetResource(id); | 401 Resource* resource = GetResource(id); |
379 return resource->lost; | 402 return resource->lost; |
380 } | 403 } |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 LazyAllocate(GetResource(id)); | 1519 LazyAllocate(GetResource(id)); |
1497 } | 1520 } |
1498 | 1521 |
1499 void ResourceProvider::LazyAllocate(Resource* resource) { | 1522 void ResourceProvider::LazyAllocate(Resource* resource) { |
1500 DCHECK(resource); | 1523 DCHECK(resource); |
1501 if (resource->allocated) | 1524 if (resource->allocated) |
1502 return; | 1525 return; |
1503 LazyCreate(resource); | 1526 LazyCreate(resource); |
1504 if (!resource->gl_id) | 1527 if (!resource->gl_id) |
1505 return; | 1528 return; |
1506 resource->allocated = true; | |
1507 GLES2Interface* gl = ContextGL(); | 1529 GLES2Interface* gl = ContextGL(); |
1508 gfx::Size& size = resource->size; | 1530 gfx::Size& size = resource->size; |
1509 ResourceFormat format = resource->format; | 1531 ResourceFormat format = resource->format; |
1510 gl->BindTexture(resource->target, resource->gl_id); | 1532 gl->BindTexture(resource->target, resource->gl_id); |
1511 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1533 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { |
1512 resource->gpu_memory_buffer = | 1534 resource->gpu_memory_buffer = |
1513 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1535 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
1514 size, BufferFormat(format), | 1536 size, BufferFormat(format), |
1515 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) | 1537 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) |
1516 .release(); | 1538 .release(); |
1517 LazyCreateImage(resource); | 1539 LazyCreateImage(resource); |
1518 resource->dirty_image = true; | 1540 resource->dirty_image = true; |
1519 resource->is_overlay_candidate = true; | 1541 resource->is_overlay_candidate = true; |
1520 } else if (use_texture_storage_ext_ && | 1542 } else if (use_texture_storage_ext_ && |
1521 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 1543 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
1522 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 1544 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { |
1523 GLenum storage_format = TextureToStorageFormat(format); | 1545 GLenum storage_format = TextureToStorageFormat(format); |
1524 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | 1546 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), |
1525 size.height()); | 1547 size.height()); |
| 1548 resource->allocated = true; |
1526 } else { | 1549 } else { |
1527 // ETC1 does not support preallocation. | 1550 // ETC1 does not support preallocation. |
1528 if (format != ETC1) { | 1551 if (format != ETC1) { |
1529 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), | 1552 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), |
1530 size.width(), size.height(), 0, GLDataFormat(format), | 1553 size.width(), size.height(), 0, GLDataFormat(format), |
1531 GLDataType(format), NULL); | 1554 GLDataType(format), NULL); |
| 1555 resource->allocated = true; |
1532 } | 1556 } |
1533 } | 1557 } |
1534 } | 1558 } |
1535 | 1559 |
1536 void ResourceProvider::LazyCreateImage(Resource* resource) { | 1560 void ResourceProvider::LazyCreateImage(Resource* resource) { |
1537 DCHECK(resource->gpu_memory_buffer); | 1561 DCHECK(resource->gpu_memory_buffer); |
1538 DCHECK(resource->gl_id); | 1562 DCHECK(resource->gl_id); |
1539 DCHECK(resource->allocated); | 1563 DCHECK(resource->allocated); |
1540 if (!resource->image_id) { | 1564 if (!resource->image_id) { |
1541 GLES2Interface* gl = ContextGL(); | 1565 GLES2Interface* gl = ContextGL(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 const int kImportance = 2; | 1685 const int kImportance = 2; |
1662 pmd->CreateSharedGlobalAllocatorDump(guid); | 1686 pmd->CreateSharedGlobalAllocatorDump(guid); |
1663 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1687 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1664 } | 1688 } |
1665 } | 1689 } |
1666 | 1690 |
1667 return true; | 1691 return true; |
1668 } | 1692 } |
1669 | 1693 |
1670 } // namespace cc | 1694 } // namespace cc |
OLD | NEW |