#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 DlRect &cull_rect, const DlMatrix &matrix) |
| void | set_preroll_delegate (const DlRect &cull_rect) |
| void | set_preroll_delegate (const DlMatrix &matrix) |
| void | fill (MutatorsStack *mutators) |
| AutoRestore | applyState (const DlRect &bounds, int can_apply_flags) |
| DlScalar | outstanding_opacity () const |
| std::shared_ptr< const DlColorFilter > | outstanding_color_filter () const |
| std::shared_ptr< DlImageFilter > | outstanding_image_filter () const |
| DlRect | outstanding_bounds () const |
| DlPaint * | fill (DlPaint &paint) const |
| DlRect | device_cull_rect () const |
| DlRect | local_cull_rect () const |
| const DlMatrix | matrix () const |
| bool | painting_is_nop () const |
| bool | content_culled (const DlRect &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 | ClipRSuperellipseEntry |
| 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 |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.
| flutter::LayerStateStack::LayerStateStack | ( | ) |
Definition at line 623 of file layer_state_stack.cc.
|
inline |
Definition at line 244 of file layer_state_stack.h.
Referenced by flutter::ClipShapeLayer< T >::Paint(), flutter::ContainerLayer::PaintChildren(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 115 of file layer_state_stack.h.
Referenced by flutter::testing::TEST(), and flutter::testing::TEST().
| void flutter::LayerStateStack::clear_delegate | ( | ) |
Definition at line 625 of file layer_state_stack.cc.
References flutter::DummyDelegate::kInstance.
Referenced by set_delegate(), set_preroll_delegate(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 297 of file layer_state_stack.h.
References delegate_.
Referenced by flutter::Layer::needs_painting(), flutter::DisplayListRasterCacheItem::PrerollFinalize(), flutter::LayerRasterCacheItem::PrerollFinalize(), and flutter::testing::TEST().
|
inline |
Definition at line 275 of file layer_state_stack.h.
References delegate_.
Referenced by flutter::BackdropFilterLayer::Preroll(), flutter::testing::TEST(), and flutter::testing::TEST().
Definition at line 271 of file layer_state_stack.h.
| void flutter::LayerStateStack::fill | ( | MutatorsStack * | mutators | ) |
Definition at line 670 of file layer_state_stack.cc.
Referenced by flutter::ClipShapeLayer< T >::Paint(), flutter::ColorFilterLayer::Paint(), flutter::DisplayListLayer::Paint(), flutter::ImageFilterLayer::Paint(), flutter::OpacityLayer::Paint(), flutter::ShaderMaskLayer::Paint(), flutter::TextureLayer::Paint(), flutter::testing::MockLayer::Paint(), flutter::PlatformViewLayer::Preroll(), flutter::testing::MockLayer::Preroll(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 309 of file layer_state_stack.h.
Referenced by flutter::testing::LayerTestBase< BaseT >::reset_display_list().
|
inline |
Definition at line 279 of file layer_state_stack.h.
References delegate_.
Referenced by flutter::BackdropFilterLayer::Preroll(), flutter::testing::MockLayer::Preroll(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 285 of file layer_state_stack.h.
References delegate_.
Referenced by flutter::ClipShapeLayer< T >::Preroll(), flutter::ColorFilterLayer::Preroll(), flutter::ImageFilterLayer::Preroll(), flutter::OpacityLayer::Preroll(), flutter::PlatformViewLayer::Preroll(), flutter::ShaderMaskLayer::Preroll(), flutter::testing::MockLayer::Preroll(), flutter::testing::MockCacheableContainerLayer::Preroll(), flutter::testing::MockCacheableLayer::Preroll(), flutter::DisplayListLayer::Preroll(), set_preroll_delegate(), set_preroll_delegate(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::LayerStateStack::MutatorContext::transform().
|
inline |
Definition at line 266 of file layer_state_stack.h.
Referenced by flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 251 of file layer_state_stack.h.
Referenced by flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 255 of file layer_state_stack.h.
Referenced by flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 249 of file layer_state_stack.h.
Referenced by flutter::DisplayListLayer::Paint(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Definition at line 291 of file layer_state_stack.h.
Referenced by flutter::Layer::needs_painting().
|
inline |
Definition at line 305 of file layer_state_stack.h.
Referenced by flutter::BackdropFilterLayer::Paint(), flutter::ClipShapeLayer< T >::Paint(), flutter::ColorFilterLayer::Paint(), flutter::DisplayListLayer::Paint(), flutter::ImageFilterLayer::Paint(), flutter::OpacityLayer::Paint(), flutter::PerformanceOverlayLayer::Paint(), flutter::ShaderMaskLayer::Paint(), flutter::TransformLayer::Paint(), flutter::ClipShapeLayer< T >::Preroll(), flutter::ImageFilterLayer::Preroll(), flutter::OpacityLayer::Preroll(), flutter::TransformLayer::Preroll(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
| void flutter::LayerStateStack::set_delegate | ( | DlCanvas * | canvas | ) |
Definition at line 630 of file layer_state_stack.cc.
References clear_delegate().
Referenced by flutter::LayerTree::Flatten(), flutter::testing::LayerTestBase< BaseT >::LayerTestBase(), flutter::testing::MockRasterCache::MockRasterCache(), flutter::LayerTree::Paint(), flutter::PlatformViewLayer::Paint(), flutter::Rasterize(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST_F().
| void flutter::LayerStateStack::set_preroll_delegate | ( | const DlMatrix & | matrix | ) |
Definition at line 646 of file layer_state_stack.cc.
References flutter::kGiantRect, matrix(), and set_preroll_delegate().
| void flutter::LayerStateStack::set_preroll_delegate | ( | const DlRect & | cull_rect | ) |
| void flutter::LayerStateStack::set_preroll_delegate | ( | const DlRect & | cull_rect, |
| const DlMatrix & | matrix | ||
| ) |
Definition at line 649 of file layer_state_stack.cc.
References clear_delegate(), and matrix().
Referenced by flutter::LayerTree::Flatten(), flutter::testing::LayerTestBase< BaseT >::LayerTestBase(), flutter::testing::MockRasterCache::MockRasterCache(), flutter::LayerTree::Preroll(), set_preroll_delegate(), set_preroll_delegate(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().
|
friend |
Definition at line 402 of file layer_state_stack.h.
|
friend |
Definition at line 410 of file layer_state_stack.h.
|
friend |
Definition at line 414 of file layer_state_stack.h.
|
friend |
Definition at line 411 of file layer_state_stack.h.
|
friend |
Definition at line 412 of file layer_state_stack.h.
|
friend |
Definition at line 413 of file layer_state_stack.h.
|
friend |
Definition at line 405 of file layer_state_stack.h.
|
friend |
Definition at line 459 of file layer_state_stack.h.
|
friend |
Definition at line 458 of file layer_state_stack.h.
|
friend |
Definition at line 404 of file layer_state_stack.h.
|
friend |
Definition at line 409 of file layer_state_stack.h.
|
friend |
Definition at line 463 of file layer_state_stack.h.
|
friend |
Definition at line 403 of file layer_state_stack.h.
|
friend |
Definition at line 460 of file layer_state_stack.h.
|
friend |
Definition at line 400 of file layer_state_stack.h.
|
friend |
Definition at line 401 of file layer_state_stack.h.
|
friend |
Definition at line 408 of file layer_state_stack.h.
|
friend |
Definition at line 407 of file layer_state_stack.h.
|
friend |
Definition at line 406 of file layer_state_stack.h.
|
staticconstexpr |
Definition at line 229 of file layer_state_stack.h.
Referenced by flutter::ContainerLayer::PrerollChildren().
|
staticconstexpr |
Definition at line 227 of file layer_state_stack.h.
Referenced by flutter::ImageFilterLayer::Preroll(), and flutter::testing::TEST().
|
staticconstexpr |
Definition at line 228 of file layer_state_stack.h.
Referenced by flutter::testing::TEST().
|
staticconstexpr |
Definition at line 226 of file layer_state_stack.h.
Referenced by flutter::ClipShapeLayer< T >::Paint(), flutter::ColorFilterLayer::Preroll(), flutter::ImageFilterLayer::Preroll(), flutter::OpacityLayer::Preroll(), flutter::TextureLayer::Preroll(), flutter::testing::MockLayer::Preroll(), flutter::DisplayListLayer::Preroll(), flutter::DisplayListRasterCacheItem::PrerollFinalize(), flutter::testing::TEST(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().