Chromium Code Reviews| Index: blimp/common/compositor/reference_tracker.cc |
| diff --git a/blimp/common/compositor/reference_tracker.cc b/blimp/common/compositor/reference_tracker.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63f55d0acf00d1d05ea6266d34ebb791d8b3eeb8 |
| --- /dev/null |
| +++ b/blimp/common/compositor/reference_tracker.cc |
| @@ -0,0 +1,52 @@ |
| +// 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. |
| + |
| +#include "blimp/common/compositor/reference_tracker.h" |
| + |
| +#include <stdint.h> |
| +#include <unordered_map> |
| +#include <unordered_set> |
| +#include <vector> |
| + |
| +#include "base/logging.h" |
| + |
| +namespace blimp { |
| + |
| +ReferenceTracker::ReferenceTracker() {} |
| + |
| +ReferenceTracker::~ReferenceTracker() {} |
| + |
| +void ReferenceTracker::IncrementRefCount(uint32_t item) { |
| + ++active_ref_counts_[item]; |
| +} |
| + |
| +void ReferenceTracker::DecrementRefCount(uint32_t item) { |
| + DCHECK_GT(active_ref_counts_[item], 0u); |
| + --active_ref_counts_[item]; |
| +} |
| + |
| +void ReferenceTracker::CommitRefCounts(std::vector<uint32_t>* added_entries, |
| + std::vector<uint32_t>* removed_entries) { |
|
Kevin M
2016/06/11 00:29:32
DCHECK added_entries and removed_entries
nyquist
2016/06/14 01:37:57
Done.
|
| + for (auto it = active_ref_counts_.begin(); it != active_ref_counts_.end();) { |
| + uint32_t key = it->first; |
| + uint32_t ref_count = it->second; |
| + bool is_committed = committed_.count(key) > 0u; |
| + if (ref_count > 0u) { |
| + if (!is_committed) { |
| + committed_.insert(key); |
| + added_entries->push_back(key); |
| + } |
| + ++it; |
| + } else { |
| + if (is_committed) { |
| + committed_.erase(key); |
| + removed_entries->push_back(key); |
| + } |
| + // The entry has no references, so should not be staged anymore. |
| + it = active_ref_counts_.erase(it); |
| + } |
| + } |
| +} |
| + |
| +} // namespace blimp |