Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3916)

Unified Diff: cc/surfaces/surface_resource_holder.cc

Issue 1531403002: Revert "Delete CC." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/surfaces/surface_resource_holder.h ('k') | cc/surfaces/surface_sequence.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/surface_resource_holder.cc
diff --git a/cc/surfaces/surface_resource_holder.cc b/cc/surfaces/surface_resource_holder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..50d31a584eef0021a28b4fef9a24c2d0205ae79c
--- /dev/null
+++ b/cc/surfaces/surface_resource_holder.cc
@@ -0,0 +1,69 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/surfaces/surface_resource_holder.h"
+
+#include "cc/surfaces/surface_factory_client.h"
+
+namespace cc {
+
+SurfaceResourceHolder::SurfaceResourceHolder(SurfaceFactoryClient* client)
+ : client_(client) {
+}
+
+SurfaceResourceHolder::~SurfaceResourceHolder() {
+}
+
+SurfaceResourceHolder::ResourceRefs::ResourceRefs()
+ : refs_received_from_child(0), refs_holding_resource_alive(0) {
+}
+
+void SurfaceResourceHolder::ReceiveFromChild(
+ 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 SurfaceResourceHolder::RefResources(
+ const TransferableResourceArray& resources) {
+ for (TransferableResourceArray::const_iterator it = resources.begin();
+ it != resources.end();
+ ++it) {
+ ResourceIdCountMap::iterator count_it =
+ resource_id_use_count_map_.find(it->id);
+ DCHECK(count_it != resource_id_use_count_map_.end());
+ count_it->second.refs_holding_resource_alive++;
+ }
+}
+
+void SurfaceResourceHolder::UnrefResources(
+ const ReturnedResourceArray& resources) {
+ ReturnedResourceArray resources_available_to_return;
+
+ 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);
+ if (count_it == resource_id_use_count_map_.end())
+ continue;
+ ResourceRefs& ref = count_it->second;
+ ref.refs_holding_resource_alive -= it->count;
+ if (ref.refs_holding_resource_alive == 0) {
+ ReturnedResource returned = *it;
+ returned.count = ref.refs_received_from_child;
+ resources_available_to_return.push_back(returned);
+ resource_id_use_count_map_.erase(count_it);
+ }
+ }
+
+ client_->ReturnResources(resources_available_to_return);
+}
+
+} // namespace cc
« no previous file with comments | « cc/surfaces/surface_resource_holder.h ('k') | cc/surfaces/surface_sequence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698