| Index: blimp/common/compositor/blimp_picture_cache_registry.cc
|
| diff --git a/blimp/common/compositor/blimp_picture_cache_registry.cc b/blimp/common/compositor/blimp_picture_cache_registry.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3748fb01423b90a2947769930f380cf5398b1d23
|
| --- /dev/null
|
| +++ b/blimp/common/compositor/blimp_picture_cache_registry.cc
|
| @@ -0,0 +1,53 @@
|
| +// 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/blimp_picture_cache_registry.h"
|
| +
|
| +#include <stdint.h>
|
| +#include <unordered_map>
|
| +#include <unordered_set>
|
| +#include <vector>
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace blimp {
|
| +
|
| +BlimpPictureCacheRegistry::BlimpPictureCacheRegistry() {}
|
| +
|
| +BlimpPictureCacheRegistry::~BlimpPictureCacheRegistry() {}
|
| +
|
| +void BlimpPictureCacheRegistry::IncrementRefCount(uint32_t item) {
|
| + ++used_item_ref_counts_[item];
|
| +}
|
| +
|
| +void BlimpPictureCacheRegistry::DecrementRefCount(uint32_t item) {
|
| + DCHECK_GT(used_item_ref_counts_[item], 0u);
|
| + --used_item_ref_counts_[item];
|
| +}
|
| +
|
| +void BlimpPictureCacheRegistry::Commit(std::vector<uint32_t>* added_entries,
|
| + std::vector<uint32_t>* removed_entries) {
|
| + for (auto it = used_item_ref_counts_.begin();
|
| + it != used_item_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 = used_item_ref_counts_.erase(it);
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace blimp
|
|
|