Flutter Engine
The Flutter Engine
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)
 
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 |LayerStateStack::fill| See |LayerStateStack::outstanding_opacity| See |LayerStateStack::outstanding_color_filter| See |LayerStateStack::outstanding_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 621 of file layer_state_stack.cc.

621: 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 243 of file layer_state_stack.h.

244 {
245 return AutoRestore(this, bounds, can_apply_flags);
246 }
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ canvas_delegate()

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

Definition at line 115 of file layer_state_stack.h.

115{ return delegate_->canvas(); }

◆ clear_delegate()

void flutter::LayerStateStack::clear_delegate ( )

Definition at line 623 of file layer_state_stack.cc.

623 {
624 delegate_->decommission();
625 delegate_ = DummyDelegate::kInstance;
626}

◆ content_culled()

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

Definition at line 305 of file layer_state_stack.h.

305 {
306 return delegate_->content_culled(content_bounds);
307 }

◆ device_cull_rect()

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

Definition at line 274 of file layer_state_stack.h.

274{ return delegate_->device_cull_rect(); }

◆ fill() [1/2]

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

Definition at line 270 of file layer_state_stack.h.

270{ return outstanding_.fill(paint); }
const Paint & paint
Definition: color_source.cc:38

◆ fill() [2/2]

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

Definition at line 668 of file layer_state_stack.cc.

668 {
669 for (auto& state : state_stack_) {
670 state->update_mutators(mutators);
671 }
672}
AtkStateType state

◆ is_empty()

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

Definition at line 317 of file layer_state_stack.h.

317{ return state_stack_.empty(); }

◆ local_cull_rect()

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

Definition at line 278 of file layer_state_stack.h.

278{ return delegate_->local_cull_rect(); }

◆ outstanding_bounds()

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

Definition at line 265 of file layer_state_stack.h.

265{ return outstanding_.save_layer_bounds; }

◆ outstanding_color_filter()

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

Definition at line 250 of file layer_state_stack.h.

250 {
251 return outstanding_.color_filter;
252 }

◆ outstanding_image_filter()

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

Definition at line 254 of file layer_state_stack.h.

254 {
255 return outstanding_.image_filter;
256 }

◆ outstanding_opacity()

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

Definition at line 248 of file layer_state_stack.h.

248{ return outstanding_.opacity; }

◆ painting_is_nop()

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

Definition at line 299 of file layer_state_stack.h.

299{ return outstanding_.opacity <= 0; }

◆ save()

MutatorContext flutter::LayerStateStack::save ( )
inline

Definition at line 313 of file layer_state_stack.h.

313{ return MutatorContext(this); }

◆ set_delegate()

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

Definition at line 628 of file layer_state_stack.cc.

628 {
629 if (delegate_) {
630 if (canvas == delegate_->canvas()) {
631 return;
632 }
634 }
635 if (canvas) {
636 delegate_ = std::make_shared<DlCanvasDelegate>(canvas);
637 reapply_all();
638 }
639}

◆ set_preroll_delegate() [1/3]

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

Definition at line 644 of file layer_state_stack.cc.

644 {
646}
void set_preroll_delegate(const SkRect &cull_rect, const SkMatrix &matrix)
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
static constexpr SkRect kGiantRect
Definition: layer.h:50

◆ set_preroll_delegate() [2/3]

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

Definition at line 641 of file layer_state_stack.cc.

641 {
642 set_preroll_delegate(cull_rect, SkMatrix::I());
643}
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544

◆ set_preroll_delegate() [3/3]

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

Definition at line 647 of file layer_state_stack.cc.

648 {
650 delegate_ = std::make_shared<PrerollDelegate>(cull_rect, matrix);
651 reapply_all();
652}

◆ transform_3x3()

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

Definition at line 293 of file layer_state_stack.h.

293{ return delegate_->matrix_3x3(); }

◆ transform_4x4()

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

Definition at line 285 of file layer_state_stack.h.

285{ return delegate_->matrix_4x4(); }

Friends And Related Function Documentation

◆ BackdropFilterEntry

friend class BackdropFilterEntry
friend

Definition at line 409 of file layer_state_stack.h.

◆ ClipEntry

friend class ClipEntry
friend

Definition at line 417 of file layer_state_stack.h.

◆ ClipPathEntry

friend class ClipPathEntry
friend

Definition at line 420 of file layer_state_stack.h.

◆ ClipRectEntry

friend class ClipRectEntry
friend

Definition at line 418 of file layer_state_stack.h.

◆ ClipRRectEntry

friend class ClipRRectEntry
friend

Definition at line 419 of file layer_state_stack.h.

◆ ColorFilterEntry

friend class ColorFilterEntry
friend

Definition at line 412 of file layer_state_stack.h.

◆ DlCanvasDelegate

friend class DlCanvasDelegate
friend

Definition at line 463 of file layer_state_stack.h.

◆ DummyDelegate

friend class DummyDelegate
friend

Definition at line 462 of file layer_state_stack.h.

◆ ImageFilterEntry

friend class ImageFilterEntry
friend

Definition at line 411 of file layer_state_stack.h.

◆ IntegralTransformEntry

friend class IntegralTransformEntry
friend

Definition at line 416 of file layer_state_stack.h.

◆ MutatorContext

friend class MutatorContext
friend

Definition at line 467 of file layer_state_stack.h.

◆ OpacityEntry

friend class OpacityEntry
friend

Definition at line 410 of file layer_state_stack.h.

◆ PrerollDelegate

friend class PrerollDelegate
friend

Definition at line 464 of file layer_state_stack.h.

◆ SaveEntry

friend class SaveEntry
friend

Definition at line 407 of file layer_state_stack.h.

◆ SaveLayerEntry

Definition at line 408 of file layer_state_stack.h.

◆ TransformM44Entry

friend class TransformM44Entry
friend

Definition at line 415 of file layer_state_stack.h.

◆ TransformMatrixEntry

friend class TransformMatrixEntry
friend

Definition at line 414 of file layer_state_stack.h.

◆ TranslateEntry

friend class TranslateEntry
friend

Definition at line 413 of file layer_state_stack.h.

Member Data Documentation

◆ kCallerCanApplyAnything

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

Definition at line 228 of file layer_state_stack.h.

◆ kCallerCanApplyColorFilter

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

Definition at line 226 of file layer_state_stack.h.

◆ kCallerCanApplyImageFilter

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

Definition at line 227 of file layer_state_stack.h.

◆ kCallerCanApplyOpacity

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

Definition at line 225 of file layer_state_stack.h.


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