| Flutter Impeller |

Classes | Public Types | 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
std::shared_ptr< FilterContents > | WithImageFilter (const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const

## Public Attributes
Color | color = Color::Black()
ColorSource | color_source
bool | dither = false
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 22 of file paint.h.

## Member Typedef Documentation

## ◆ ColorSourceProc

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

Definition at line 31 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 26 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 30 of file paint.h.

## Member Enumeration Documentation

## ◆ Style

enum impeller::Paint::Style
| strong

Enumerator
kFill |
kStroke |

Definition at line 33 of file paint.h.

33 {
34 kFill,
35 kStroke,
36 };

## Member Function Documentation

## ◆ CreateContentsForGeometry()

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

Definition at line 29 of file paint.cc.

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

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 184 of file paint.cc.

184 {
185 if (invert_colors && color_filter) {
186 auto filter = ColorFilter::MakeMatrix(kColorInversion);
187 return ColorFilter::MakeComposed(filter, color_filter);
188 }
189 if (invert_colors) {
190 return ColorFilter::MakeMatrix(kColorInversion);
191 }
192 if (color_filter) {
193 return color_filter;
194 }
195 return nullptr;
196 }

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 198 of file paint.cc.

198 {
199 return !!color_filter || invert_colors;
200 }

References color_filter, and invert_colors.

Referenced by impeller::Canvas::DrawImageRect(), and impeller::testing::TEST_P().

## ◆ 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 55 of file paint.cc.

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

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

Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawTextFrame(), and impeller::Canvas::DrawVertices().

## ◆ 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 66 of file paint.cc.

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

References image_filter, impeller::Entity::kSubpass, 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 87 of file paint.cc.

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

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

Definition at line 78 of file paint.cc.

79 {
80 if (mask_blur_descriptor.has_value()) {
81 input = mask_blur_descriptor->CreateMaskBlur(FilterInput::Make(input),
82 is_solid_color);
83 }
84 return input;
85 }

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

Referenced by impeller::Canvas::DrawTextFrame().

## Member Data Documentation

## ◆ blend_mode

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

Definition at line 60 of file paint.h.

Referenced by impeller::PaintPassDelegate::CanElide(), impeller::OpacityPeepholePassDelegate::CanElide(), impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawCircle(), impeller::DlDispatcher::drawColor(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawLine(), impeller::Canvas::DrawOval(), impeller::Canvas::DrawPaint(), impeller::Canvas::DrawPath(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), impeller::Canvas::SaveLayer(), impeller::DlDispatcher::setBlendMode(), and impeller::testing::TEST_P().

## ◆ color

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

Definition at line 51 of file paint.h.

Referenced by impeller::OpacityPeepholePassDelegate::CanCollapseIntoParentPass(), impeller::PaintPassDelegate::CreateContentsForSubpassTarget(), impeller::Canvas::DrawAtlas(), impeller::DlDispatcher::drawColor(), impeller::DlDispatcher::drawDisplayList(), impeller::Canvas::DrawImageRect(), impeller::DlDispatcher::drawShadow(), impeller::Canvas::DrawTextFrame(), impeller::Canvas::DrawVertices(), impeller::DlDispatcher::setColor(), and impeller::testing::TEST_P().

## ◆ color_filter

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

Definition at line 64 of file paint.h.

Referenced by impeller::OpacityPeepholePassDelegate::CanCollapseIntoParentPass(), CreateContentsForGeometry(), impeller::Paint::MaskBlurDescriptor::CreateMaskBlur(), GetColorFilter(), HasColorFilter(), impeller::DlDispatcher::setColorFilter(), and impeller::testing::TEST_P().

## ◆ color_source

ColorSource impeller::Paint::color_source

Definition at line 52 of file paint.h.

Referenced by impeller::testing::CanRenderConicalGradientWithDithering(), impeller::testing::CanRenderLinearGradientWithDithering(), impeller::testing::CanRenderRadialGradientWithDithering(), impeller::testing::CanRenderSweepGradientWithDithering(), CreateContentsForGeometry(), impeller::Canvas::DrawVertices(), impeller::DlDispatcher::setColorSource(), impeller::testing::TEST_F(), impeller::testing::TEST_P(), and impeller::UseColorSourceContents().

## ◆ dither

bool impeller::Paint::dither = false

Definition at line 53 of file paint.h.

Referenced by impeller::testing::CanRenderConicalGradientWithDithering(), impeller::testing::CanRenderLinearGradientWithDithering(), impeller::testing::CanRenderRadialGradientWithDithering(), and impeller::testing::CanRenderSweepGradientWithDithering().

## ◆ image_filter

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

Definition at line 63 of file paint.h.

Referenced by impeller::OpacityPeepholePassDelegate::CanCollapseIntoParentPass(), impeller::Canvas::SaveLayer(), impeller::DlDispatcher::setImageFilter(), impeller::testing::TEST(), impeller::testing::TEST_P(), WithFilters(), WithFiltersForSubpassTarget(), and WithImageFilter().

## ◆ invert_colors

bool impeller::Paint::invert_colors = false

Definition at line 61 of file paint.h.

Referenced by GetColorFilter(), HasColorFilter(), impeller::DlDispatcher::setInvertColors(), and impeller::testing::TEST_P().

## ◆ mask_blur_descriptor

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

Definition at line 65 of file paint.h.

Referenced by CreateContentsForGeometry(), impeller::DlDispatcher::drawShadow(), impeller::Canvas::DrawTextFrame(), impeller::DlDispatcher::setMaskFilter(), impeller::testing::TEST_P(), and WithMaskBlur().

## ◆ stroke_cap

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

Definition at line 56 of file paint.h.

Referenced by impeller::Canvas::DrawLine(), impeller::DlDispatcher::drawPoints(), impeller::DlDispatcher::setStrokeCap(), and impeller::testing::TEST_P().

## ◆ stroke_join

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

Definition at line 57 of file paint.h.

Referenced by impeller::DlDispatcher::setStrokeJoin(), and impeller::testing::TEST_P().

## ◆ stroke_miter

Scalar impeller::Paint::stroke_miter = 4.0

Definition at line 58 of file paint.h.

Referenced by impeller::DlDispatcher::setStrokeMiter().

## ◆ stroke_width

Scalar impeller::Paint::stroke_width = 0.0

Definition at line 55 of file paint.h.

Referenced by impeller::Canvas::DrawCircle(), impeller::Canvas::DrawLine(), impeller::DlDispatcher::drawPoints(), impeller::DlDispatcher::setStrokeWidth(), impeller::testing::TEST_F(), and impeller::testing::TEST_P().

## ◆ style

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

Definition at line 59 of file paint.h.

Referenced by impeller::Paint::MaskBlurDescriptor::CreateMaskBlur(), impeller::Canvas::DrawCircle(), impeller::Canvas::DrawOval(), impeller::DlDispatcher::drawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), impeller::DlDispatcher::drawShadow(), impeller::DlDispatcher::setDrawStyle(), impeller::testing::TEST_F(), and impeller::testing::TEST_P().

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:234
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:52
impeller::PolygonMode::kFill
@ kFill
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:64
impeller::kColorInversion
constexpr ColorMatrix kColorInversion
A color matrix which inverts colors.
Definition: paint.cc:19
impeller::Paint::GetColorFilter
std::shared_ptr< ColorFilter > GetColorFilter() const
Definition: paint.cc:184
impeller::Entity::RenderingMode::kDirect
@ kDirect
impeller::Entity::RenderingMode::kSubpass
@ kSubpass
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:87
impeller::Paint::invert_colors
bool invert_colors
Definition: paint.h:61
impeller::ColorFilterContents::AbsorbOpacity::kYes
@ kYes
impeller::Paint::mask_blur_descriptor
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:65
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:63