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

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

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non-existing SkPicture::uniqueID() when dealing with display items without SkPictures Created 4 years, 7 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/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..c5f3111f9610c31a71a4329063155d6c4083855f
--- /dev/null
+++ b/blimp/common/compositor/blimp_picture_cache_registry.cc
@@ -0,0 +1,73 @@
+// 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 <map>
+#include <set>
+
+#include "base/logging.h"
+
+namespace blimp {
+
+BlimpPictureCacheRegistry::BlimpPictureCacheRegistry() {}
+
+BlimpPictureCacheRegistry::~BlimpPictureCacheRegistry() {}
+
+void BlimpPictureCacheRegistry::Stage(uint32_t item) {
+ auto it = staging_.find(item);
vmpstr 2016/05/25 01:54:06 This whole function is equivalent to: ++staging_[
nyquist 2016/05/26 01:08:09 Done.
+ if (it == staging_.end()) {
+ staging_.insert(std::make_pair(item, 1));
+ return;
+ }
+ ++it->second;
+}
+
+void BlimpPictureCacheRegistry::Unstage(uint32_t item) {
+ auto it = staging_.find(item);
+ if (it == staging_.end()) {
vmpstr 2016/05/25 01:54:06 If you skip this check (and please let me know why
nyquist 2016/05/26 01:08:09 Done.
+ NOTREACHED() << "Trying to unstage " << item
+ << " which has not been staged.";
+ return;
+ }
+ --it->second;
+ DCHECK_GE(it->second, 0U);
vmpstr 2016/05/25 01:54:06 unsigned value is always >= 0
nyquist 2016/05/26 01:08:09 ... Done.
+}
+
+void BlimpPictureCacheRegistry::Commit(std::set<uint32_t>* added_entries,
vmpstr 2016/05/25 01:54:06 Because these are generated from an std::map, this
nyquist 2016/05/26 01:08:09 Done.
+ std::set<uint32_t>* removed_entries) {
+ // Staged entries with 0 usage.
+ std::set<uint32_t> unused;
+ // Staged entries with > 0 usage.
+ std::set<uint32_t> used;
+
+ for (const auto& it : staging_) {
+ if (it.second > 0) {
vmpstr 2016/05/25 01:54:06 Maybe: auto& which = it.second > 0 ? used : unuse
nyquist 2016/05/26 01:08:09 Irrelevant after the rest of the change.
+ used.insert(it.first);
+ } else {
+ unused.insert(it.first);
+ }
+ }
+
+ // Remove unused entries from |committed_| and update |removed_entries|.
vmpstr 2016/05/25 01:54:06 Below here, you iterate over unused (without using
nyquist 2016/05/26 01:08:09 Done.
+ for (const auto it : unused) {
vmpstr 2016/05/25 01:54:06 don't name it "it" if it's not an iterator. Also,
nyquist 2016/05/26 01:08:09 Done.
+ if (committed_.find(it) != committed_.end()) {
+ committed_.erase(it);
+ removed_entries->insert(it);
+ }
+ // The entry has no references, so should not be staged anymore.
+ staging_.erase(it);
+ }
+
+ // Add new entries to |committed_| and update |added_entries|.
+ for (const auto it : used) {
+ if (committed_.find(it) == committed_.end()) {
+ committed_.insert(it);
+ added_entries->insert(it);
+ }
+ }
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698