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_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |
| 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <memory> |
| 10 #include <unordered_map> |
| 11 #include <unordered_set> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/logging.h" |
| 15 #include "base/macros.h" |
| 16 #include "blimp/common/compositor/reference_tracker.h" |
| 17 #include "cc/blimp/client_picture_cache.h" |
| 18 #include "cc/blimp/engine_picture_cache.h" |
| 19 #include "cc/blimp/picture_data.h" |
| 20 #include "third_party/skia/include/core/SkPicture.h" |
| 21 #include "third_party/skia/include/core/SkRefCnt.h" |
| 22 |
| 23 namespace blimp { |
| 24 namespace client { |
| 25 |
| 26 // BlimpClientPictureCache provides functionality for caching SkPictures once |
| 27 // they are received from the engine, and cleaning up once the pictures are no |
| 28 // longer in use. It is required to update this cache when an SkPicture starts |
| 29 // being used and when it is not longer in use by calling |
| 30 // MarkPictureForRegistration and MarkPictureForUnregistration respectively. |
| 31 class BlimpClientPictureCache : public cc::ClientPictureCache { |
| 32 public: |
| 33 explicit BlimpClientPictureCache( |
| 34 SkPicture::InstallPixelRefProc pixel_deserializer); |
| 35 ~BlimpClientPictureCache() override; |
| 36 |
| 37 // cc::ClientPictureCache implementation. |
| 38 sk_sp<const SkPicture> GetPicture(uint32_t engine_picture_id) override; |
| 39 void ApplyCacheUpdate( |
| 40 const std::vector<cc::PictureData>& cache_update) override; |
| 41 void Flush() override; |
| 42 void MarkUsed(uint32_t engine_picture_id) override; |
| 43 |
| 44 private: |
| 45 // Removes all pictures specified in |picture_ids| from |pictures_|. The |
| 46 // picture IDs passed to this function must refer to the pictures that are no |
| 47 // longer in use. |
| 48 void RemoveUnusedPicturesFromCache(const std::vector<uint32_t>& picture_ids); |
| 49 |
| 50 // Retrieves the SkPicture with the given |picture_id| from the cache. The |
| 51 // given |picture_id| is the unique ID that the engine used to identify the |
| 52 // picture in the cc::PictureCacheUpdate that contained the image. |
| 53 sk_sp<const SkPicture> GetPictureFromCache(uint32_t picture_id); |
| 54 |
| 55 // Verify that the incoming cache update matches the new items that were added |
| 56 // to the |reference_tracker_|. |
| 57 void VerifyCacheUpdateMatchesReferenceTrackerData( |
| 58 const std::vector<uint32_t>& new_tracked_items); |
| 59 |
| 60 #if DCHECK_IS_ON() |
| 61 // A set of the items that were added when the last cache update was applied. |
| 62 // Used for verifying that the calculation from the registry matches the |
| 63 // expectations. |
| 64 std::unordered_set<uint32_t> last_added_; |
| 65 #endif // DCHECK_IS_ON() |
| 66 |
| 67 // A function pointer valid to use for deserializing images when |
| 68 // using SkPicture::CreateFromStream to create an SkPicture from a stream. |
| 69 SkPicture::InstallPixelRefProc pixel_deserializer_; |
| 70 |
| 71 // The current cache of SkPictures. The key is the unique ID used by the |
| 72 // engine, and the value is the SkPicture itself. |
| 73 std::unordered_map<uint32_t, sk_sp<const SkPicture>> pictures_; |
| 74 |
| 75 // The reference tracker maintains the reference count of used SkPictures. |
| 76 ReferenceTracker reference_tracker_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(BlimpClientPictureCache); |
| 79 }; |
| 80 |
| 81 } // namespace client |
| 82 } // namespace blimp |
| 83 |
| 84 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |
OLD | NEW |