OLD | NEW |
---|---|
(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/client/feature/compositor/blimp_client_picture_cache.h" | |
6 | |
7 #include <stdint.h> | |
8 #include <map> | |
9 #include <memory> | |
10 #include <vector> | |
11 | |
12 #include "base/logging.h" | |
13 #include "blimp/common/compositor/blimp_picture_cache_registry.h" | |
14 #include "cc/proto/picture_cache.h" | |
15 #include "third_party/skia/include/core/SkPicture.h" | |
16 #include "third_party/skia/include/core/SkRefCnt.h" | |
17 #include "third_party/skia/include/core/SkStream.h" | |
18 | |
19 namespace blimp { | |
20 namespace client { | |
21 | |
22 namespace { | |
23 // Helper function to deserialize the content of |picture_data| into an | |
24 // SkPicture. | |
25 sk_sp<SkPicture> DeserializePicture( | |
26 SkPicture::InstallPixelRefProc pixel_deserializer, | |
27 const cc::PictureData& picture_data) { | |
28 SkMemoryStream stream(picture_data.data); | |
29 return SkPicture::MakeFromStream(&stream, pixel_deserializer); | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 BlimpClientPictureCache::BlimpClientPictureCache( | |
35 SkPicture::InstallPixelRefProc pixel_deserializer) | |
36 : pixel_deserializer_(pixel_deserializer) {} | |
37 | |
38 BlimpClientPictureCache::~BlimpClientPictureCache() {} | |
vmpstr
2016/06/01 00:10:56
nit: = default
nyquist
2016/06/04 00:24:57
Done.
| |
39 | |
40 sk_sp<const SkPicture> BlimpClientPictureCache::GetPicture( | |
41 uint32_t engine_picture_id) { | |
42 DCHECK(pictures_.find(engine_picture_id) != pictures_.end()); | |
43 return pictures_.find(engine_picture_id)->second; | |
vmpstr
2016/06/01 00:10:56
return pictures_[engine_picture_id];
nyquist
2016/06/04 00:24:57
Done.
| |
44 } | |
45 | |
46 void BlimpClientPictureCache::ApplyCacheUpdate( | |
47 const cc::PictureCacheUpdate& cache_update) { | |
48 for (const cc::PictureData& picture_data : cache_update) { | |
49 sk_sp<SkPicture> deserialized_picture = | |
vmpstr
2016/06/01 00:10:56
I think we need to be a bit more consistent with c
nyquist
2016/06/04 00:24:57
Done.
| |
50 DeserializePicture(pixel_deserializer_, picture_data); | |
51 DCHECK(pictures_.find(picture_data.unique_id) == pictures_.end()); | |
52 pictures_.insert( | |
53 std::make_pair(picture_data.unique_id, deserialized_picture)); | |
vmpstr
2016/06/01 00:10:56
I think pictures_.emplace(picture_data.unique_id,
nyquist
2016/06/04 00:24:57
Does this look OK?
| |
54 #if DCHECK_IS_ON() | |
55 last_added_.insert(picture_data.unique_id); | |
56 #endif | |
57 } | |
58 } | |
59 | |
60 void BlimpClientPictureCache::Flush() { | |
61 std::vector<uint32_t> added; | |
62 std::vector<uint32_t> removed; | |
63 registry_.Commit(&added, &removed); | |
64 | |
65 #if DCHECK_IS_ON() | |
66 // Verify that the incoming cache update matches the new items. | |
67 DCHECK_EQ(added.size(), last_added_.size()); | |
68 DCHECK(std::set<uint32_t>(added.begin(), added.end()) == last_added_); | |
69 last_added_.clear(); | |
70 #endif | |
71 | |
72 for (const auto& it : removed) { | |
73 auto entry = pictures_.find(it); | |
74 if (entry == pictures_.end()) { | |
75 NOTREACHED() << "PictureMap does not contain entry " << it; | |
vmpstr
2016/06/01 00:10:56
Can this if be a DCHECK instead? If not, can you a
nyquist
2016/06/04 00:24:57
Done.
| |
76 continue; | |
77 } | |
78 pictures_.erase(entry); | |
79 } | |
80 } | |
81 | |
82 void BlimpClientPictureCache::MarkPictureForUnregistration( | |
83 uint32_t engine_picture_id) { | |
84 registry_.DecrementRefCount(engine_picture_id); | |
85 } | |
86 | |
87 void BlimpClientPictureCache::MarkPictureForRegistration( | |
88 uint32_t engine_picture_id) { | |
89 registry_.IncrementRefCount(engine_picture_id); | |
90 } | |
91 | |
92 } // namespace client | |
93 } // namespace blimp | |
OLD | NEW |