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], 0); |
| 26 --active_ref_counts_[item]; |
| 27 } |
| 28 |
| 29 void ReferenceTracker::ClearRefCounts() { |
| 30 for (auto it = active_ref_counts_.begin(); it != active_ref_counts_.end(); |
| 31 ++it) { |
| 32 it->second = 0; |
| 33 } |
| 34 } |
| 35 |
| 36 void ReferenceTracker::CommitRefCounts(std::vector<uint32_t>* added_entries, |
| 37 std::vector<uint32_t>* removed_entries) { |
| 38 DCHECK(added_entries); |
| 39 DCHECK(removed_entries); |
| 40 for (auto it = active_ref_counts_.begin(); it != active_ref_counts_.end();) { |
| 41 uint32_t key = it->first; |
| 42 uint32_t ref_count = it->second; |
| 43 bool is_committed = committed_.count(key) > 0u; |
| 44 if (ref_count > 0u) { |
| 45 if (!is_committed) { |
| 46 // The entry is new and has a positive reference count, so needs commit. |
| 47 committed_.insert(key); |
| 48 added_entries->push_back(key); |
| 49 } |
| 50 ++it; |
| 51 } else { |
| 52 if (is_committed) { |
| 53 // The entry has already been committed, but is not reference anymore. |
| 54 committed_.erase(key); |
| 55 removed_entries->push_back(key); |
| 56 } |
| 57 // The entry has no references, so should not be staged anymore. |
| 58 it = active_ref_counts_.erase(it); |
| 59 } |
| 60 } |
| 61 } |
| 62 |
| 63 } // namespace blimp |
OLD | NEW |