| 1 | // Copyright 2013 The Flutter 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 FLUTTER_FLOW_LAYERS_CACHEABLE_LAYER_H_ |
| 6 | #define FLUTTER_FLOW_LAYERS_CACHEABLE_LAYER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "flutter/flow/layers/container_layer.h" |
| 11 | #include "flutter/flow/layers/layer_raster_cache_item.h" |
| 12 | |
| 13 | namespace flutter { |
| 14 | |
| 15 | class AutoCache { |
| 16 | public: |
| 17 | AutoCache(RasterCacheItem* raster_cache_item, |
| 18 | PrerollContext* context, |
| 19 | const SkMatrix& matrix); |
| 20 | |
| 21 | void ShouldNotBeCached() { raster_cache_item_ = nullptr; } |
| 22 | |
| 23 | ~AutoCache(); |
| 24 | |
| 25 | private: |
| 26 | inline bool IsCacheEnabled(); |
| 27 | RasterCacheItem* raster_cache_item_ = nullptr; |
| 28 | PrerollContext* context_ = nullptr; |
| 29 | const SkMatrix matrix_; |
| 30 | }; |
| 31 | |
| 32 | class CacheableContainerLayer : public ContainerLayer { |
| 33 | public: |
| 34 | explicit CacheableContainerLayer( |
| 35 | int layer_cached_threshold = |
| 36 | RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer, |
| 37 | bool can_cache_children = false); |
| 38 | |
| 39 | const LayerRasterCacheItem* raster_cache_item() const { |
| 40 | return layer_raster_cache_item_.get(); |
| 41 | } |
| 42 | |
| 43 | protected: |
| 44 | std::unique_ptr<LayerRasterCacheItem> layer_raster_cache_item_; |
| 45 | }; |
| 46 | |
| 47 | } // namespace flutter |
| 48 | |
| 49 | #endif // FLUTTER_FLOW_LAYERS_CACHEABLE_LAYER_H_ |
| 50 |
