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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 <map>
9 #include <set>
10
11 #include "base/logging.h"
12
13 namespace blimp {
14
15 BlimpPictureCacheRegistry::BlimpPictureCacheRegistry() {}
16
17 BlimpPictureCacheRegistry::~BlimpPictureCacheRegistry() {}
18
19 void BlimpPictureCacheRegistry::Stage(uint32_t item) {
20 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.
21 if (it == staging_.end()) {
22 staging_.insert(std::make_pair(item, 1));
23 return;
24 }
25 ++it->second;
26 }
27
28 void BlimpPictureCacheRegistry::Unstage(uint32_t item) {
29 auto it = staging_.find(item);
30 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.
31 NOTREACHED() << "Trying to unstage " << item
32 << " which has not been staged.";
33 return;
34 }
35 --it->second;
36 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.
37 }
38
39 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.
40 std::set<uint32_t>* removed_entries) {
41 // Staged entries with 0 usage.
42 std::set<uint32_t> unused;
43 // Staged entries with > 0 usage.
44 std::set<uint32_t> used;
45
46 for (const auto& it : staging_) {
47 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.
48 used.insert(it.first);
49 } else {
50 unused.insert(it.first);
51 }
52 }
53
54 // 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.
55 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.
56 if (committed_.find(it) != committed_.end()) {
57 committed_.erase(it);
58 removed_entries->insert(it);
59 }
60 // The entry has no references, so should not be staged anymore.
61 staging_.erase(it);
62 }
63
64 // Add new entries to |committed_| and update |added_entries|.
65 for (const auto it : used) {
66 if (committed_.find(it) == committed_.end()) {
67 committed_.insert(it);
68 added_entries->insert(it);
69 }
70 }
71 }
72
73 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698