| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), | 654 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), |
| 655 Resource::EXTERNAL, GL_LINEAR)); | 655 Resource::EXTERNAL, GL_LINEAR)); |
| 656 } | 656 } |
| 657 resource->allocated = true; | 657 resource->allocated = true; |
| 658 resource->set_mailbox(mailbox); | 658 resource->set_mailbox(mailbox); |
| 659 resource->release_callback_impl = | 659 resource->release_callback_impl = |
| 660 base::Bind(&SingleReleaseCallbackImpl::Run, | 660 base::Bind(&SingleReleaseCallbackImpl::Run, |
| 661 base::Owned(release_callback_impl.release())); | 661 base::Owned(release_callback_impl.release())); |
| 662 resource->read_lock_fences_enabled = read_lock_fences_enabled; | 662 resource->read_lock_fences_enabled = read_lock_fences_enabled; |
| 663 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); | 663 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); |
| 664 resource->gpu_memory_buffer_id = mailbox.gpu_memory_buffer_id(); | |
| 665 | 664 |
| 666 return id; | 665 return id; |
| 667 } | 666 } |
| 668 | 667 |
| 669 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 668 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 670 const TextureMailbox& mailbox, | 669 const TextureMailbox& mailbox, |
| 671 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { | 670 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { |
| 672 return CreateResourceFromTextureMailbox( | 671 return CreateResourceFromTextureMailbox( |
| 673 mailbox, std::move(release_callback_impl), false); | 672 mailbox, std::move(release_callback_impl), false); |
| 674 } | 673 } |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1096 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1098 ~ScopedWriteLockGpuMemoryBuffer() { | 1097 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1099 DCHECK(thread_checker_.CalledOnValidThread()); | 1098 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1100 resource_provider_->UnlockForWrite(resource_); | 1099 resource_provider_->UnlockForWrite(resource_); |
| 1101 if (!gpu_memory_buffer_) | 1100 if (!gpu_memory_buffer_) |
| 1102 return; | 1101 return; |
| 1103 | 1102 |
| 1104 DCHECK(!resource_->gpu_memory_buffer); | 1103 DCHECK(!resource_->gpu_memory_buffer); |
| 1105 resource_provider_->LazyCreate(resource_); | 1104 resource_provider_->LazyCreate(resource_); |
| 1106 resource_->gpu_memory_buffer = std::move(gpu_memory_buffer_); | 1105 resource_->gpu_memory_buffer = std::move(gpu_memory_buffer_); |
| 1107 if (resource_->gpu_memory_buffer) | |
| 1108 resource_->gpu_memory_buffer_id = resource_->gpu_memory_buffer->GetId(); | |
| 1109 resource_->allocated = true; | 1106 resource_->allocated = true; |
| 1110 resource_provider_->LazyCreateImage(resource_); | 1107 resource_provider_->LazyCreateImage(resource_); |
| 1111 resource_->dirty_image = true; | 1108 resource_->dirty_image = true; |
| 1112 resource_->is_overlay_candidate = true; | 1109 resource_->is_overlay_candidate = true; |
| 1113 resource_->SetSynchronized(); | 1110 resource_->SetSynchronized(); |
| 1114 | 1111 |
| 1115 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 1112 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| 1116 // Read lock fences are required to ensure that we're not trying to map a | 1113 // Read lock fences are required to ensure that we're not trying to map a |
| 1117 // buffer that is currently in-use by the GPU. | 1114 // buffer that is currently in-use by the GPU. |
| 1118 resource_->read_lock_fences_enabled = true; | 1115 resource_->read_lock_fences_enabled = true; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 resource = InsertResource( | 1382 resource = InsertResource( |
| 1386 local_id, Resource(0, it->size, Resource::DELEGATED, | 1383 local_id, Resource(0, it->size, Resource::DELEGATED, |
| 1387 it->mailbox_holder.texture_target, it->filter, | 1384 it->mailbox_holder.texture_target, it->filter, |
| 1388 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, | 1385 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, |
| 1389 it->format)); | 1386 it->format)); |
| 1390 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, | 1387 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, |
| 1391 it->mailbox_holder.sync_token, | 1388 it->mailbox_holder.sync_token, |
| 1392 it->mailbox_holder.texture_target)); | 1389 it->mailbox_holder.texture_target)); |
| 1393 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; | 1390 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; |
| 1394 resource->is_overlay_candidate = it->is_overlay_candidate; | 1391 resource->is_overlay_candidate = it->is_overlay_candidate; |
| 1395 resource->gpu_memory_buffer_id = it->gpu_memory_buffer_id; | |
| 1396 } | 1392 } |
| 1397 resource->child_id = child; | 1393 resource->child_id = child; |
| 1398 // Don't allocate a texture for a child. | 1394 // Don't allocate a texture for a child. |
| 1399 resource->allocated = true; | 1395 resource->allocated = true; |
| 1400 resource->imported_count = 1; | 1396 resource->imported_count = 1; |
| 1401 child_info.parent_to_child_map[local_id] = it->id; | 1397 child_info.parent_to_child_map[local_id] = it->id; |
| 1402 child_info.child_to_parent_map[it->id] = local_id; | 1398 child_info.child_to_parent_map[it->id] = local_id; |
| 1403 } | 1399 } |
| 1404 } | 1400 } |
| 1405 | 1401 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 DCHECK(!source->locked_for_write); | 1506 DCHECK(!source->locked_for_write); |
| 1511 DCHECK(!source->lock_for_read_count); | 1507 DCHECK(!source->lock_for_read_count); |
| 1512 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); | 1508 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); |
| 1513 DCHECK(source->allocated); | 1509 DCHECK(source->allocated); |
| 1514 resource->id = id; | 1510 resource->id = id; |
| 1515 resource->format = source->format; | 1511 resource->format = source->format; |
| 1516 resource->mailbox_holder.texture_target = source->target; | 1512 resource->mailbox_holder.texture_target = source->target; |
| 1517 resource->filter = source->filter; | 1513 resource->filter = source->filter; |
| 1518 resource->size = source->size; | 1514 resource->size = source->size; |
| 1519 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; | 1515 resource->read_lock_fences_enabled = source->read_lock_fences_enabled; |
| 1520 resource->gpu_memory_buffer_id = source->gpu_memory_buffer_id; | |
| 1521 resource->is_overlay_candidate = source->is_overlay_candidate; | 1516 resource->is_overlay_candidate = source->is_overlay_candidate; |
| 1522 | 1517 |
| 1523 if (source->type == RESOURCE_TYPE_BITMAP) { | 1518 if (source->type == RESOURCE_TYPE_BITMAP) { |
| 1524 resource->mailbox_holder.mailbox = source->shared_bitmap_id; | 1519 resource->mailbox_holder.mailbox = source->shared_bitmap_id; |
| 1525 resource->is_software = true; | 1520 resource->is_software = true; |
| 1526 } else { | 1521 } else { |
| 1527 DCHECK(source->mailbox().IsValid()); | 1522 DCHECK(source->mailbox().IsValid()); |
| 1528 DCHECK(source->mailbox().IsTexture()); | 1523 DCHECK(source->mailbox().IsTexture()); |
| 1529 DCHECK(!source->image_id || !source->dirty_image); | 1524 DCHECK(!source->image_id || !source->dirty_image); |
| 1530 // This is either an external resource, or a compositor resource that we | 1525 // This is either an external resource, or a compositor resource that we |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 resource->allocated = true; | 1723 resource->allocated = true; |
| 1729 GLES2Interface* gl = ContextGL(); | 1724 GLES2Interface* gl = ContextGL(); |
| 1730 gfx::Size& size = resource->size; | 1725 gfx::Size& size = resource->size; |
| 1731 ResourceFormat format = resource->format; | 1726 ResourceFormat format = resource->format; |
| 1732 gl->BindTexture(resource->target, resource->gl_id); | 1727 gl->BindTexture(resource->target, resource->gl_id); |
| 1733 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1728 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { |
| 1734 resource->gpu_memory_buffer = | 1729 resource->gpu_memory_buffer = |
| 1735 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1730 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
| 1736 size, BufferFormat(format), | 1731 size, BufferFormat(format), |
| 1737 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); | 1732 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); |
| 1738 if (resource->gpu_memory_buffer) | |
| 1739 resource->gpu_memory_buffer_id = resource->gpu_memory_buffer->GetId(); | |
| 1740 LazyCreateImage(resource); | 1733 LazyCreateImage(resource); |
| 1741 resource->dirty_image = true; | 1734 resource->dirty_image = true; |
| 1742 resource->is_overlay_candidate = true; | 1735 resource->is_overlay_candidate = true; |
| 1743 } else if (use_texture_storage_ext_ && | 1736 } else if (use_texture_storage_ext_ && |
| 1744 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 1737 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
| 1745 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 1738 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { |
| 1746 GLenum storage_format = TextureToStorageFormat(format); | 1739 GLenum storage_format = TextureToStorageFormat(format); |
| 1747 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | 1740 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), |
| 1748 size.height()); | 1741 size.height()); |
| 1749 } else { | 1742 } else { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1909 | 1902 |
| 1910 const int kImportance = 2; | 1903 const int kImportance = 2; |
| 1911 pmd->CreateSharedGlobalAllocatorDump(guid); | 1904 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 1912 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1905 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 1913 } | 1906 } |
| 1914 | 1907 |
| 1915 return true; | 1908 return true; |
| 1916 } | 1909 } |
| 1917 | 1910 |
| 1918 } // namespace cc | 1911 } // namespace cc |
| OLD | NEW |