diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-17 02:14:23 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-17 02:14:23 +0000 |
commit | 65d540fca58712c931316119ea6db4825260423d (patch) | |
tree | 59f765ae903215cb22c1949685784ebe4a36ac77 /cc/surfaces/surface.cc | |
parent | 64f537d8537a86f816a518413f96099a15f752b2 (diff) | |
download | chromium_src-65d540fca58712c931316119ea6db4825260423d.zip chromium_src-65d540fca58712c931316119ea6db4825260423d.tar.gz chromium_src-65d540fca58712c931316119ea6db4825260423d.tar.bz2 |
Manage resource lifetimes in frames submitted to Surfaces
This keeps track of the use of resources in frames sumbmitted to
surfaces as well as refs grabbed by ResourceProviders that want to draw
the submitted frames.
BUG=339257
Review URL: https://codereview.chromium.org/195993006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/surfaces/surface.cc')
-rw-r--r-- | cc/surfaces/surface.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/cc/surfaces/surface.cc b/cc/surfaces/surface.cc index 4012814..ed5a0f6 100644 --- a/cc/surfaces/surface.cc +++ b/cc/surfaces/surface.cc @@ -23,9 +23,70 @@ Surface::~Surface() { } void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame) { + scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); current_frame_ = frame.Pass(); + ReceiveResourcesFromClient( + current_frame_->delegated_frame_data->resource_list); + if (previous_frame) { + ReturnedResourceArray previous_resources; + TransferableResource::ReturnResources( + previous_frame->delegated_frame_data->resource_list, + &previous_resources); + UnrefResources(previous_resources); + } } CompositorFrame* Surface::GetEligibleFrame() { return current_frame_.get(); } +void Surface::ReturnUnusedResourcesToClient() { + client_->ReturnResources(resources_available_to_return_); + resources_available_to_return_.clear(); +} + +void Surface::RefCurrentFrameResources() { + if (!current_frame_) + return; + const TransferableResourceArray& current_frame_resources = + current_frame_->delegated_frame_data->resource_list; + for (size_t i = 0; i < current_frame_resources.size(); ++i) { + const TransferableResource& resource = current_frame_resources[i]; + ResourceIdCountMap::iterator it = + resource_id_use_count_map_.find(resource.id); + DCHECK(it != resource_id_use_count_map_.end()); + it->second.refs_holding_resource_alive++; + } +} + +Surface::ResourceRefs::ResourceRefs() + : refs_received_from_child(0), refs_holding_resource_alive(0) { +} + +void Surface::ReceiveResourcesFromClient( + const TransferableResourceArray& resources) { + for (TransferableResourceArray::const_iterator it = resources.begin(); + it != resources.end(); + ++it) { + ResourceRefs& ref = resource_id_use_count_map_[it->id]; + ref.refs_holding_resource_alive++; + ref.refs_received_from_child++; + } +} + +void Surface::UnrefResources(const ReturnedResourceArray& resources) { + for (ReturnedResourceArray::const_iterator it = resources.begin(); + it != resources.end(); + ++it) { + ResourceProvider::ResourceId id = it->id; + ResourceIdCountMap::iterator count_it = resource_id_use_count_map_.find(id); + DCHECK(count_it != resource_id_use_count_map_.end()); + count_it->second.refs_holding_resource_alive -= it->count; + if (count_it->second.refs_holding_resource_alive == 0) { + resources_available_to_return_.push_back(*it); + resources_available_to_return_.back().count = + count_it->second.refs_received_from_child; + resource_id_use_count_map_.erase(count_it); + } + } +} + } // namespace cc |