Index: blimp/common/compositor/blimp_picture_cache_registry.h |
diff --git a/blimp/common/compositor/blimp_picture_cache_registry.h b/blimp/common/compositor/blimp_picture_cache_registry.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b324f91a860af2f679ed218e38a915b81e628641 |
--- /dev/null |
+++ b/blimp/common/compositor/blimp_picture_cache_registry.h |
@@ -0,0 +1,57 @@ |
+// 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. |
+ |
+#ifndef BLIMP_COMMON_COMPOSITOR_BLIMP_PICTURE_CACHE_REGISTRY_H_ |
+#define BLIMP_COMMON_COMPOSITOR_BLIMP_PICTURE_CACHE_REGISTRY_H_ |
+ |
+#include <stdint.h> |
+#include <unordered_map> |
+#include <unordered_set> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "blimp/common/blimp_common_export.h" |
+ |
+namespace blimp { |
+ |
+// BlimpPictureCacheRegistry provides functionality to count the number of |
+// references to a given item, and a way of retrieving the delta in the number |
+// of items with a positive reference count since last call to Commit(). |
Kevin M
2016/06/06 23:33:58
...of uncommitted items
nyquist
2016/06/10 22:02:24
But it also provides the delta for items that were
|
+// Commit() functions provides the deltas since last call to Commit(), as sets |
+// of added and removed entries. |
+// It is not necessary to increment the ref count for an item if it has already |
+// been committed. Only changes to the reference count need to be informed. |
Kevin M
2016/06/06 23:33:58
It's not the ref count change that matters, it's t
nyquist
2016/06/10 22:02:24
Tried to clarify.
|
+// It is illegal to have a negative reference count. |
+class BLIMP_COMMON_EXPORT BlimpPictureCacheRegistry { |
+ public: |
+ BlimpPictureCacheRegistry(); |
+ ~BlimpPictureCacheRegistry(); |
+ |
+ // Increment the reference count for an |item|. Must be called before |
+ // DecrementRefCount for that item. |
+ void IncrementRefCount(uint32_t item); |
+ |
+ // Decrement the reference count for an |item|. |
+ void DecrementRefCount(uint32_t item); |
+ |
+ // Calculates the delta of items that have a positive reference count since |
+ // since last call to Commit() and provides the result in the output params |
+ // |added_items| and |removed_items|. |
+ void Commit(std::vector<uint32_t>* added_items, |
Kevin M
2016/06/06 23:33:58
"Commit"() seems like it's mixing in concepts from
nyquist
2016/06/10 22:02:24
You're right, it's technically calculating the del
|
+ std::vector<uint32_t>* removed_items); |
+ |
+ private: |
+ // A reference count for all the given items. The key is the item, and the |
+ // value is the count for that item. |
+ std::unordered_map<uint32_t, uint32_t> used_item_ref_counts_; |
+ |
+ // The full set of all committed items. |
+ std::unordered_set<uint32_t> committed_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BlimpPictureCacheRegistry); |
+}; |
+ |
+} // namespace blimp |
+ |
+#endif // BLIMP_COMMON_COMPOSITOR_BLIMP_PICTURE_CACHE_REGISTRY_H_ |