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 <memory> | |
9 #include <unordered_map> | |
Kevin M
2016/06/06 23:33:58
already included in .h, ditto for stdint, memory
nyquist
2016/06/10 22:02:23
Done.
| |
10 #include <utility> | |
11 #include <vector> | |
12 | |
13 #include "base/logging.h" | |
14 #include "blimp/common/compositor/blimp_picture_cache_registry.h" | |
15 #include "cc/proto/picture_cache.h" | |
16 #include "third_party/skia/include/core/SkPicture.h" | |
17 #include "third_party/skia/include/core/SkRefCnt.h" | |
18 #include "third_party/skia/include/core/SkStream.h" | |
19 | |
20 namespace blimp { | |
21 namespace client { | |
22 | |
23 namespace { | |
24 // Helper function to deserialize the content of |picture_data| into an | |
25 // SkPicture. | |
26 sk_sp<const SkPicture> DeserializePicture( | |
27 SkPicture::InstallPixelRefProc pixel_deserializer, | |
28 const cc::PictureData& picture_data) { | |
29 SkMemoryStream stream(picture_data.data); | |
30 return SkPicture::MakeFromStream(&stream, pixel_deserializer); | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 BlimpClientPictureCache::BlimpClientPictureCache( | |
36 SkPicture::InstallPixelRefProc pixel_deserializer) | |
37 : pixel_deserializer_(pixel_deserializer) {} | |
38 | |
39 BlimpClientPictureCache::~BlimpClientPictureCache() = default; | |
40 | |
41 sk_sp<const SkPicture> BlimpClientPictureCache::GetPicture( | |
42 uint32_t engine_picture_id) { | |
43 DCHECK(pictures_.find(engine_picture_id) != pictures_.end()); | |
44 return pictures_[engine_picture_id]; | |
45 } | |
46 | |
47 void BlimpClientPictureCache::ApplyCacheUpdate( | |
48 const cc::PictureCacheUpdate& cache_update) { | |
49 for (const cc::PictureData& picture_data : cache_update) { | |
50 sk_sp<const SkPicture> deserialized_picture = | |
51 DeserializePicture(pixel_deserializer_, picture_data); | |
52 DCHECK(pictures_.find(picture_data.unique_id) == pictures_.end()); | |
Kevin M
2016/06/06 23:33:58
DCHECK_EQ(expected, actual)
nyquist
2016/06/10 22:02:24
I'm not sure I like that for iterators. Are you ce
| |
53 | |
54 pictures_[picture_data.unique_id] = std::move(deserialized_picture); | |
55 | |
56 #if DCHECK_IS_ON() | |
57 last_added_.insert(picture_data.unique_id); | |
58 #endif | |
59 } | |
60 } | |
61 | |
62 void BlimpClientPictureCache::Flush() { | |
63 std::vector<uint32_t> added; | |
64 std::vector<uint32_t> removed; | |
65 registry_.Commit(&added, &removed); | |
66 | |
67 #if DCHECK_IS_ON() | |
68 // Verify that the incoming cache update matches the new items. | |
69 DCHECK_EQ(added.size(), last_added_.size()); | |
70 DCHECK(std::unordered_set<uint32_t>(added.begin(), added.end()) == | |
71 last_added_); | |
72 last_added_.clear(); | |
73 #endif | |
74 | |
75 for (const auto& it : removed) { | |
76 auto entry = pictures_.find(it); | |
77 DCHECK(entry != pictures_.end()); | |
Kevin M
2016/06/06 23:33:58
DCHECK_NE
Kevin M
2016/06/06 23:33:58
Is it possible that this could happen at release t
nyquist
2016/06/10 22:02:24
It's just a sanity check. If it happens it's a bug
| |
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 |