Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: blimp/common/compositor/reference_tracker.cc

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from vmpstr, including adding //cc/blimp Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/common/compositor/reference_tracker.h ('k') | blimp/common/compositor/reference_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/common/compositor/reference_tracker.cc
diff --git a/blimp/common/compositor/reference_tracker.cc b/blimp/common/compositor/reference_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d5a2edc3a6d3214f45579643c83aa4743314aab5
--- /dev/null
+++ b/blimp/common/compositor/reference_tracker.cc
@@ -0,0 +1,63 @@
+// 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/reference_tracker.h"
+
+#include <stdint.h>
+#include <unordered_map>
+#include <unordered_set>
+#include <vector>
+
+#include "base/logging.h"
+
+namespace blimp {
+
+ReferenceTracker::ReferenceTracker() {}
+
+ReferenceTracker::~ReferenceTracker() {}
+
+void ReferenceTracker::IncrementRefCount(uint32_t item) {
+ ++active_ref_counts_[item];
+}
+
+void ReferenceTracker::DecrementRefCount(uint32_t item) {
+ DCHECK_GT(active_ref_counts_[item], 0);
+ --active_ref_counts_[item];
+}
+
+void ReferenceTracker::ClearRefCounts() {
+ for (auto it = active_ref_counts_.begin(); it != active_ref_counts_.end();
+ ++it) {
+ it->second = 0;
+ }
+}
+
+void ReferenceTracker::CommitRefCounts(std::vector<uint32_t>* added_entries,
+ std::vector<uint32_t>* removed_entries) {
+ DCHECK(added_entries);
+ DCHECK(removed_entries);
+ for (auto it = active_ref_counts_.begin(); it != active_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) {
+ // The entry is new and has a positive reference count, so needs commit.
+ committed_.insert(key);
+ added_entries->push_back(key);
+ }
+ ++it;
+ } else {
+ if (is_committed) {
+ // The entry has already been committed, but is not reference anymore.
+ committed_.erase(key);
+ removed_entries->push_back(key);
+ }
+ // The entry has no references, so should not be staged anymore.
+ it = active_ref_counts_.erase(it);
+ }
+ }
+}
+
+} // namespace blimp
« no previous file with comments | « blimp/common/compositor/reference_tracker.h ('k') | blimp/common/compositor/reference_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698