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_REFERENCE_TRACKER_H_ | |
| 6 #define BLIMP_COMMON_COMPOSITOR_REFERENCE_TRACKER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <unordered_map> | |
| 10 #include <unordered_set> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "blimp/common/blimp_common_export.h" | |
| 15 | |
| 16 namespace blimp { | |
| 17 | |
| 18 // ReferenceTracker provides functionality to count the number of references to | |
| 19 // a given item, and a way of retrieving the delta in the number of items with a | |
|
Kevin M
2016/06/11 00:29:32
nit: item => int32? Using a general term for "item
nyquist
2016/06/14 01:37:57
I guess it technically could be templatized, but I
| |
| 20 // positive reference count since last call to CommitRefCounts(). | |
| 21 // CommitRefCounts() functions provides the deltas since last call to Commit(), | |
| 22 // as sets of added and removed entries. | |
| 23 // The important thing for any given item is whether it is in a state of having | |
| 24 // positive reference count at the time of the call to CommitRefCounts(), not | |
| 25 // how the reference count changed overtime in-between two calls to | |
| 26 // CommitRefCounts(). | |
| 27 class BLIMP_COMMON_EXPORT ReferenceTracker { | |
| 28 public: | |
| 29 ReferenceTracker(); | |
| 30 ~ReferenceTracker(); | |
| 31 | |
| 32 // Increment the reference count for an |item|. Must be called before | |
|
Kevin M
2016/06/11 00:29:32
The second sentence might be better on Decrement,
nyquist
2016/06/14 01:37:57
Done.
| |
| 33 // DecrementRefCount for that item. | |
| 34 void IncrementRefCount(uint32_t item); | |
| 35 | |
| 36 // Decrement the reference count for an |item|. | |
| 37 void DecrementRefCount(uint32_t item); | |
| 38 | |
| 39 // Calculates the delta of items that still have a positive reference count | |
| 40 // since last call to CommitRefCounts() and provides calculated delta in the | |
| 41 // output params |added_items| and |removed_items|. | |
| 42 void CommitRefCounts(std::vector<uint32_t>* added_items, | |
| 43 std::vector<uint32_t>* removed_items); | |
| 44 | |
| 45 private: | |
| 46 // A reference count for all the given items. The key is the item, and the | |
| 47 // value is the count for that item. | |
| 48 std::unordered_map<uint32_t, uint32_t> active_ref_counts_; | |
| 49 | |
| 50 // The full set of all committed items. | |
| 51 std::unordered_set<uint32_t> committed_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(ReferenceTracker); | |
| 54 }; | |
| 55 | |
| 56 } // namespace blimp | |
| 57 | |
| 58 #endif // BLIMP_COMMON_COMPOSITOR_REFERENCE_TRACKER_H_ | |
| OLD | NEW |