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 #ifndef BLIMP_ENGINE_RENDERER_BLIMP_ENGINE_PICTURE_CACHE_H_ | |
6 #define BLIMP_ENGINE_RENDERER_BLIMP_ENGINE_PICTURE_CACHE_H_ | |
7 | |
8 #include <memory> | |
9 #include <unordered_map> | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "blimp/common/compositor/reference_tracker.h" | |
14 #include "cc/proto/picture_cache.h" | |
15 #include "third_party/skia/include/core/SkPicture.h" | |
16 | |
17 class SkPixelSerializer; | |
18 | |
19 namespace blimp { | |
20 namespace engine { | |
21 | |
22 // BlimpEnginePictureCache provides functionality for caching SkPictures before | |
23 // they are sent from the engine to the client. The cache is cleared after | |
24 // every time it is flushed which happens when CalculateCacheUpdateAndFlush() | |
25 // is called. The expected state of what the client already has cached is | |
26 // tracked. It is required to update this cache when an SkPicture | |
27 // starts being used and when it is not longer in use by calling | |
28 // MarkPictureForRegistration and MarkPictureForUnregistration respectively. | |
29 // The lifetime of a cache matches the lifetime of a specific compositor. | |
Kevin M
2016/06/11 00:29:33
What's the threading situation like for this class
nyquist
2016/06/14 01:37:57
Only ever on the main thread. Added a comment to c
| |
30 class BlimpEnginePictureCache : public cc::EnginePictureCache { | |
31 public: | |
32 explicit BlimpEnginePictureCache(SkPixelSerializer* pixel_serializer); | |
33 ~BlimpEnginePictureCache() override; | |
34 | |
35 // cc::EnginePictureCache implementation. | |
36 void MarkPictureForUnregistration(const SkPicture* picture) override; | |
37 void MarkPictureForRegistration(const SkPicture* picture) override; | |
38 cc::PictureCacheUpdate CalculateCacheUpdateAndFlush() override; | |
39 | |
40 private: | |
41 // Serializes the SkPicture and adds it to |pictures_|. | |
42 void SerializePictureAndAddToCache(const SkPicture* picture); | |
43 | |
44 // Returns whether |pictures_| currently contains the |picture|. | |
45 bool CacheContainsPicture(const SkPicture* picture); | |
Kevin M
2016/06/11 00:29:33
nit: make this const?
nyquist
2016/06/14 01:37:57
Done.
| |
46 | |
47 // A serializer that be used to pass in to SkPicture::serialize(...) for | |
48 // serializing the SkPicture to a stream. | |
49 SkPixelSerializer* pixel_serializer_; | |
50 | |
51 // The current cache of pictures. Used for temporarily storing pictures until | |
52 // the next call to CalculateCacheUpdateAndFlush(), at which point this map | |
53 // is cleared. | |
54 std::unordered_map<uint32_t, cc::PictureData> pictures_; | |
55 | |
56 // The reference tracker maintains the reference count of used SkPictures. | |
57 ReferenceTracker reference_tracker_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(BlimpEnginePictureCache); | |
60 }; | |
61 | |
62 } // namespace engine | |
63 } // namespace blimp | |
64 | |
65 #endif // BLIMP_ENGINE_RENDERER_BLIMP_ENGINE_PICTURE_CACHE_H_ | |
OLD | NEW |