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

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 kmarshall 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
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..aa3d43f8d1c3f1f5ec4c63ae6053b274a065f467
--- /dev/null
+++ b/blimp/common/compositor/reference_tracker.cc
@@ -0,0 +1,54 @@
+// 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], 0u);
+ --active_ref_counts_[item];
+}
+
+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) {
+ committed_.insert(key);
Kevin M 2016/06/21 21:35:04 Add a one-line comment, like on 48?
nyquist 2016/06/24 11:11:15 Done.
+ 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 = active_ref_counts_.erase(it);
+ }
+ }
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698