| 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 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 | 1054 |
| 1055 Resource* resource = &it->second; | 1055 Resource* resource = &it->second; |
| 1056 DCHECK_GT(resource->lock_for_read_count, 0); | 1056 DCHECK_GT(resource->lock_for_read_count, 0); |
| 1057 DCHECK_EQ(resource->exported_count, 0); | 1057 DCHECK_EQ(resource->exported_count, 0); |
| 1058 resource->lock_for_read_count--; | 1058 resource->lock_for_read_count--; |
| 1059 if (resource->marked_for_deletion && !resource->lock_for_read_count) { | 1059 if (resource->marked_for_deletion && !resource->lock_for_read_count) { |
| 1060 if (!resource->child_id) { | 1060 if (!resource->child_id) { |
| 1061 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1061 // The resource belongs to this ResourceProvider, so it can be destroyed. |
| 1062 DeleteResourceInternal(it, NORMAL); | 1062 DeleteResourceInternal(it, NORMAL); |
| 1063 } else { | 1063 } else { |
| 1064 ChildMap::iterator child_it = children_.find(resource->child_id); | 1064 if (batch_return_resources_) { |
| 1065 ResourceIdArray unused; | 1065 batched_returning_resources_[resource->child_id].push_back(id); |
| 1066 unused.push_back(id); | 1066 } else { |
| 1067 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); | 1067 ChildMap::iterator child_it = children_.find(resource->child_id); |
| 1068 ResourceIdArray unused; |
| 1069 unused.push_back(id); |
| 1070 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); |
| 1071 } |
| 1068 } | 1072 } |
| 1069 } | 1073 } |
| 1070 } | 1074 } |
| 1071 | 1075 |
| 1072 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { | 1076 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { |
| 1073 Resource* resource = GetResource(id); | 1077 Resource* resource = GetResource(id); |
| 1074 DCHECK(CanLockForWrite(id)); | 1078 DCHECK(CanLockForWrite(id)); |
| 1075 if (resource->allocated) | 1079 if (resource->allocated) |
| 1076 WaitSyncTokenIfNeeded(id); | 1080 WaitSyncTokenIfNeeded(id); |
| 1077 resource->locked_for_write = true; | 1081 resource->locked_for_write = true; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 gfx::GpuMemoryBuffer* | 1380 gfx::GpuMemoryBuffer* |
| 1377 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { | 1381 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { |
| 1378 if (!gpu_memory_buffer_) { | 1382 if (!gpu_memory_buffer_) { |
| 1379 gpu_memory_buffer_ = | 1383 gpu_memory_buffer_ = |
| 1380 resource_provider_->gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( | 1384 resource_provider_->gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( |
| 1381 size_, BufferFormat(format_), usage_, gpu::kNullSurfaceHandle); | 1385 size_, BufferFormat(format_), usage_, gpu::kNullSurfaceHandle); |
| 1382 } | 1386 } |
| 1383 return gpu_memory_buffer_.get(); | 1387 return gpu_memory_buffer_.get(); |
| 1384 } | 1388 } |
| 1385 | 1389 |
| 1390 ResourceProvider::ScopedBatchReturnResources::ScopedBatchReturnResources( |
| 1391 ResourceProvider* resource_provider) |
| 1392 : resource_provider_(resource_provider) { |
| 1393 resource_provider_->SetBatchReturnResources(true); |
| 1394 } |
| 1395 |
| 1396 ResourceProvider::ScopedBatchReturnResources::~ScopedBatchReturnResources() { |
| 1397 resource_provider_->SetBatchReturnResources(false); |
| 1398 } |
| 1399 |
| 1386 ResourceProvider::SynchronousFence::SynchronousFence( | 1400 ResourceProvider::SynchronousFence::SynchronousFence( |
| 1387 gpu::gles2::GLES2Interface* gl) | 1401 gpu::gles2::GLES2Interface* gl) |
| 1388 : gl_(gl), has_synchronized_(true) {} | 1402 : gl_(gl), has_synchronized_(true) {} |
| 1389 | 1403 |
| 1390 ResourceProvider::SynchronousFence::~SynchronousFence() {} | 1404 ResourceProvider::SynchronousFence::~SynchronousFence() {} |
| 1391 | 1405 |
| 1392 void ResourceProvider::SynchronousFence::Set() { | 1406 void ResourceProvider::SynchronousFence::Set() { |
| 1393 has_synchronized_ = false; | 1407 has_synchronized_ = false; |
| 1394 } | 1408 } |
| 1395 | 1409 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 resources_for_child[resource->child_id].push_back(local_id); | 1698 resources_for_child[resource->child_id].push_back(local_id); |
| 1685 } | 1699 } |
| 1686 | 1700 |
| 1687 for (const auto& children : resources_for_child) { | 1701 for (const auto& children : resources_for_child) { |
| 1688 ChildMap::iterator child_it = children_.find(children.first); | 1702 ChildMap::iterator child_it = children_.find(children.first); |
| 1689 DCHECK(child_it != children_.end()); | 1703 DCHECK(child_it != children_.end()); |
| 1690 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); | 1704 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); |
| 1691 } | 1705 } |
| 1692 } | 1706 } |
| 1693 | 1707 |
| 1708 void ResourceProvider::SetBatchReturnResources(bool batch) { |
| 1709 DCHECK_NE(batch_return_resources_, batch); |
| 1710 batch_return_resources_ = batch; |
| 1711 if (!batch) { |
| 1712 for (const auto& resources : batched_returning_resources_) { |
| 1713 ChildMap::iterator child_it = children_.find(resources.first); |
| 1714 DCHECK(child_it != children_.end()); |
| 1715 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, resources.second); |
| 1716 } |
| 1717 batched_returning_resources_.clear(); |
| 1718 } |
| 1719 } |
| 1720 |
| 1694 #if defined(OS_ANDROID) | 1721 #if defined(OS_ANDROID) |
| 1695 void ResourceProvider::SendPromotionHints( | 1722 void ResourceProvider::SendPromotionHints( |
| 1696 const OverlayCandidateList::PromotionHintInfoMap& promotion_hints) { | 1723 const OverlayCandidateList::PromotionHintInfoMap& promotion_hints) { |
| 1697 GLES2Interface* gl = ContextGL(); | 1724 GLES2Interface* gl = ContextGL(); |
| 1698 if (!gl) | 1725 if (!gl) |
| 1699 return; | 1726 return; |
| 1700 | 1727 |
| 1701 for (const auto& id : wants_promotion_hints_set_) { | 1728 for (const auto& id : wants_promotion_hints_set_) { |
| 1702 const ResourceMap::iterator it = resources_.find(id); | 1729 const ResourceMap::iterator it = resources_.find(id); |
| 1703 if (it == resources_.end()) | 1730 if (it == resources_.end()) |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2170 | 2197 |
| 2171 const int kImportance = 2; | 2198 const int kImportance = 2; |
| 2172 pmd->CreateSharedGlobalAllocatorDump(guid); | 2199 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2173 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2200 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2174 } | 2201 } |
| 2175 | 2202 |
| 2176 return true; | 2203 return true; |
| 2177 } | 2204 } |
| 2178 | 2205 |
| 2179 } // namespace cc | 2206 } // namespace cc |
| OLD | NEW |