Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_COMMON_COMPOSITOR_BLIMP_PICTURE_CACHE_REGISTRY_H_ | |
| 6 #define BLIMP_COMMON_COMPOSITOR_BLIMP_PICTURE_CACHE_REGISTRY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <map> | |
| 10 #include <set> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "blimp/common/blimp_common_export.h" | |
| 15 | |
| 16 namespace blimp { | |
| 17 | |
| 18 // BlimpPictureCacheRegistry provides functionality to count the number of | |
| 19 // references to a given item, and a way of retrieving the delta in the number | |
| 20 // of items with a positive reference count since last call to Commit(). | |
| 21 // Commit() functions provides the deltas since last call to Commit(), as sets | |
| 22 // of added and removed entries. | |
| 23 // It is not necessary to increment the ref count for an item if it has already | |
| 24 // been committed. Only changes to the reference count need to be informed. | |
| 25 // It is illegal to have a negative reference count. | |
| 26 class BLIMP_COMMON_EXPORT BlimpPictureCacheRegistry { | |
| 27 public: | |
| 28 BlimpPictureCacheRegistry(); | |
| 29 ~BlimpPictureCacheRegistry(); | |
| 30 | |
| 31 // Increment the reference count for an |item|. Must be called before | |
| 32 // DecrementRefCount for that item. | |
| 33 void IncrementRefCount(uint32_t item); | |
| 34 | |
| 35 // Decrement the reference count for an |item|. | |
| 36 void DecrementRefCount(uint32_t item); | |
| 37 | |
| 38 // Calculates the delta of items that have a positive reference count since | |
| 39 // since last call to Commit() and provides the result in the output params | |
| 40 // |added_items| and |removed_items|. | |
| 41 void Commit(std::vector<uint32_t>* added_items, | |
| 42 std::vector<uint32_t>* removed_items); | |
| 43 | |
| 44 private: | |
| 45 // A reference count for all the given items. The key is the item, and the | |
| 46 // value is the count for that item. | |
| 47 std::map<uint32_t, uint32_t> used_item_ref_counts_; | |
|
vmpstr
2016/06/01 00:10:56
std::unordered_map
nyquist
2016/06/04 00:24:57
Done.
| |
| 48 | |
| 49 // The full set of all committed items. | |
| 50 std::set<uint32_t> committed_; | |
|
vmpstr
2016/06/01 00:10:56
std::unordered_set
nyquist
2016/06/04 00:24:57
Done.
| |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(BlimpPictureCacheRegistry); | |
| 53 }; | |
| 54 | |
| 55 } // namespace blimp | |
| 56 | |
| 57 #endif // BLIMP_COMMON_COMPOSITOR_BLIMP_PICTURE_CACHE_REGISTRY_H_ | |
| OLD | NEW |