Chromium Code Reviews| Index: blimp/common/compositor/reference_tracker.h |
| diff --git a/blimp/common/compositor/reference_tracker.h b/blimp/common/compositor/reference_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..57d41242ce33b4371235851c88e0eec10e97dfe8 |
| --- /dev/null |
| +++ b/blimp/common/compositor/reference_tracker.h |
| @@ -0,0 +1,58 @@ |
| +// 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_REFERENCE_TRACKER_H_ |
| +#define BLIMP_COMMON_COMPOSITOR_REFERENCE_TRACKER_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 { |
| + |
| +// ReferenceTracker 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 |
|
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
|
| +// positive reference count since last call to CommitRefCounts(). |
| +// CommitRefCounts() functions provides the deltas since last call to Commit(), |
| +// as sets of added and removed entries. |
| +// The important thing for any given item is whether it is in a state of having |
| +// positive reference count at the time of the call to CommitRefCounts(), not |
| +// how the reference count changed overtime in-between two calls to |
| +// CommitRefCounts(). |
| +class BLIMP_COMMON_EXPORT ReferenceTracker { |
| + public: |
| + ReferenceTracker(); |
| + ~ReferenceTracker(); |
| + |
| + // 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.
|
| + // 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 still have a positive reference count |
| + // since last call to CommitRefCounts() and provides calculated delta in the |
| + // output params |added_items| and |removed_items|. |
| + void CommitRefCounts(std::vector<uint32_t>* added_items, |
| + 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> active_ref_counts_; |
| + |
| + // The full set of all committed items. |
| + std::unordered_set<uint32_t> committed_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ReferenceTracker); |
| +}; |
| + |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_COMMON_COMPOSITOR_REFERENCE_TRACKER_H_ |