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/blimp_picture_cache_registry.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 BlimpPictureCacheRegistry::BlimpPictureCacheRegistry() {} |
| 17 |
| 18 BlimpPictureCacheRegistry::~BlimpPictureCacheRegistry() {} |
| 19 |
| 20 void BlimpPictureCacheRegistry::IncrementRefCount(uint32_t item) { |
| 21 ++used_item_ref_counts_[item]; |
| 22 } |
| 23 |
| 24 void BlimpPictureCacheRegistry::DecrementRefCount(uint32_t item) { |
| 25 DCHECK_GT(used_item_ref_counts_[item], 0u); |
| 26 --used_item_ref_counts_[item]; |
| 27 } |
| 28 |
| 29 void BlimpPictureCacheRegistry::Commit(std::vector<uint32_t>* added_entries, |
| 30 std::vector<uint32_t>* removed_entries) { |
| 31 for (auto it = used_item_ref_counts_.begin(); |
| 32 it != used_item_ref_counts_.end();) { |
| 33 uint32_t key = it->first; |
| 34 uint32_t ref_count = it->second; |
| 35 bool is_committed = committed_.count(key) > 0u; |
| 36 if (ref_count > 0u) { |
| 37 if (!is_committed) { |
| 38 committed_.insert(key); |
| 39 added_entries->push_back(key); |
| 40 } |
| 41 ++it; |
| 42 } else { |
| 43 if (is_committed) { |
| 44 committed_.erase(key); |
| 45 removed_entries->push_back(key); |
| 46 } |
| 47 // The entry has no references, so should not be staged anymore. |
| 48 it = used_item_ref_counts_.erase(it); |
| 49 } |
| 50 } |
| 51 } |
| 52 |
| 53 } // namespace blimp |
OLD | NEW |