55#ifndef FLUTTER_FLOW_LAYERS_LAYER_H_
66#define FLUTTER_FLOW_LAYERS_LAYER_H_
77
8+ #include < algorithm>
89#include < memory>
10+ #include < unordered_set>
911#include < vector>
1012
1113#include " flutter/common/graphics/texture.h"
@@ -34,6 +36,11 @@ namespace testing {
3436class MockLayer ;
3537} // namespace testing
3638
39+ class PictureLayer ;
40+ class DisplayListLayer ;
41+ class PerformanceOverlayLayer ;
42+ class TextureLayer ;
43+
3744static constexpr SkRect kGiantRect = SkRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F);
3845
3946// This should be an exact copy of the Clip enum in painting.dart.
@@ -80,12 +87,32 @@ struct PrerollContext {
8087 // than to remember the value so that it can choose the right strategy
8188 // for its |Paint| method.
8289 bool subtree_can_inherit_opacity = false ;
90+
91+ std::vector<Layer*> raster_cached_layers;
8392};
8493
85- class PictureLayer ;
86- class DisplayListLayer ;
87- class PerformanceOverlayLayer ;
88- class TextureLayer ;
94+ class AutoGatherLayers {
95+ public:
96+ explicit AutoGatherLayers (std::vector<Layer*>& layers)
97+ : current_layer_(nullptr ),
98+ layers_(layers),
99+ initial_size_(layers.size()) {}
100+
101+ void SetCurrentLayer (Layer* current_layer) { current_layer_ = current_layer; }
102+
103+ ~AutoGatherLayers () {
104+ if (current_layer_) {
105+ layers_.resize (
106+ initial_size_); // remove all child layers added in the meanwhile
107+ layers_.push_back (current_layer_);
108+ }
109+ }
110+
111+ private:
112+ Layer* current_layer_;
113+ std::vector<Layer*>& layers_;
114+ size_t initial_size_;
115+ };
89116
90117// Represents a single composited layer. Created on the UI thread but then
91118// subquently used on the Rasterizer thread.
@@ -108,6 +135,9 @@ class Layer {
108135 // Performs diff with given layer
109136 virtual void Diff (DiffContext* context, const Layer* old_layer) {}
110137
138+ virtual void TryToPrepareRasterCache (PrerollContext* context,
139+ const SkMatrix& ctm);
140+
111141 // Used when diffing retained layer; In case the layer is identical, it
112142 // doesn't need to be diffed, but the paint region needs to be stored in diff
113143 // context so that it can be used in next frame
@@ -178,7 +208,7 @@ class Layer {
178208
179209 class AutoCachePaint {
180210 public:
181- AutoCachePaint (PaintContext& context) : context_(context) {
211+ explicit AutoCachePaint (PaintContext& context) : context_(context) {
182212 needs_paint_ = context.inherited_opacity < SK_Scalar1;
183213 if (needs_paint_) {
184214 paint_.setAlphaf (context.inherited_opacity );
@@ -329,6 +359,21 @@ class Layer {
329359
330360 uint64_t unique_id () const { return unique_id_; }
331361
362+ void SetLevel (unsigned value) { level_ = value; }
363+ unsigned level () const { return level_; }
364+
365+ void SetAncestors (const std::unordered_set<uint64_t >& ancestors) {
366+ ancestors_ = ancestors;
367+ }
368+
369+ void AddAncestor (uint64_t id) { ancestors_.insert (id); }
370+
371+ const std::unordered_set<uint64_t > GetAncestors () const { return ancestors_; }
372+
373+ bool HasAncestor (uint64_t id) {
374+ return ancestors_.find (id) != ancestors_.end ();
375+ }
376+
332377 virtual const PictureLayer* as_picture_layer () const { return nullptr ; }
333378 virtual const DisplayListLayer* as_display_list_layer () const {
334379 return nullptr ;
@@ -345,6 +390,9 @@ class Layer {
345390 uint64_t original_layer_id_;
346391 bool subtree_has_platform_view_;
347392 bool layer_can_inherit_opacity_;
393+ std::unordered_set<uint64_t > ancestors_ = {};
394+
395+ unsigned level_ = 0 ;
348396
349397 static uint64_t NextUniqueID ();
350398
0 commit comments