Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
impeller::OpacityPeepholePassDelegate Class Referencefinal

#include <paint_pass_delegate.h>

Inheritance diagram for impeller::OpacityPeepholePassDelegate:
impeller::EntityPassDelegate

Public Member Functions

 OpacityPeepholePassDelegate (Paint paint)
 
 ~OpacityPeepholePassDelegate () override
 
bool CanElide () override
 
bool CanCollapseIntoParentPass (EntityPass *entity_pass) override
 Whether or not this entity pass can be collapsed into the parent. If true, this method may modify the entities for the current pass.
 
std::shared_ptr< ContentsCreateContentsForSubpassTarget (std::shared_ptr< Texture > target, const Matrix &effect_transform) override
 
std::shared_ptr< FilterContentsWithImageFilter (const FilterInput::Variant &input, const Matrix &effect_transform) const override
 
- Public Member Functions inherited from impeller::EntityPassDelegate
 EntityPassDelegate ()
 
virtual ~EntityPassDelegate ()
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::EntityPassDelegate
static std::unique_ptr< EntityPassDelegateMakeDefault ()
 

Detailed Description

A delegate that attempts to forward opacity from a save layer to child contents.

Currently this has a hardcoded limit of 3 entities in a pass, and cannot forward to child subpass delegates.

Definition at line 52 of file paint_pass_delegate.h.

Constructor & Destructor Documentation

◆ OpacityPeepholePassDelegate()

impeller::OpacityPeepholePassDelegate::OpacityPeepholePassDelegate ( Paint  paint)
explicit

OpacityPeepholePassDelegate

Definition at line 60 of file paint_pass_delegate.cc.

61 : paint_(std::move(paint)) {}
const Paint & paint

◆ ~OpacityPeepholePassDelegate()

impeller::OpacityPeepholePassDelegate::~OpacityPeepholePassDelegate ( )
overridedefault

Member Function Documentation

◆ CanCollapseIntoParentPass()

bool impeller::OpacityPeepholePassDelegate::CanCollapseIntoParentPass ( EntityPass entity_pass)
overridevirtual

Whether or not this entity pass can be collapsed into the parent. If true, this method may modify the entities for the current pass.

Implements impeller::EntityPassDelegate.

Definition at line 72 of file paint_pass_delegate.cc.

73 {
74 // Passes with enforced bounds that clip the contents can not be safely
75 // collapsed.
76 if (entity_pass->GetBoundsLimitMightClipContent()) {
77 return false;
78 }
79
80 // OpacityPeepholePassDelegate will only get used if the pass's blend mode is
81 // SourceOver, so no need to check here.
82 if (paint_.color.alpha <= 0.0 || paint_.color.alpha >= 1.0 ||
83 paint_.image_filter || paint_.color_filter) {
84 return false;
85 }
86
87 // Note: determing whether any coverage intersects has quadradic complexity in
88 // the number of rectangles, and depending on whether or not we cache at
89 // different levels of the entity tree may end up cubic. In the interest of
90 // proving whether or not this optimization is valuable, we only consider very
91 // simple peephole optimizations here - where there is a single drawing
92 // command wrapped in save layer. This would indicate something like an
93 // Opacity or FadeTransition wrapping a very simple widget, like in the
94 // CupertinoPicker.
95 if (entity_pass->GetElementCount() > 3) {
96 // Single paint command with a save layer would be:
97 // 1. clip
98 // 2. draw command
99 // 3. restore.
100 return false;
101 }
102 bool all_can_accept = true;
103 std::vector<Rect> all_coverages;
104 auto had_subpass = entity_pass->IterateUntilSubpass(
105 [&all_coverages, &all_can_accept](Entity& entity) {
106 const auto& contents = entity.GetContents();
107 if (!entity.CanInheritOpacity()) {
108 all_can_accept = false;
109 return false;
110 }
111 auto maybe_coverage = contents->GetCoverage(entity);
112 if (maybe_coverage.has_value()) {
113 auto coverage = maybe_coverage.value();
114 for (const auto& cv : all_coverages) {
115 if (cv.IntersectsWithRect(coverage)) {
116 all_can_accept = false;
117 return false;
118 }
119 }
120 all_coverages.push_back(coverage);
121 }
122 return true;
123 });
124 if (had_subpass || !all_can_accept) {
125 return false;
126 }
127 auto alpha = paint_.color.alpha;
128 entity_pass->IterateUntilSubpass([&alpha](Entity& entity) {
129 entity.SetInheritedOpacity(alpha);
130 return true;
131 });
132 return true;
133}
Scalar alpha
Definition color.h:143
std::shared_ptr< ImageFilter > image_filter
Definition paint.h:67
Color color
Definition paint.h:55
std::shared_ptr< ColorFilter > color_filter
Definition paint.h:68

◆ CanElide()

bool impeller::OpacityPeepholePassDelegate::CanElide ( )
overridevirtual

Implements impeller::EntityPassDelegate.

Definition at line 67 of file paint_pass_delegate.cc.

67 {
68 return paint_.blend_mode == BlendMode::kDestination;
69}
BlendMode blend_mode
Definition paint.h:64

◆ CreateContentsForSubpassTarget()

std::shared_ptr< Contents > impeller::OpacityPeepholePassDelegate::CreateContentsForSubpassTarget ( std::shared_ptr< Texture target,
const Matrix effect_transform 
)
overridevirtual

Implements impeller::EntityPassDelegate.

Definition at line 137 of file paint_pass_delegate.cc.

139 {
140 auto contents = TextureContents::MakeRect(Rect::MakeSize(target->GetSize()));
141 contents->SetLabel("Subpass");
142 contents->SetTexture(target);
143 contents->SetSourceRect(Rect::MakeSize(target->GetSize()));
144 contents->SetOpacity(paint_.color.alpha);
145 contents->SetDeferApplyingOpacity(true);
146
147 return paint_.WithFiltersForSubpassTarget(std::move(contents),
148 effect_transform);
149}
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
uint32_t * target
std::shared_ptr< Contents > WithFiltersForSubpassTarget(std::shared_ptr< Contents > input, const Matrix &effect_transform=Matrix()) const
Wrap this paint's configured filters to the given contents of subpass target.
Definition paint.cc:67
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146

◆ WithImageFilter()

std::shared_ptr< FilterContents > impeller::OpacityPeepholePassDelegate::WithImageFilter ( const FilterInput::Variant input,
const Matrix effect_transform 
) const
overridevirtual

Implements impeller::EntityPassDelegate.

Definition at line 152 of file paint_pass_delegate.cc.

154 {
155 return paint_.WithImageFilter(input, effect_transform,
157}
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition paint.cc:88

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