| 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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 | 1026 |
| 1027 Resource* resource = &it->second; | 1027 Resource* resource = &it->second; |
| 1028 DCHECK_GT(resource->lock_for_read_count, 0); | 1028 DCHECK_GT(resource->lock_for_read_count, 0); |
| 1029 DCHECK_EQ(resource->exported_count, 0); | 1029 DCHECK_EQ(resource->exported_count, 0); |
| 1030 resource->lock_for_read_count--; | 1030 resource->lock_for_read_count--; |
| 1031 if (resource->marked_for_deletion && !resource->lock_for_read_count) { | 1031 if (resource->marked_for_deletion && !resource->lock_for_read_count) { |
| 1032 if (!resource->child_id) { | 1032 if (!resource->child_id) { |
| 1033 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1033 // The resource belongs to this ResourceProvider, so it can be destroyed. |
| 1034 DeleteResourceInternal(it, NORMAL); | 1034 DeleteResourceInternal(it, NORMAL); |
| 1035 } else { | 1035 } else { |
| 1036 ChildMap::iterator child_it = children_.find(resource->child_id); | 1036 if (batch_return_resources_) { |
| 1037 ResourceIdArray unused; | 1037 batched_returning_resources_[resource->child_id].push_back(id); |
| 1038 unused.push_back(id); | 1038 } else { |
| 1039 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); | 1039 ChildMap::iterator child_it = children_.find(resource->child_id); |
| 1040 ResourceIdArray unused; |
| 1041 unused.push_back(id); |
| 1042 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); |
| 1043 } |
| 1040 } | 1044 } |
| 1041 } | 1045 } |
| 1042 } | 1046 } |
| 1043 | 1047 |
| 1044 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { | 1048 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { |
| 1045 Resource* resource = GetResource(id); | 1049 Resource* resource = GetResource(id); |
| 1046 DCHECK(CanLockForWrite(id)); | 1050 DCHECK(CanLockForWrite(id)); |
| 1047 if (resource->allocated) | 1051 if (resource->allocated) |
| 1048 WaitSyncTokenIfNeeded(id); | 1052 WaitSyncTokenIfNeeded(id); |
| 1049 resource->locked_for_write = true; | 1053 resource->locked_for_write = true; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 gfx::GpuMemoryBuffer* | 1352 gfx::GpuMemoryBuffer* |
| 1349 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { | 1353 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { |
| 1350 if (!gpu_memory_buffer_) { | 1354 if (!gpu_memory_buffer_) { |
| 1351 gpu_memory_buffer_ = | 1355 gpu_memory_buffer_ = |
| 1352 resource_provider_->gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( | 1356 resource_provider_->gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( |
| 1353 size_, BufferFormat(format_), usage_, gpu::kNullSurfaceHandle); | 1357 size_, BufferFormat(format_), usage_, gpu::kNullSurfaceHandle); |
| 1354 } | 1358 } |
| 1355 return gpu_memory_buffer_.get(); | 1359 return gpu_memory_buffer_.get(); |
| 1356 } | 1360 } |
| 1357 | 1361 |
| 1362 ResourceProvider::ScopedBatchReturnResources::ScopedBatchReturnResources( |
| 1363 ResourceProvider* resource_provider) |
| 1364 : resource_provider_(resource_provider) { |
| 1365 resource_provider_->SetBatchReturnResources(true); |
| 1366 } |
| 1367 |
| 1368 ResourceProvider::ScopedBatchReturnResources::~ScopedBatchReturnResources() { |
| 1369 resource_provider_->SetBatchReturnResources(false); |
| 1370 } |
| 1371 |
| 1358 ResourceProvider::SynchronousFence::SynchronousFence( | 1372 ResourceProvider::SynchronousFence::SynchronousFence( |
| 1359 gpu::gles2::GLES2Interface* gl) | 1373 gpu::gles2::GLES2Interface* gl) |
| 1360 : gl_(gl), has_synchronized_(true) {} | 1374 : gl_(gl), has_synchronized_(true) {} |
| 1361 | 1375 |
| 1362 ResourceProvider::SynchronousFence::~SynchronousFence() {} | 1376 ResourceProvider::SynchronousFence::~SynchronousFence() {} |
| 1363 | 1377 |
| 1364 void ResourceProvider::SynchronousFence::Set() { | 1378 void ResourceProvider::SynchronousFence::Set() { |
| 1365 has_synchronized_ = false; | 1379 has_synchronized_ = false; |
| 1366 } | 1380 } |
| 1367 | 1381 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 resources_for_child[resource->child_id].push_back(local_id); | 1670 resources_for_child[resource->child_id].push_back(local_id); |
| 1657 } | 1671 } |
| 1658 | 1672 |
| 1659 for (const auto& children : resources_for_child) { | 1673 for (const auto& children : resources_for_child) { |
| 1660 ChildMap::iterator child_it = children_.find(children.first); | 1674 ChildMap::iterator child_it = children_.find(children.first); |
| 1661 DCHECK(child_it != children_.end()); | 1675 DCHECK(child_it != children_.end()); |
| 1662 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); | 1676 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); |
| 1663 } | 1677 } |
| 1664 } | 1678 } |
| 1665 | 1679 |
| 1680 void ResourceProvider::SetBatchReturnResources(bool batch) { |
| 1681 DCHECK_NE(batch_return_resources_, batch); |
| 1682 batch_return_resources_ = batch; |
| 1683 if (!batch) { |
| 1684 for (const auto& resources : batched_returning_resources_) { |
| 1685 ChildMap::iterator child_it = children_.find(resources.first); |
| 1686 DCHECK(child_it != children_.end()); |
| 1687 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, resources.second); |
| 1688 } |
| 1689 batched_returning_resources_.clear(); |
| 1690 } |
| 1691 } |
| 1692 |
| 1666 #if defined(OS_ANDROID) | 1693 #if defined(OS_ANDROID) |
| 1667 void ResourceProvider::SendPromotionHints( | 1694 void ResourceProvider::SendPromotionHints( |
| 1668 const OverlayCandidateList::PromotionHintInfoMap& promotion_hints) { | 1695 const OverlayCandidateList::PromotionHintInfoMap& promotion_hints) { |
| 1669 GLES2Interface* gl = ContextGL(); | 1696 GLES2Interface* gl = ContextGL(); |
| 1670 if (!gl) | 1697 if (!gl) |
| 1671 return; | 1698 return; |
| 1672 | 1699 |
| 1673 for (const auto& id : wants_promotion_hints_set_) { | 1700 for (const auto& id : wants_promotion_hints_set_) { |
| 1674 const ResourceMap::iterator it = resources_.find(id); | 1701 const ResourceMap::iterator it = resources_.find(id); |
| 1675 if (it == resources_.end()) | 1702 if (it == resources_.end()) |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2142 | 2169 |
| 2143 const int kImportance = 2; | 2170 const int kImportance = 2; |
| 2144 pmd->CreateSharedGlobalAllocatorDump(guid); | 2171 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2145 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2172 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2146 } | 2173 } |
| 2147 | 2174 |
| 2148 return true; | 2175 return true; |
| 2149 } | 2176 } |
| 2150 | 2177 |
| 2151 } // namespace cc | 2178 } // namespace cc |
| OLD | NEW |