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..e2ba73ae67de7633ea17b9be554b0bd5427d550d |
| --- /dev/null |
| +++ b/blimp/client/feature/compositor/blimp_client_picture_cache.h |
| @@ -0,0 +1,66 @@ |
| +// 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 <map> |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| +#include "blimp/common/compositor/blimp_picture_cache_registry.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 { |
| + 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: |
| + // Helper function to deserialize the content of |picture_data| into an |
| + // SkPicture. |
| + sk_sp<SkPicture> DeserializePicture(const cc::PictureData& picture_data); |
|
vmpstr
2016/05/25 01:54:06
This should be in .cc anonymous block (and take pi
nyquist
2016/05/26 01:08:09
Done.
|
| + |
| + // 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::map<uint32_t, sk_sp<SkPicture>> pictures_; |
| + |
| + // A ref-counted registry of SkPictures that are currently in use. |
| + BlimpPictureCacheRegistry registry_; |
| + |
| + // 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::set<uint32_t> last_added_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlimpClientPictureCache); |
| +}; |
| + |
| +} // namespace client |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_CLIENT_PICTURE_CACHE_H_ |