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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 resource->gpu_memory_buffer = NULL; | 606 resource->gpu_memory_buffer = NULL; |
607 } | 607 } |
608 resources_.erase(it); | 608 resources_.erase(it); |
609 } | 609 } |
610 | 610 |
611 ResourceProvider::ResourceType ResourceProvider::GetResourceType( | 611 ResourceProvider::ResourceType ResourceProvider::GetResourceType( |
612 ResourceId id) { | 612 ResourceId id) { |
613 return GetResource(id)->type; | 613 return GetResource(id)->type; |
614 } | 614 } |
615 | 615 |
| 616 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { |
| 617 return GetResource(id)->target; |
| 618 } |
| 619 |
616 void ResourceProvider::CopyToResource(ResourceId id, | 620 void ResourceProvider::CopyToResource(ResourceId id, |
617 const uint8_t* image, | 621 const uint8_t* image, |
618 const gfx::Size& image_size) { | 622 const gfx::Size& image_size) { |
619 Resource* resource = GetResource(id); | 623 Resource* resource = GetResource(id); |
620 DCHECK(!resource->locked_for_write); | 624 DCHECK(!resource->locked_for_write); |
621 DCHECK(!resource->lock_for_read_count); | 625 DCHECK(!resource->lock_for_read_count); |
622 DCHECK(resource->origin == Resource::INTERNAL); | 626 DCHECK(resource->origin == Resource::INTERNAL); |
623 DCHECK_EQ(resource->exported_count, 0); | 627 DCHECK_EQ(resource->exported_count, 0); |
624 DCHECK(ReadLockFenceHasPassed(resource)); | 628 DCHECK(ReadLockFenceHasPassed(resource)); |
625 | 629 |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 if (resource->image_id && resource->dirty_image) | 1445 if (resource->image_id && resource->dirty_image) |
1442 BindImageForSampling(resource); | 1446 BindImageForSampling(resource); |
1443 | 1447 |
1444 return target; | 1448 return target; |
1445 } | 1449 } |
1446 | 1450 |
1447 void ResourceProvider::CreateForTesting(ResourceId id) { | 1451 void ResourceProvider::CreateForTesting(ResourceId id) { |
1448 LazyCreate(GetResource(id)); | 1452 LazyCreate(GetResource(id)); |
1449 } | 1453 } |
1450 | 1454 |
1451 GLenum ResourceProvider::TargetForTesting(ResourceId id) { | |
1452 Resource* resource = GetResource(id); | |
1453 return resource->target; | |
1454 } | |
1455 | |
1456 void ResourceProvider::LazyCreate(Resource* resource) { | 1455 void ResourceProvider::LazyCreate(Resource* resource) { |
1457 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || | 1456 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || |
1458 resource->origin != Resource::INTERNAL) | 1457 resource->origin != Resource::INTERNAL) |
1459 return; | 1458 return; |
1460 | 1459 |
1461 if (resource->gl_id) | 1460 if (resource->gl_id) |
1462 return; | 1461 return; |
1463 | 1462 |
1464 DCHECK(resource->origin == Resource::INTERNAL); | 1463 DCHECK(resource->origin == Resource::INTERNAL); |
1465 DCHECK(!resource->mailbox.IsValid()); | 1464 DCHECK(!resource->mailbox.IsValid()); |
(...skipping 29 matching lines...) Expand all Loading... |
1495 return; | 1494 return; |
1496 resource->allocated = true; | 1495 resource->allocated = true; |
1497 GLES2Interface* gl = ContextGL(); | 1496 GLES2Interface* gl = ContextGL(); |
1498 gfx::Size& size = resource->size; | 1497 gfx::Size& size = resource->size; |
1499 ResourceFormat format = resource->format; | 1498 ResourceFormat format = resource->format; |
1500 gl->BindTexture(resource->target, resource->gl_id); | 1499 gl->BindTexture(resource->target, resource->gl_id); |
1501 if (use_gpu_memory_buffer_resources_) { | 1500 if (use_gpu_memory_buffer_resources_) { |
1502 resource->gpu_memory_buffer = | 1501 resource->gpu_memory_buffer = |
1503 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1502 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
1504 size, BufferFormat(format), | 1503 size, BufferFormat(format), |
1505 gfx::BufferUsage::SCANOUT) | 1504 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) |
1506 .release(); | 1505 .release(); |
1507 LazyCreateImage(resource); | 1506 LazyCreateImage(resource); |
1508 resource->dirty_image = true; | 1507 resource->dirty_image = true; |
1509 resource->is_overlay_candidate = true; | 1508 resource->is_overlay_candidate = true; |
1510 } else if (use_texture_storage_ext_ && | 1509 } else if (use_texture_storage_ext_ && |
1511 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 1510 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
1512 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 1511 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { |
1513 GLenum storage_format = TextureToStorageFormat(format); | 1512 GLenum storage_format = TextureToStorageFormat(format); |
1514 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | 1513 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), |
1515 size.height()); | 1514 size.height()); |
(...skipping 17 matching lines...) Expand all Loading... |
1533 | 1532 |
1534 #if defined(OS_CHROMEOS) | 1533 #if defined(OS_CHROMEOS) |
1535 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization | 1534 // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization |
1536 // on ChromeOS to avoid some performance issues. This only works with | 1535 // on ChromeOS to avoid some performance issues. This only works with |
1537 // shared memory backed buffers. crbug.com/436314 | 1536 // shared memory backed buffers. crbug.com/436314 |
1538 DCHECK_EQ(resource->gpu_memory_buffer->GetHandle().type, | 1537 DCHECK_EQ(resource->gpu_memory_buffer->GetHandle().type, |
1539 gfx::SHARED_MEMORY_BUFFER); | 1538 gfx::SHARED_MEMORY_BUFFER); |
1540 #endif | 1539 #endif |
1541 resource->image_id = gl->CreateImageCHROMIUM( | 1540 resource->image_id = gl->CreateImageCHROMIUM( |
1542 resource->gpu_memory_buffer->AsClientBuffer(), resource->size.width(), | 1541 resource->gpu_memory_buffer->AsClientBuffer(), resource->size.width(), |
1543 resource->size.height(), GLInternalFormat(resource->format)); | 1542 resource->size.height(), GLImageFormat(resource->format)); |
1544 } | 1543 } |
1545 } | 1544 } |
1546 | 1545 |
1547 void ResourceProvider::BindImageForSampling(Resource* resource) { | 1546 void ResourceProvider::BindImageForSampling(Resource* resource) { |
1548 GLES2Interface* gl = ContextGL(); | 1547 GLES2Interface* gl = ContextGL(); |
1549 DCHECK(resource->gl_id); | 1548 DCHECK(resource->gl_id); |
1550 DCHECK(resource->image_id); | 1549 DCHECK(resource->image_id); |
1551 | 1550 |
1552 // Release image currently bound to texture. | 1551 // Release image currently bound to texture. |
1553 gl->BindTexture(resource->target, resource->gl_id); | 1552 gl->BindTexture(resource->target, resource->gl_id); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 const int kImportance = 2; | 1650 const int kImportance = 2; |
1652 pmd->CreateSharedGlobalAllocatorDump(guid); | 1651 pmd->CreateSharedGlobalAllocatorDump(guid); |
1653 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1652 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1654 } | 1653 } |
1655 } | 1654 } |
1656 | 1655 |
1657 return true; | 1656 return true; |
1658 } | 1657 } |
1659 | 1658 |
1660 } // namespace cc | 1659 } // namespace cc |
OLD | NEW |