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/engine/renderer/blimp_engine_picture_cache.h" | |
6 | |
7 #include <sstream> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/memory/ptr_util.h" | |
11 #include "third_party/skia/include/core/SkStream.h" | |
12 | |
13 namespace blimp { | |
14 namespace engine { | |
15 | |
16 BlimpEnginePictureCache::BlimpEnginePictureCache( | |
17 SkPixelSerializer* pixel_serializer) | |
Kevin M
2016/06/11 00:29:33
DCHECK(pixel_serializer)
nyquist
2016/06/14 01:37:57
A nullptr pixel serializer ends up using the defau
| |
18 : pixel_serializer_(pixel_serializer) {} | |
19 | |
20 BlimpEnginePictureCache::~BlimpEnginePictureCache() = default; | |
21 | |
22 void BlimpEnginePictureCache::MarkPictureForUnregistration( | |
23 const SkPicture* picture) { | |
Kevin M
2016/06/11 00:29:32
DCHECK(picture)
nyquist
2016/06/14 01:37:57
Done.
| |
24 reference_tracker_.DecrementRefCount(picture->uniqueID()); | |
25 } | |
26 | |
27 void BlimpEnginePictureCache::MarkPictureForRegistration( | |
28 const SkPicture* picture) { | |
Kevin M
2016/06/11 00:29:33
DCHECK(picture)
nyquist
2016/06/14 01:37:57
Done.
| |
29 reference_tracker_.IncrementRefCount(picture->uniqueID()); | |
30 | |
31 // Do not serialize multiple times, even though the item is referred to from | |
32 // multiple places. | |
33 if (CacheContainsPicture(picture)) { | |
34 return; | |
35 } | |
36 | |
37 SerializePictureAndAddToCache(picture); | |
38 } | |
39 | |
40 cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { | |
41 std::vector<uint32_t> added; | |
42 std::vector<uint32_t> removed; | |
43 reference_tracker_.CommitRefCounts(&added, &removed); | |
44 | |
45 // Create cache update consisting of new pictures. | |
46 cc::PictureCacheUpdate update; | |
47 for (const uint32_t item : added) { | |
48 auto entry = pictures_.find(item); | |
49 if (entry == pictures_.end()) { | |
50 DLOG(ERROR) << "Picture map does not contain item " << item; | |
Kevin M
2016/06/11 00:29:33
How messed up is it if this happens? If the answer
nyquist
2016/06/14 01:37:57
Pretty messed up.
Done.
| |
51 continue; | |
52 } | |
53 update.push_back(entry->second); | |
54 } | |
55 | |
56 // All new items will be sent to client, so clear everything. | |
Kevin M
2016/06/11 00:29:32
the client
nyquist
2016/06/14 01:37:57
Done.
| |
57 pictures_.clear(); | |
58 | |
59 return update; | |
60 } | |
61 | |
62 bool BlimpEnginePictureCache::CacheContainsPicture(const SkPicture* picture) { | |
63 return pictures_.find(picture->uniqueID()) != pictures_.end(); | |
64 } | |
65 | |
66 void BlimpEnginePictureCache::SerializePictureAndAddToCache( | |
67 const SkPicture* picture) { | |
68 SkDynamicMemoryWStream stream; | |
69 picture->serialize(&stream, pixel_serializer_); | |
70 DCHECK_GE(stream.bytesWritten(), 0u); | |
71 | |
72 // Store the picture data until it is sent to the client. | |
73 cc::PictureData picture_data; | |
74 picture_data.unique_id = picture->uniqueID(); | |
75 picture_data.data.reset(stream.copyToData()); | |
76 pictures_[picture_data.unique_id] = picture_data; | |
77 } | |
78 | |
79 } // namespace engine | |
80 } // namespace blimp | |
OLD | NEW |