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..c24478d57b7c2aa2d51684077e1e2a7445933255 |
| --- /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 uint32_t, and a way of retrieving the delta in the number of items |
| +// with a 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|. |
| + void IncrementRefCount(uint32_t item); |
| + |
| + // Decrement the reference count for an |item|. Negative reference counts are |
| + // not allowed. |
| + 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_; |
|
vmpstr
2016/06/16 22:09:58
i think the value can just be "int"
nyquist
2016/06/24 11:11:14
Done.
|
| + |
| + // 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_ |