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. |
| 30 // All interaction with this class should happen on the main thread. |
| 31 class BlimpEnginePictureCache : public cc::EnginePictureCache { |
| 32 public: |
| 33 explicit BlimpEnginePictureCache(SkPixelSerializer* pixel_serializer); |
| 34 ~BlimpEnginePictureCache() override; |
| 35 |
| 36 // cc::EnginePictureCache implementation. |
| 37 void MarkPictureForUnregistration(const SkPicture* picture) override; |
| 38 void MarkPictureForRegistration(const SkPicture* picture) override; |
| 39 cc::PictureCacheUpdate CalculateCacheUpdateAndFlush() override; |
| 40 |
| 41 private: |
| 42 // Serializes the SkPicture and adds it to |pictures_|. |
| 43 void SerializePictureAndAddToCache(const SkPicture* picture); |
| 44 |
| 45 // Returns whether |pictures_| currently contains the |picture|. |
| 46 bool CacheContainsPicture(const SkPicture* picture) const; |
| 47 |
| 48 // A serializer that be used to pass in to SkPicture::serialize(...) for |
| 49 // serializing the SkPicture to a stream. |
| 50 SkPixelSerializer* pixel_serializer_; |
| 51 |
| 52 // The current cache of pictures. Used for temporarily storing pictures until |
| 53 // the next call to CalculateCacheUpdateAndFlush(), at which point this map |
| 54 // is cleared. |
| 55 std::unordered_map<uint32_t, cc::PictureData> pictures_; |
| 56 |
| 57 // The reference tracker maintains the reference count of used SkPictures. |
| 58 ReferenceTracker reference_tracker_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(BlimpEnginePictureCache); |
| 61 }; |
| 62 |
| 63 } // namespace engine |
| 64 } // namespace blimp |
| 65 |
| 66 #endif // BLIMP_ENGINE_RENDERER_BLIMP_ENGINE_PICTURE_CACHE_H_ |
OLD | NEW |