Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Friends | List of all members
flutter::LayerStateStack Class Reference

#include <layer_state_stack.h>

Classes

class  AutoRestore
 
class  MutatorContext
 

Public Member Functions

 LayerStateStack ()
 
void clear_delegate ()
 
DlCanvascanvas_delegate ()
 
void set_delegate (DlCanvas *canvas)
 
void set_preroll_delegate (const SkRect &cull_rect, const SkMatrix &matrix)
 
void set_preroll_delegate (const SkRect &cull_rect)
 
void set_preroll_delegate (const SkMatrix &matrix)
 
void fill (MutatorsStack *mutators)
 
CheckerboardFunc checkerboard_func () const
 
void set_checkerboard_func (CheckerboardFunc checkerboard_func)
 
AutoRestore applyState (const SkRect &bounds, int can_apply_flags)
 
SkScalar outstanding_opacity () const
 
std::shared_ptr< const DlColorFilteroutstanding_color_filter () const
 
std::shared_ptr< const DlImageFilteroutstanding_image_filter () const
 
SkRect outstanding_bounds () const
 
DlPaintfill (DlPaint &paint) const
 
SkRect device_cull_rect () const
 
SkRect local_cull_rect () const
 
SkM44 transform_4x4 () const
 
SkMatrix transform_3x3 () const
 
bool painting_is_nop () const
 
bool content_culled (const SkRect &content_bounds) const
 
MutatorContext save ()
 
bool is_empty () const
 

Static Public Attributes

static constexpr int kCallerCanApplyOpacity = 0x1
 
static constexpr int kCallerCanApplyColorFilter = 0x2
 
static constexpr int kCallerCanApplyImageFilter = 0x4
 
static constexpr int kCallerCanApplyAnything
 

Friends

class SaveEntry
 
class SaveLayerEntry
 
class BackdropFilterEntry
 
class OpacityEntry
 
class ImageFilterEntry
 
class ColorFilterEntry
 
class TranslateEntry
 
class TransformMatrixEntry
 
class TransformM44Entry
 
class IntegralTransformEntry
 
class ClipEntry
 
class ClipRectEntry
 
class ClipRRectEntry
 
class ClipPathEntry
 
class DummyDelegate
 
class DlCanvasDelegate
 
class PrerollDelegate
 
class MutatorContext
 

Detailed Description

The LayerStateStack manages the inherited state passed down between |Layer| objects in a |LayerTree| during |Preroll| and |Paint|.

More specifically, it manages the clip and transform state during recursive rendering and will hold and lazily apply opacity, ImageFilter and ColorFilter attributes to recursive content. This is not a truly general state management mechnanism as it makes assumptions that code will be applying the attributes to rendered content that happens in recursive calls. The automatic save/restore mechanisms only work in a context where C++ auto-destruct calls will engage the restore at the end of a code block and that any applied attributes will only be applied to the content rendered inside that block. These restrictions match the organization of the |LayerTree| methods precisely.

The stack can manage a single state delegate. The delegate will provide tracking of the current transform and clip and will also execute saveLayer calls at the appropriate time if it is a rendering delegate. The delegate can be swapped out on the fly (as is typically done by PlatformViewLayer when recording the state for multiple "overlay" layers that occur between embedded view subtrees. The old delegate will be restored to its original state before it became a delegate and the new delegate will have all of the state recorded by the stack replayed into it to bring it up to speed with the current rendering context.

The delegate can be any one of:

The rendering state attributes will be automatically applied to the nested content using a |saveLayer| call at the point at which we encounter rendered content (i.e. various nested layers that exist only to apply new state will not trigger the |saveLayer| and the attributes can accumulate until we reach actual content that is rendered.) Some rendered content can avoid the |saveLayer| if it reports to the object that it is able to apply all of the attributes that happen to be outstanding (accumulated from parent state-modifiers). A |ContainerLayer| can also monitor the attribute rendering capabilities of a list of children and can ask the object to apply a protective |saveLayer| or not based on the negotiated capabilities of the entire group.

Any code that is planning to modify the clip, transform, or rendering attributes for its child content must start by calling the |save| method which returns a MutatorContext object. The methods that modify such state only exist on the MutatorContext object so it is difficult to get that wrong, but the caller must make sure that the call happens within a C++ code block that will define the "rendering scope" of those state changes as they will be automatically restored on exit from that block. Note that the layer might make similar state calls directly on the canvas or builder during the Paint cycle (via saveLayer, transform, or clip calls), but should avoid doing so if there is any nested content that needs to track or react to those state calls.

Code that needs to render content can simply inform the parent of their abilities by setting the |PrerollContext::renderable_state_flags| during |Preroll| and then render with those attributes during |Paint| by requesting the outstanding values of those attributes from the state_stack object. Individual leaf layers can ignore this feature as the default behavior during |Preroll| will have their parent |ContainerLayer| assume that they cannot render any outstanding state attributes and will apply the protective saveLayer on their behalf if needed. As such, this object only provides "opt-in" features for leaf layers and no responsibilities otherwise. See |LayerStateStackfill| See |LayerStateStackoutstanding_opacity| See |LayerStateStackoutstanding_color_filter| See |LayerStateStackoutstanding_image_filter|

State-modifying layers should contain code similar to this pattern in both their |Preroll| and |Paint| methods.

void [LayerType]::[Preroll/Paint](context) { auto mutator = context.state_stack.save(); mutator.translate(origin.x, origin.y); mutator.applyOpacity(content_bounds, opacity_value); mutator.applyColorFilter(content_bounds, color_filter); // or any of the mutator transform, clip or attribute methods

// Children will react to the state applied above during their // Preroll/Paint methods or ContainerLayer will protect them // conservatively by default. [Preroll/Paint]Children(context);

// here the mutator will be auto-destructed and the state accumulated // by it will be restored out of the state_stack and its associated // delegates. }

Definition at line 105 of file layer_state_stack.h.

Constructor & Destructor Documentation

◆ LayerStateStack()

flutter::LayerStateStack::LayerStateStack ( )

Definition at line 625 of file layer_state_stack.cc.

625: delegate_(DummyDelegate::kInstance) {}
static const std::shared_ptr< DummyDelegate > kInstance

Member Function Documentation

◆ applyState()

AutoRestore flutter::LayerStateStack::applyState ( const SkRect bounds,
int  can_apply_flags 
)
inline

Definition at line 250 of file layer_state_stack.h.

251 {
252 return AutoRestore(this, bounds, can_apply_flags);
253 }

◆ canvas_delegate()

DlCanvas * flutter::LayerStateStack::canvas_delegate ( )
inline

Definition at line 115 of file layer_state_stack.h.

115{ return delegate_->canvas(); }

◆ checkerboard_func()

CheckerboardFunc flutter::LayerStateStack::checkerboard_func ( ) const
inline

Definition at line 136 of file layer_state_stack.h.

136{ return checkerboard_func_; }

◆ clear_delegate()

void flutter::LayerStateStack::clear_delegate ( )

Definition at line 627 of file layer_state_stack.cc.

627 {
628 delegate_->decommission();
629 delegate_ = DummyDelegate::kInstance;
630}

◆ content_culled()

bool flutter::LayerStateStack::content_culled ( const SkRect content_bounds) const
inline

Definition at line 312 of file layer_state_stack.h.

312 {
313 return delegate_->content_culled(content_bounds);
314 }

◆ device_cull_rect()

SkRect flutter::LayerStateStack::device_cull_rect ( ) const
inline

Definition at line 281 of file layer_state_stack.h.

281{ return delegate_->device_cull_rect(); }

◆ fill() [1/2]

DlPaint * flutter::LayerStateStack::fill ( DlPaint paint) const
inline

Definition at line 277 of file layer_state_stack.h.

277{ return outstanding_.fill(paint); }
const Paint & paint

◆ fill() [2/2]

void flutter::LayerStateStack::fill ( MutatorsStack mutators)

Definition at line 672 of file layer_state_stack.cc.

672 {
673 for (auto& state : state_stack_) {
674 state->update_mutators(mutators);
675 }
676}
AtkStateType state

◆ is_empty()

bool flutter::LayerStateStack::is_empty ( ) const
inline

Definition at line 324 of file layer_state_stack.h.

324{ return state_stack_.empty(); }

◆ local_cull_rect()

SkRect flutter::LayerStateStack::local_cull_rect ( ) const
inline

Definition at line 285 of file layer_state_stack.h.

285{ return delegate_->local_cull_rect(); }

◆ outstanding_bounds()

SkRect flutter::LayerStateStack::outstanding_bounds ( ) const
inline

Definition at line 272 of file layer_state_stack.h.

272{ return outstanding_.save_layer_bounds; }

◆ outstanding_color_filter()

std::shared_ptr< const DlColorFilter > flutter::LayerStateStack::outstanding_color_filter ( ) const
inline

Definition at line 257 of file layer_state_stack.h.

257 {
258 return outstanding_.color_filter;
259 }

◆ outstanding_image_filter()

std::shared_ptr< const DlImageFilter > flutter::LayerStateStack::outstanding_image_filter ( ) const
inline

Definition at line 261 of file layer_state_stack.h.

261 {
262 return outstanding_.image_filter;
263 }

◆ outstanding_opacity()

SkScalar flutter::LayerStateStack::outstanding_opacity ( ) const
inline

Definition at line 255 of file layer_state_stack.h.

255{ return outstanding_.opacity; }

◆ painting_is_nop()

bool flutter::LayerStateStack::painting_is_nop ( ) const
inline

Definition at line 306 of file layer_state_stack.h.

306{ return outstanding_.opacity <= 0; }

◆ save()

MutatorContext flutter::LayerStateStack::save ( )
inline

Definition at line 320 of file layer_state_stack.h.

320{ return MutatorContext(this); }

◆ set_checkerboard_func()

void flutter::LayerStateStack::set_checkerboard_func ( CheckerboardFunc  checkerboard_func)
inline

Definition at line 137 of file layer_state_stack.h.

137 {
138 checkerboard_func_ = checkerboard_func;
139 }
CheckerboardFunc checkerboard_func() const

◆ set_delegate()

void flutter::LayerStateStack::set_delegate ( DlCanvas canvas)

Definition at line 632 of file layer_state_stack.cc.

632 {
633 if (delegate_) {
634 if (canvas == delegate_->canvas()) {
635 return;
636 }
638 }
639 if (canvas) {
640 delegate_ = std::make_shared<DlCanvasDelegate>(canvas);
641 reapply_all();
642 }
643}

◆ set_preroll_delegate() [1/3]

void flutter::LayerStateStack::set_preroll_delegate ( const SkMatrix matrix)

Definition at line 648 of file layer_state_stack.cc.

648 {
650}
void set_preroll_delegate(const SkRect &cull_rect, const SkMatrix &matrix)
static constexpr SkRect kGiantRect
Definition layer.h:49

◆ set_preroll_delegate() [2/3]

void flutter::LayerStateStack::set_preroll_delegate ( const SkRect cull_rect)

Definition at line 645 of file layer_state_stack.cc.

645 {
646 set_preroll_delegate(cull_rect, SkMatrix::I());
647}
static const SkMatrix & I()

◆ set_preroll_delegate() [3/3]

void flutter::LayerStateStack::set_preroll_delegate ( const SkRect cull_rect,
const SkMatrix matrix 
)

Definition at line 651 of file layer_state_stack.cc.

652 {
654 delegate_ = std::make_shared<PrerollDelegate>(cull_rect, matrix);
655 reapply_all();
656}

◆ transform_3x3()

SkMatrix flutter::LayerStateStack::transform_3x3 ( ) const
inline

Definition at line 300 of file layer_state_stack.h.

300{ return delegate_->matrix_3x3(); }

◆ transform_4x4()

SkM44 flutter::LayerStateStack::transform_4x4 ( ) const
inline

Definition at line 292 of file layer_state_stack.h.

292{ return delegate_->matrix_4x4(); }

Friends And Related Symbol Documentation

◆ BackdropFilterEntry

friend class BackdropFilterEntry
friend

Definition at line 416 of file layer_state_stack.h.

◆ ClipEntry

friend class ClipEntry
friend

Definition at line 424 of file layer_state_stack.h.

◆ ClipPathEntry

friend class ClipPathEntry
friend

Definition at line 427 of file layer_state_stack.h.

◆ ClipRectEntry

friend class ClipRectEntry
friend

Definition at line 425 of file layer_state_stack.h.

◆ ClipRRectEntry

friend class ClipRRectEntry
friend

Definition at line 426 of file layer_state_stack.h.

◆ ColorFilterEntry

friend class ColorFilterEntry
friend

Definition at line 419 of file layer_state_stack.h.

◆ DlCanvasDelegate

friend class DlCanvasDelegate
friend

Definition at line 470 of file layer_state_stack.h.

◆ DummyDelegate

friend class DummyDelegate
friend

Definition at line 469 of file layer_state_stack.h.

◆ ImageFilterEntry

friend class ImageFilterEntry
friend

Definition at line 418 of file layer_state_stack.h.

◆ IntegralTransformEntry

friend class IntegralTransformEntry
friend

Definition at line 423 of file layer_state_stack.h.

◆ MutatorContext

friend class MutatorContext
friend

Definition at line 474 of file layer_state_stack.h.

◆ OpacityEntry

friend class OpacityEntry
friend

Definition at line 417 of file layer_state_stack.h.

◆ PrerollDelegate

friend class PrerollDelegate
friend

Definition at line 471 of file layer_state_stack.h.

◆ SaveEntry

friend class SaveEntry
friend

Definition at line 414 of file layer_state_stack.h.

◆ SaveLayerEntry

Definition at line 415 of file layer_state_stack.h.

◆ TransformM44Entry

friend class TransformM44Entry
friend

Definition at line 422 of file layer_state_stack.h.

◆ TransformMatrixEntry

friend class TransformMatrixEntry
friend

Definition at line 421 of file layer_state_stack.h.

◆ TranslateEntry

friend class TranslateEntry
friend

Definition at line 420 of file layer_state_stack.h.

Member Data Documentation

◆ kCallerCanApplyAnything

constexpr int flutter::LayerStateStack::kCallerCanApplyAnything
staticconstexpr
Initial value:

Definition at line 235 of file layer_state_stack.h.

◆ kCallerCanApplyColorFilter

constexpr int flutter::LayerStateStack::kCallerCanApplyColorFilter = 0x2
staticconstexpr

Definition at line 233 of file layer_state_stack.h.

◆ kCallerCanApplyImageFilter

constexpr int flutter::LayerStateStack::kCallerCanApplyImageFilter = 0x4
staticconstexpr

Definition at line 234 of file layer_state_stack.h.

◆ kCallerCanApplyOpacity

constexpr int flutter::LayerStateStack::kCallerCanApplyOpacity = 0x1
staticconstexpr

Definition at line 232 of file layer_state_stack.h.


The documentation for this class was generated from the following files: