| Flutter Impeller |

Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
impeller::Paint Struct Reference

`#include <paint.h>`

## Classes
struct | MaskBlurDescriptor

## Public Types
enum | Style { Style::kFill, Style::kStroke }
using | ImageFilterProc = std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)>
using | MaskFilterProc = std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, bool is_solid_color, const Matrix &effect_transform)>
using | ColorSourceProc = std::function< std::shared_ptr< ColorSourceContents >()>

## Public Member Functions
std::shared_ptr< ColorFilter > | GetColorFilter () const
std::shared_ptr< Contents > | WithFilters (std::shared_ptr< Contents > input) const
| Wrap this paint's configured filters to the given contents. More...
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. More...
std::shared_ptr< Contents > | CreateContentsForGeometry (const std::shared_ptr< Geometry > &geometry) const
bool | HasColorFilter () const
| Whether this paint has a color filter that can apply opacity. More...
std::shared_ptr< Contents > | WithMaskBlur (std::shared_ptr< Contents > input, bool is_solid_color, const Matrix &ctm) const
std::shared_ptr< FilterContents > | WithImageFilter (const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const

## Static Public Member Functions
static bool | CanApplyOpacityPeephole (const Paint &paint)
| Whether or not a save layer with the provided paint can perform the opacity peephole optimization. More...

## Public Attributes
Color | color = Color::Black()
ColorSource | color_source
Scalar | stroke_width = 0.0
Cap | stroke_cap = Cap::kButt
Join | stroke_join = Join::kMiter
Scalar | stroke_miter = 4.0
Style | style = Style::kFill
BlendMode | blend_mode = BlendMode::kSourceOver
bool | invert_colors = false
std::shared_ptr< ImageFilter > | image_filter
std::shared_ptr< ColorFilter > | color_filter
std::optional< MaskBlurDescriptor > | mask_blur_descriptor

## Detailed Description

Definition at line 23 of file paint.h.

## Member Typedef Documentation

## ◆ ColorSourceProc

using impeller::Paint::ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>

Definition at line 32 of file paint.h.

## ◆ ImageFilterProc

using impeller::Paint::ImageFilterProc = std::function<std::shared_ptr<FilterContents>( FilterInput::Ref, const Matrix& effect_transform, Entity::RenderingMode rendering_mode)>

Definition at line 27 of file paint.h.

## ◆ MaskFilterProc

using impeller::Paint::MaskFilterProc = std::function<std::shared_ptr<FilterContents>( FilterInput::Ref, bool is_solid_color, const Matrix& effect_transform)>

Definition at line 31 of file paint.h.

## Member Enumeration Documentation

## ◆ Style

enum impeller::Paint::Style
| strong

Enumerator
kFill |
kStroke |

Definition at line 43 of file paint.h.

43 {
44 kFill,
45 kStroke,
46 };

## Member Function Documentation

## ◆ CanApplyOpacityPeephole()

static bool impeller::Paint::CanApplyOpacityPeephole | ( | const Paint & | paint | ) |
| inline static

Whether or not a save layer with the provided paint can perform the opacity peephole optimization.

Definition at line 36 of file paint.h.

36 {
37 return paint.blend_mode == BlendMode::kSourceOver &&
38 paint.invert_colors == false &&
39 !paint.mask_blur_descriptor.has_value() &&
40 paint.image_filter == nullptr && paint.color_filter == nullptr;
41 }

References impeller::kSourceOver, and paint.

Referenced by impeller::ExperimentalCanvas::SaveLayer().

## ◆ CreateContentsForGeometry()

std::shared_ptr< Contents > impeller::Paint::CreateContentsForGeometry | ( | const std::shared_ptr< Geometry > & | geometry | ) | const

Definition at line 30 of file paint.cc.

31 {
32 auto contents = color_source.GetContents(*this);
33
34 // Attempt to apply the color filter on the CPU first.
35 // Note: This is not just an optimization; some color sources rely on
36 // CPU-applied color filters to behave properly.
37 auto color_filter = GetColorFilter();
38 bool needs_color_filter = !!color_filter;
39 if (color_filter &&
40 contents->ApplyColorFilter(color_filter->GetCPUColorFilterProc())) {
41 needs_color_filter = false;
42 }
43
44 contents->SetGeometry(geometry);
45 if (mask_blur_descriptor.has_value()) {
46 // If there's a mask blur and we need to apply the color filter on the GPU,
47 // we need to be careful to only apply the color filter to the source
48 // colors. CreateMaskBlur is able to handle this case.
49 return mask_blur_descriptor->CreateMaskBlur(
50 contents, needs_color_filter ? color_filter : nullptr);
51 }
52
53 return contents;
54 }

References color_filter, color_source, GetColorFilter(), impeller::ColorSource::GetContents(), and mask_blur_descriptor.

## ◆ GetColorFilter()

std::shared_ptr< ColorFilter > impeller::Paint::GetColorFilter | ( |  | ) | const

Definition at line 222 of file paint.cc.

222 {
223 if (invert_colors && color_filter) {
224 auto filter = ColorFilter::MakeMatrix(kColorInversion);
225 return ColorFilter::MakeComposed(filter, color_filter);
226 }
227 if (invert_colors) {
228 return ColorFilter::MakeMatrix(kColorInversion);
229 }
230 if (color_filter) {
231 return color_filter;
232 }
233 return nullptr;
234 }

References color_filter, invert_colors, impeller::kColorInversion, impeller::ColorFilter::MakeComposed(), and impeller::ColorFilter::MakeMatrix().

Referenced by CreateContentsForGeometry().

## ◆ HasColorFilter()

bool impeller::Paint::HasColorFilter | ( |  | ) | const

Whether this paint has a color filter that can apply opacity.

Definition at line 236 of file paint.cc.

236 {
237 return !!color_filter || invert_colors;
238 }

References color_filter, and invert_colors.

## ◆ WithFilters()

std::shared_ptr< Contents > impeller::Paint::WithFilters | ( | std::shared_ptr< Contents > | input | ) | const

Wrap this paint's configured filters to the given contents.

Parameters

  [in] | input | The contents to wrap with paint's filters.

Returns
  The filter-wrapped contents. If there are no filters that need to be wrapped for the current paint configuration, the original contents is returned.

Definition at line 56 of file paint.cc.

57 {
58 input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
59 auto image_filter =
60 WithImageFilter(input, Matrix(), Entity::RenderingMode::kDirect);
61 if (image_filter) {
62 input = image_filter;
63 }
64 return input;
65 }

References image_filter, impeller::Entity::kDirect, impeller::ColorFilterContents::kYes, and WithImageFilter().

## ◆ WithFiltersForSubpassTarget()

std::shared_ptr< Contents > impeller::Paint::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.

Parameters

  [in] | input | The contents of subpass target to wrap with paint's filters.

Returns
  The filter-wrapped contents. If there are no filters that need to be wrapped for the current paint configuration, the original contents is returned.

Definition at line 67 of file paint.cc.

69 {
70 auto image_filter =
71 WithImageFilter(input, effect_transform,
72 Entity::RenderingMode::kSubpassPrependSnapshotTransform);
73 if (image_filter) {
74 input = image_filter;
75 }
76 input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
77 return input;
78 }

References image_filter, impeller::Entity::kSubpassPrependSnapshotTransform, impeller::ColorFilterContents::kYes, and WithImageFilter().

Referenced by impeller::PaintPassDelegate::CreateContentsForSubpassTarget().

## ◆ WithImageFilter()

std::shared_ptr< FilterContents > impeller::Paint::WithImageFilter | ( | const FilterInput::Variant & | input,
|  | const Matrix & | effect_transform,
|  | Entity::RenderingMode | rendering_mode
| ) |  | const

Definition at line 90 of file paint.cc.

93 {
94 if (!image_filter) {
95 return nullptr;
96 }
97 auto filter = image_filter->WrapInput(FilterInput::Make(input));
98 filter->SetRenderingMode(rendering_mode);
99 filter->SetEffectTransform(effect_transform);
100 return filter;
101 }

References image_filter, and impeller::FilterInput::Make().

Referenced by WithFilters(), WithFiltersForSubpassTarget(), and impeller::PaintPassDelegate::WithImageFilter().

## ◆ WithMaskBlur()

std::shared_ptr< Contents > impeller::Paint::WithMaskBlur | ( | std::shared_ptr< Contents > | input,
|  | bool | is_solid_color,
|  | const Matrix & | ctm
| ) |  | const

Definition at line 80 of file paint.cc.

82 {
83 if (mask_blur_descriptor.has_value()) {
84 input = mask_blur_descriptor->CreateMaskBlur(FilterInput::Make(input),
85 is_solid_color, ctm);
86 }
87 return input;
88 }

References impeller::FilterInput::Make(), and mask_blur_descriptor.

## Member Data Documentation

## ◆ blend_mode

BlendMode impeller::Paint::blend_mode = BlendMode::kSourceOver

Definition at line 76 of file paint.h.

Referenced by impeller::PaintPassDelegate::CanElide(), impeller::ExperimentalCanvas::Restore(), impeller::DlDispatcherBase::setBlendMode(), and impeller::testing::TEST_P().

## ◆ color

Color impeller::Paint::color = Color::Black()

Definition at line 68 of file paint.h.

Referenced by impeller::testing::BlendModeTest(), impeller::PaintPassDelegate::CreateContentsForSubpassTarget(), impeller::DlDispatcherBase::drawDisplayList(), impeller::TextFrameDispatcher::drawTextFrame(), impeller::ExperimentalCanvas::SaveLayer(), impeller::Canvas::SaveLayer(), impeller::DlDispatcherBase::setColor(), impeller::TextFrameDispatcher::setColor(), and impeller::testing::TEST_P().

## ◆ color_filter

std::shared_ptr<ColorFilter> impeller::Paint::color_filter

Definition at line 80 of file paint.h.

Referenced by CreateContentsForGeometry(), impeller::Paint::MaskBlurDescriptor::CreateMaskBlur(), GetColorFilter(), HasColorFilter(), and impeller::DlDispatcherBase::setColorFilter().

## ◆ color_source

ColorSource impeller::Paint::color_source

Definition at line 69 of file paint.h.

Referenced by CreateContentsForGeometry(), impeller::DlDispatcherBase::setColorSource(), and impeller::testing::TEST_P().

## ◆ image_filter

std::shared_ptr<ImageFilter> impeller::Paint::image_filter

Definition at line 79 of file paint.h.

Referenced by impeller::DlDispatcherBase::setImageFilter(), impeller::testing::TEST(), WithFilters(), WithFiltersForSubpassTarget(), and WithImageFilter().

## ◆ invert_colors

bool impeller::Paint::invert_colors = false

Definition at line 77 of file paint.h.

Referenced by GetColorFilter(), HasColorFilter(), and impeller::DlDispatcherBase::setInvertColors().

## ◆ mask_blur_descriptor

std::optional<MaskBlurDescriptor> impeller::Paint::mask_blur_descriptor

Definition at line 81 of file paint.h.

Referenced by CreateContentsForGeometry(), impeller::DlDispatcherBase::setMaskFilter(), impeller::testing::TEST_P(), and WithMaskBlur().

## ◆ stroke_cap

Cap impeller::Paint::stroke_cap = Cap::kButt

Definition at line 72 of file paint.h.

Referenced by impeller::TextFrameDispatcher::drawTextFrame(), impeller::DlDispatcherBase::setStrokeCap(), and impeller::TextFrameDispatcher::setStrokeCap().

## ◆ stroke_join

Join impeller::Paint::stroke_join = Join::kMiter

Definition at line 73 of file paint.h.

Referenced by impeller::TextFrameDispatcher::drawTextFrame(), impeller::DlDispatcherBase::setStrokeJoin(), and impeller::TextFrameDispatcher::setStrokeJoin().

## ◆ stroke_miter

Scalar impeller::Paint::stroke_miter = 4.0

Definition at line 74 of file paint.h.

Referenced by impeller::TextFrameDispatcher::drawTextFrame(), impeller::DlDispatcherBase::setStrokeMiter(), and impeller::TextFrameDispatcher::setStrokeMiter().

## ◆ stroke_width

Scalar impeller::Paint::stroke_width = 0.0

Definition at line 71 of file paint.h.

Referenced by impeller::TextFrameDispatcher::drawTextFrame(), impeller::DlDispatcherBase::setStrokeWidth(), and impeller::TextFrameDispatcher::setStrokeWidth().

## ◆ style

Style impeller::Paint::style = Style::kFill

Definition at line 75 of file paint.h.

Referenced by impeller::Paint::MaskBlurDescriptor::CreateMaskBlur(), impeller::DlDispatcherBase::drawDashedLine(), impeller::TextFrameDispatcher::drawTextFrame(), impeller::DlDispatcherBase::setDrawStyle(), and impeller::TextFrameDispatcher::setDrawStyle().

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

- impeller/aiks/paint.h
- impeller/aiks/paint.cc

impeller::ColorSource::GetContents
std::shared_ptr< ColorSourceContents > GetContents(const Paint &paint) const
Definition: color_source.cc:264
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::ColorFilter::MakeComposed
static std::shared_ptr< ColorFilter > MakeComposed(const std::shared_ptr< ColorFilter > &outer, const std::shared_ptr< ColorFilter > &inner)
Definition: color_filter.cc:40
impeller::Paint::color_source
ColorSource color_source
Definition: paint.h:69
impeller::PolygonMode::kFill
@ kFill
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:80
impeller::kColorInversion
constexpr ColorMatrix kColorInversion
A color matrix which inverts colors.
Definition: paint.cc:20
impeller::Paint::GetColorFilter
std::shared_ptr< ColorFilter > GetColorFilter() const
Definition: paint.cc:222
impeller::Entity::RenderingMode::kDirect
@ kDirect
impeller::ColorFilter::MakeMatrix
static std::shared_ptr< ColorFilter > MakeMatrix(ColorMatrix color_matrix)
Definition: color_filter.cc:28
impeller::Paint::WithImageFilter
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition: paint.cc:90
impeller::Entity::RenderingMode::kSubpassPrependSnapshotTransform
@ kSubpassPrependSnapshotTransform
impeller::Paint::invert_colors
bool invert_colors
Definition: paint.h:77
paint
const Paint & paint
Definition: color_source.cc:38
impeller::ColorFilterContents::AbsorbOpacity::kYes
@ kYes
impeller::Paint::mask_blur_descriptor
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:81
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:79