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 #include "blimp/common/compositor/reference_tracker.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 #include <unordered_map> | |
| 9 #include <unordered_set> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/logging.h" | |
| 13 | |
| 14 namespace blimp { | |
| 15 | |
| 16 ReferenceTracker::ReferenceTracker() {} | |
| 17 | |
| 18 ReferenceTracker::~ReferenceTracker() {} | |
| 19 | |
| 20 void ReferenceTracker::IncrementRefCount(uint32_t item) { | |
| 21 ++active_ref_counts_[item]; | |
| 22 } | |
| 23 | |
| 24 void ReferenceTracker::DecrementRefCount(uint32_t item) { | |
| 25 DCHECK_GT(active_ref_counts_[item], 0u); | |
| 26 --active_ref_counts_[item]; | |
| 27 } | |
| 28 | |
| 29 void ReferenceTracker::CommitRefCounts(std::vector<uint32_t>* added_entries, | |
| 30 std::vector<uint32_t>* removed_entries) { | |
| 31 DCHECK(added_entries); | |
| 32 DCHECK(removed_entries); | |
| 33 for (auto it = active_ref_counts_.begin(); it != active_ref_counts_.end();) { | |
| 34 uint32_t key = it->first; | |
| 35 uint32_t ref_count = it->second; | |
| 36 bool is_committed = committed_.count(key) > 0u; | |
| 37 if (ref_count > 0u) { | |
| 38 if (!is_committed) { | |
| 39 committed_.insert(key); | |
|
Kevin M
2016/06/21 21:35:04
Add a one-line comment, like on 48?
nyquist
2016/06/24 11:11:15
Done.
| |
| 40 added_entries->push_back(key); | |
| 41 } | |
| 42 ++it; | |
| 43 } else { | |
| 44 if (is_committed) { | |
| 45 committed_.erase(key); | |
| 46 removed_entries->push_back(key); | |
| 47 } | |
| 48 // The entry has no references, so should not be staged anymore. | |
| 49 it = active_ref_counts_.erase(it); | |
| 50 } | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 } // namespace blimp | |
| OLD | NEW |