Flutter Impeller
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. More...
 
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)) {}

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

References impeller::Color::alpha, impeller::Entity::CanInheritOpacity(), impeller::Paint::color, impeller::Paint::color_filter, impeller::EntityPass::GetBoundsLimit(), impeller::Entity::GetContents(), impeller::EntityPass::GetElementCount(), impeller::Paint::image_filter, and impeller::EntityPass::IterateUntilSubpass().

◆ 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 }

References impeller::Paint::blend_mode, and impeller::kDestination.

◆ CreateContentsForSubpassTarget()

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

Implements impeller::EntityPassDelegate.

Definition at line 136 of file paint_pass_delegate.cc.

138  {
139  auto contents = TextureContents::MakeRect(Rect::MakeSize(target->GetSize()));
140  contents->SetLabel("Subpass");
141  contents->SetTexture(target);
142  contents->SetSourceRect(Rect::MakeSize(target->GetSize()));
143  contents->SetOpacity(paint_.color.alpha);
144  contents->SetDeferApplyingOpacity(true);
145 
146  return paint_.WithFiltersForSubpassTarget(std::move(contents),
147  effect_transform);
148 }

◆ WithImageFilter()

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

Implements impeller::EntityPassDelegate.

Definition at line 151 of file paint_pass_delegate.cc.

153  {
154  return paint_.WithImageFilter(input, effect_transform,
156 }

The documentation for this class was generated from the following files:
impeller::Paint::color
Color color
Definition: paint.h:51
impeller::BlendMode::kDestination
@ kDestination
impeller::Color::alpha
Scalar alpha
Definition: color.h:143
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:64
impeller::Entity::RenderingMode::kSubpass
@ kSubpass
impeller::Paint::WithImageFilter
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition: paint.cc:87
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:44
impeller::TextureContents::MakeRect
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
Definition: texture_contents.cc:27
impeller::Paint::WithFiltersForSubpassTarget
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:66
impeller::Paint::blend_mode
BlendMode blend_mode
Definition: paint.h:60
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:63