Flutter Engine
The Flutter Engine
|
#include <layer_state_stack.h>
Classes | |
class | AutoRestore |
class | MutatorContext |
Public Member Functions | |
LayerStateStack () | |
void | clear_delegate () |
DlCanvas * | canvas_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 DlColorFilter > | outstanding_color_filter () const |
std::shared_ptr< const DlImageFilter > | outstanding_image_filter () const |
SkRect | outstanding_bounds () const |
DlPaint * | fill (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 |
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.
flutter::LayerStateStack::LayerStateStack | ( | ) |
Definition at line 621 of file layer_state_stack.cc.
|
inline |
Definition at line 243 of file layer_state_stack.h.
|
inline |
Definition at line 115 of file layer_state_stack.h.
void flutter::LayerStateStack::clear_delegate | ( | ) |
Definition at line 623 of file layer_state_stack.cc.
|
inline |
Definition at line 305 of file layer_state_stack.h.
|
inline |
Definition at line 274 of file layer_state_stack.h.
Definition at line 270 of file layer_state_stack.h.
void flutter::LayerStateStack::fill | ( | MutatorsStack * | mutators | ) |
Definition at line 668 of file layer_state_stack.cc.
|
inline |
Definition at line 317 of file layer_state_stack.h.
|
inline |
Definition at line 278 of file layer_state_stack.h.
|
inline |
Definition at line 265 of file layer_state_stack.h.
|
inline |
Definition at line 250 of file layer_state_stack.h.
|
inline |
Definition at line 254 of file layer_state_stack.h.
|
inline |
Definition at line 248 of file layer_state_stack.h.
|
inline |
Definition at line 299 of file layer_state_stack.h.
|
inline |
Definition at line 313 of file layer_state_stack.h.
void flutter::LayerStateStack::set_delegate | ( | DlCanvas * | canvas | ) |
Definition at line 628 of file layer_state_stack.cc.
void flutter::LayerStateStack::set_preroll_delegate | ( | const SkMatrix & | matrix | ) |
Definition at line 644 of file layer_state_stack.cc.
void flutter::LayerStateStack::set_preroll_delegate | ( | const SkRect & | cull_rect | ) |
Definition at line 641 of file layer_state_stack.cc.
void flutter::LayerStateStack::set_preroll_delegate | ( | const SkRect & | cull_rect, |
const SkMatrix & | matrix | ||
) |
Definition at line 647 of file layer_state_stack.cc.
|
inline |
Definition at line 293 of file layer_state_stack.h.
|
inline |
Definition at line 285 of file layer_state_stack.h.
|
friend |
Definition at line 409 of file layer_state_stack.h.
|
friend |
Definition at line 417 of file layer_state_stack.h.
|
friend |
Definition at line 420 of file layer_state_stack.h.
|
friend |
Definition at line 418 of file layer_state_stack.h.
|
friend |
Definition at line 419 of file layer_state_stack.h.
|
friend |
Definition at line 412 of file layer_state_stack.h.
|
friend |
Definition at line 463 of file layer_state_stack.h.
|
friend |
Definition at line 462 of file layer_state_stack.h.
|
friend |
Definition at line 411 of file layer_state_stack.h.
|
friend |
Definition at line 416 of file layer_state_stack.h.
|
friend |
Definition at line 467 of file layer_state_stack.h.
|
friend |
Definition at line 410 of file layer_state_stack.h.
|
friend |
Definition at line 464 of file layer_state_stack.h.
|
friend |
Definition at line 407 of file layer_state_stack.h.
|
friend |
Definition at line 408 of file layer_state_stack.h.
|
friend |
Definition at line 415 of file layer_state_stack.h.
|
friend |
Definition at line 414 of file layer_state_stack.h.
|
friend |
Definition at line 413 of file layer_state_stack.h.
|
staticconstexpr |
Definition at line 228 of file layer_state_stack.h.
|
staticconstexpr |
Definition at line 226 of file layer_state_stack.h.
|
staticconstexpr |
Definition at line 227 of file layer_state_stack.h.
|
staticconstexpr |
Definition at line 225 of file layer_state_stack.h.