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) { | |
Kevin M
2016/06/11 00:29:32
DCHECK added_entries and removed_entries
nyquist
2016/06/14 01:37:57
Done.
| |
31 for (auto it = active_ref_counts_.begin(); it != active_ref_counts_.end();) { | |
32 uint32_t key = it->first; | |
33 uint32_t ref_count = it->second; | |
34 bool is_committed = committed_.count(key) > 0u; | |
35 if (ref_count > 0u) { | |
36 if (!is_committed) { | |
37 committed_.insert(key); | |
38 added_entries->push_back(key); | |
39 } | |
40 ++it; | |
41 } else { | |
42 if (is_committed) { | |
43 committed_.erase(key); | |
44 removed_entries->push_back(key); | |
45 } | |
46 // The entry has no references, so should not be staged anymore. | |
47 it = active_ref_counts_.erase(it); | |
48 } | |
49 } | |
50 } | |
51 | |
52 } // namespace blimp | |
OLD | NEW |