Flutter Engine
The Flutter Engine
layer_raster_cache_item.h
Go to the documentation of this file.
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_LAYER_RASTER_CACHE_ITEM_H_
6#define FLUTTER_FLOW_LAYERS_LAYER_RASTER_CACHE_ITEM_H_
7
8#if !SLIMPELLER
9
10#include <memory>
11#include <optional>
12
13#include "flutter/flow/raster_cache_item.h"
14
15namespace flutter {
16
18 public:
19 explicit LayerRasterCacheItem(Layer* layer,
20 int layer_cached_threshold = 1,
21 bool can_cache_children = false);
22
23 /**
24 * @brief Create a LayerRasterCacheItem, connect a layer and manage the
25 * Layer's raster cache
26 *
27 * @param layer_cache_threshold after how many frames to start trying to
28 * cache the layer self
29 * @param can_cache_children the layer can do a cache for his children
30 */
31 static std::unique_ptr<LayerRasterCacheItem>
32 Make(Layer*, int layer_cache_threshold, bool can_cache_children = false);
33
34 std::optional<RasterCacheKeyID> GetId() const override;
35
36 void PrerollSetup(PrerollContext* context, const SkMatrix& matrix) override;
37
38 void PrerollFinalize(PrerollContext* context,
39 const SkMatrix& matrix) override;
40
41 bool Draw(const PaintContext& context, const DlPaint* paint) const override;
42
43 bool Draw(const PaintContext& context,
44 DlCanvas* canvas,
45 const DlPaint* paint) const override;
46
47 bool TryToPrepareRasterCache(const PaintContext& context,
48 bool parent_cached = false) const override;
49
51
53
54 bool IsCacheChildren() const { return cache_state_ == CacheState::kChildren; }
55
56 protected:
57 const SkRect* GetPaintBoundsFromLayer() const;
58
60
61 // The id for cache the layer's children.
62 std::optional<RasterCacheKeyID> layer_children_id_;
63
65
66 // if the layer's children can be directly cache, set the param is true;
67 bool can_cache_children_ = false;
68
69 mutable int num_cache_attempts_ = 1;
70};
71
72} // namespace flutter
73
74#endif // !SLIMPELLER
75
76#endif // FLUTTER_FLOW_LAYERS_LAYER_RASTER_CACHE_ITEM_H_
Developer-facing API for rendering anything within the engine.
Definition: dl_canvas.h:38
std::optional< RasterCacheKeyID > layer_children_id_
static std::unique_ptr< LayerRasterCacheItem > Make(Layer *, int layer_cache_threshold, bool can_cache_children=false)
Create a LayerRasterCacheItem, connect a layer and manage the Layer's raster cache.
std::optional< RasterCacheKeyID > GetId() const override
void PrerollSetup(PrerollContext *context, const SkMatrix &matrix) override
LayerRasterCacheItem(Layer *layer, int layer_cached_threshold=1, bool can_cache_children=false)
bool Draw(const PaintContext &context, const DlPaint *paint) const override
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
const SkRect * GetPaintBoundsFromLayer() const
void PrerollFinalize(PrerollContext *context, const SkMatrix &matrix) override
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258