Chromium Code Reviews| Index: blimp/client/feature/compositor/blimp_client_picture_cache.h |
| diff --git a/blimp/client/feature/compositor/blimp_client_picture_cache.h b/blimp/client/feature/compositor/blimp_client_picture_cache.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..829fe85d2c8273a2fe22e25ad96c72cee74ee2e2 |
| --- /dev/null |
| +++ b/blimp/client/feature/compositor/blimp_client_picture_cache.h |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |
| +#define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |
| + |
| +#include <stdint.h> |
| +#include <memory> |
| +#include <unordered_map> |
| +#include <unordered_set> |
| + |
| +#include "base/logging.h" |
| +#include "base/macros.h" |
| +#include "blimp/common/compositor/reference_tracker.h" |
| +#include "cc/proto/picture_cache.h" |
| +#include "third_party/skia/include/core/SkPicture.h" |
| +#include "third_party/skia/include/core/SkRefCnt.h" |
| + |
| +namespace blimp { |
| +namespace client { |
| + |
| +// BlimpClientPictureCache provides functionality for caching SkPictures once |
| +// they are received from the engine, and cleaning up once the pictures are no |
| +// longer in use. It is required to update this cache when an SkPicture starts |
| +// being used and when it is not longer in use by calling |
| +// MarkPictureForRegistration and MarkPictureForUnregistration respectively. |
| +class BlimpClientPictureCache : public cc::ClientPictureCache { |
|
vmpstr
2016/06/16 22:09:58
might need an export
nyquist
2016/06/24 11:11:14
Wouldn't that lead to some kind of compile error o
|
| + public: |
| + explicit BlimpClientPictureCache( |
| + SkPicture::InstallPixelRefProc pixel_deserializer); |
| + ~BlimpClientPictureCache() override; |
| + |
| + // cc::ClientPictureCache implementation. |
| + sk_sp<const SkPicture> GetPicture(uint32_t engine_picture_id) override; |
| + void ApplyCacheUpdate(const cc::PictureCacheUpdate& cache_update) override; |
| + void Flush() override; |
| + void MarkPictureForUnregistration(uint32_t engine_picture_id) override; |
| + void MarkPictureForRegistration(uint32_t engine_picture_id) override; |
| + |
| + private: |
| + // Adds new pictures from the |cache_update| to |pictures_|. |
| + void AddNewPicturesToCache(const cc::PictureCacheUpdate& cache_update); |
| + |
| + // Removes all unusued pictures from |pictures_|. |
| + void RemoveUnusedPicturesFromCache(const std::vector<uint32_t>& picture_ids); |
|
vmpstr
2016/06/16 22:09:58
comment on what the parameter is
nyquist
2016/06/24 11:11:14
Done.
|
| + |
| + // Retrieves the SkPicture with the given |picture_id| from the cache. The |
| + // given |picture_id| is the unique ID that the engine used to identify the |
| + // picture in the cc::PictureCacheUpdate that contained the image. |
| + sk_sp<const SkPicture> GetPictureFromCache(uint32_t picture_id); |
| + |
| +#if DCHECK_IS_ON() |
| + // Verify that the incoming cache update matches the new items that were added |
| + // to the |reference_tracker_|. |
| + void VerifyCacheUpdateMatchesReferenceTrackerData( |
| + const std::vector<uint32_t>& new_tracked_items); |
| + |
| + // A set of the items that were added when the last cache update was applied. |
| + // Used for verifying that the calculation from the registry matches the |
| + // expectations. |
| + std::unordered_set<uint32_t> last_added_; |
| +#endif // DCHECK_IS_ON() |
| + |
| + // A function pointer valid to use for deserializing images when |
| + // using SkPicture::CreateFromStream to create an SkPicture from a stream. |
| + SkPicture::InstallPixelRefProc pixel_deserializer_; |
| + |
| + // The current cache of SkPictures. The key is the unique ID used by the |
| + // engine, and the value is the SkPicture itself. |
| + std::unordered_map<uint32_t, sk_sp<const SkPicture>> pictures_; |
| + |
| + // The reference tracker maintains the reference count of used SkPictures. |
| + ReferenceTracker reference_tracker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlimpClientPictureCache); |
| +}; |
| + |
| +} // namespace client |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |