Index: blimp/common/compositor/blimp_picture_cache_registry.cc |
diff --git a/blimp/common/compositor/blimp_picture_cache_registry.cc b/blimp/common/compositor/blimp_picture_cache_registry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2a75f0779e31b0e2127292ff673fb7fa2abc00e8 |
--- /dev/null |
+++ b/blimp/common/compositor/blimp_picture_cache_registry.cc |
@@ -0,0 +1,53 @@ |
+// Copyright 2016 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 "blimp/common/compositor/blimp_picture_cache_registry.h" |
+ |
+#include <stdint.h> |
+#include <map> |
+#include <set> |
+#include <vector> |
+ |
+#include "base/logging.h" |
+ |
+namespace blimp { |
+ |
+BlimpPictureCacheRegistry::BlimpPictureCacheRegistry() {} |
+ |
+BlimpPictureCacheRegistry::~BlimpPictureCacheRegistry() {} |
+ |
+void BlimpPictureCacheRegistry::IncrementRefCount(uint32_t item) { |
+ ++used_item_ref_counts_[item]; |
+} |
+ |
+void BlimpPictureCacheRegistry::DecrementRefCount(uint32_t item) { |
+ DCHECK_GT(used_item_ref_counts_[item], 0U); |
vmpstr
2016/06/01 00:10:56
nit: lowercase u
nyquist
2016/06/04 00:24:57
Done.
|
+ --used_item_ref_counts_[item]; |
+} |
+ |
+void BlimpPictureCacheRegistry::Commit(std::vector<uint32_t>* added_entries, |
+ std::vector<uint32_t>* removed_entries) { |
+ for (auto it = used_item_ref_counts_.begin(); |
+ it != used_item_ref_counts_.end();) { |
+ uint32_t key = it->first; |
+ uint32_t ref_count = it->second; |
+ bool is_committed = committed_.find(key) != committed_.end(); |
vmpstr
2016/06/01 00:10:56
committed_.count(key) > 0;
nyquist
2016/06/04 00:24:57
Done.
|
+ if (ref_count > 0U) { |
vmpstr
2016/06/01 00:10:56
nit: same here.
nyquist
2016/06/04 00:24:57
Done.
|
+ if (!is_committed) { |
+ committed_.insert(key); |
+ added_entries->push_back(key); |
+ } |
+ ++it; |
+ } else { |
+ if (is_committed) { |
+ committed_.erase(key); |
+ removed_entries->push_back(key); |
+ } |
+ // The entry has no references, so should not be staged anymore. |
+ it = used_item_ref_counts_.erase(it); |
+ } |
+ } |
+} |
+ |
+} // namespace blimp |