Commit b51c9ded authored by jadahl@opera.com's avatar jadahl@opera.com

cc: Keep track of busy resources in ResourcePool

Instead of assuming every released resource could be potentially
reusable, manage a list of busy resources and a list of immediately
reusable resources. A busy resource is one which can not be locked for
write.
    
Recheck busy resources before the tile manager is to schedule new tasks,
in AssignGpuMemoryToTiles().
    
If this operation becomes too expensive, the CheckBusyResources()
function should only be called if some resource(s) are returned from the
parent compositor or when ResourcePool releases some resource.

BUG=

Review URL: https://codereview.chromium.org/43753002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233374 0039d316-1c4b-4281-b951-d872f2087c98
parent c2fc0ab7
......@@ -47,9 +47,8 @@ scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
for (ResourceList::iterator it = unused_resources_.begin();
it != unused_resources_.end(); ++it) {
Resource* resource = *it;
DCHECK(resource_provider_->CanLockForWrite(resource->id()));
if (!resource_provider_->CanLockForWrite(resource->id()))
continue;
if (resource->size() != size)
continue;
if (resource->format() != format)
......@@ -75,14 +74,7 @@ scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
void ResourcePool::ReleaseResource(
scoped_ptr<ResourcePool::Resource> resource) {
if (ResourceUsageTooHigh()) {
memory_usage_bytes_ -= resource->bytes();
--resource_count_;
return;
}
unused_memory_usage_bytes_ += resource->bytes();
unused_resources_.push_back(resource.release());
busy_resources_.push_back(resource.release());
}
void ResourcePool::SetResourceUsageLimits(
......@@ -127,4 +119,20 @@ bool ResourcePool::ResourceUsageTooHigh() {
return false;
}
void ResourcePool::CheckBusyResources() {
ResourceList::iterator it = busy_resources_.begin();
while (it != busy_resources_.end()) {
Resource* resource = *it;
if (resource_provider_->CanLockForWrite(resource->id())) {
unused_memory_usage_bytes_ += resource->bytes();
unused_resources_.push_back(resource);
it = busy_resources_.erase(it);
} else {
++it;
}
}
}
} // namespace cc
......@@ -45,6 +45,7 @@ class CC_EXPORT ResourcePool {
size_t max_resource_count);
void ReduceResourceUsage();
void CheckBusyResources();
size_t total_memory_usage_bytes() const {
return memory_usage_bytes_;
......@@ -72,6 +73,7 @@ class CC_EXPORT ResourcePool {
typedef std::list<Resource*> ResourceList;
ResourceList unused_resources_;
ResourceList busy_resources_;
DISALLOW_COPY_AND_ASSIGN(ResourcePool);
};
......
......@@ -595,6 +595,13 @@ void TileManager::AssignGpuMemoryToTiles(
TileVector* tiles_that_need_to_be_rasterized) {
TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles");
// Maintain the list of released resources that can potentially be re-used
// or deleted.
// If this operation becomes expensive too, only do this after some
// resource(s) was returned. Note that in that case, one also need to
// invalidate when releasing some resource from the pool.
resource_pool_->CheckBusyResources();
// Now give memory out to the tiles until we're out, and build
// the needs-to-be-rasterized queue.
all_tiles_that_need_to_be_rasterized_have_memory_ = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment