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_RASTER_CACHE_ITEM_H_
6#define FLUTTER_FLOW_RASTER_CACHE_ITEM_H_
7
8#include <memory>
9#include <optional>
10
11#include "flutter/display_list/dl_canvas.h"
12#include "flutter/flow/raster_cache_key.h"
13
14namespace flutter {
15
16struct PrerollContext;
17struct PaintContext;
18class DisplayList;
19class RasterCache;
20class LayerRasterCacheItem;
21class DisplayListRasterCacheItem;
22
23class RasterCacheItem {
24 public:
25 enum CacheState {
26 kNone = 0,
27 kCurrent,
28 kChildren,
29 };
30
31 explicit RasterCacheItem(RasterCacheKeyID key_id,
32 CacheState cache_state = CacheState::kNone,
33 unsigned child_entries = 0)
34 : key_id_(key_id),
35 cache_state_(cache_state),
36 child_items_(child_entries) {}
37
38 virtual void PrerollSetup(PrerollContext* context,
39 const SkMatrix& matrix) = 0;
40
41 virtual void PrerollFinalize(PrerollContext* context,
42 const SkMatrix& matrix) = 0;
43
44 virtual bool Draw(const PaintContext& context,
45 const DlPaint* paint) const = 0;
46
47 virtual bool Draw(const PaintContext& context,
48 DlCanvas* canvas,
49 const DlPaint* paint) const = 0;
50
51 virtual std::optional<RasterCacheKeyID> GetId() const { return key_id_; }
52
53 virtual bool TryToPrepareRasterCache(const PaintContext& context,
54 bool parent_cached = false) const = 0;
55
56 unsigned child_items() const { return child_items_; }
57
58 void set_matrix(const SkMatrix& matrix) { matrix_ = matrix; }
59
60 CacheState cache_state() const { return cache_state_; }
61
62 bool need_caching() const { return cache_state_ != CacheState::kNone; }
63
64 virtual ~RasterCacheItem() = default;
65
66 protected:
67 // The id for cache the layer self.
68 RasterCacheKeyID key_id_;
69 CacheState cache_state_ = CacheState::kNone;
70 mutable SkMatrix matrix_;
71 unsigned child_items_;
72};
73
74} // namespace flutter
75
76#endif // FLUTTER_FLOW_RASTER_CACHE_ITEM_H_
77

source code of flutter_engine/flutter/flow/raster_cache_item.h