| 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< 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 > | CreateContentsForEntity (const Path &path={}, bool cover=false) const
std::shared_ptr< Contents > | CreateContentsForGeometry (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 25 of file paint.h.

## Member Typedef Documentation

## ◆ ColorSourceProc

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

Definition at line 34 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 29 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 33 of file paint.h.

## Member Enumeration Documentation

## ◆ Style

enum impeller::Paint::Style
| strong

Enumerator
kFill |
kStroke |

Definition at line 36 of file paint.h.

36 {
37 kFill,
38 kStroke,
39 };

## Member Function Documentation

## ◆ CreateContentsForEntity()

std::shared_ptr< Contents > impeller::Paint::CreateContentsForEntity | ( | const Path & | path = `{}`,
|  | bool | cover = `false`
| ) |  | const

Definition at line 17 of file paint.cc.

18 {
19 std::unique_ptr<Geometry> geometry;
20 switch (style) {
21 case Style::kFill:
22 geometry = cover ? Geometry::MakeCover() : Geometry::MakeFillPath(path);
23 break;
24 case Style::kStroke:
25 geometry =
26 cover ? Geometry::MakeCover()
27 : Geometry::MakeStrokePath(path, stroke_width, stroke_miter,
28 stroke_cap, stroke_join);
29 break;
30 }
31 return CreateContentsForGeometry(std::move(geometry));
32 }

References CreateContentsForGeometry(), kFill, kStroke, impeller::Geometry::MakeCover(), impeller::Geometry::MakeFillPath(), impeller::Geometry::MakeStrokePath(), stroke_cap, stroke_join, stroke_miter, stroke_width, and style.

Referenced by impeller::Canvas::DrawPaint(), and impeller::Canvas::DrawPath().

## ◆ CreateContentsForGeometry()

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

Definition at line 34 of file paint.cc.

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

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

Referenced by CreateContentsForEntity(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), and impeller::Canvas::DrawVertices().

## ◆ HasColorFilter()

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

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

Definition at line 211 of file paint.cc.

211 {
212 return !!color_filter;
213 }

References color_filter.

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

60 {
61 input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
62 input = WithInvertFilter(input);
63 auto image_filter =
64 WithImageFilter(input, Matrix(), Entity::RenderingMode::kDirect);
65 if (image_filter) {
66 input = image_filter;
67 }
68 return input;
69 }

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

Referenced by impeller::Canvas::DrawAtlas(), impeller::Canvas::DrawImageRect(), impeller::Canvas::DrawPath(), impeller::Canvas::DrawPoints(), impeller::Canvas::DrawRect(), impeller::Canvas::DrawRRect(), 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 71 of file paint.cc.

73 {
74 auto image_filter =
75 WithImageFilter(input, effect_transform, Entity::RenderingMode::kSubpass);
76 if (image_filter) {
77 input = image_filter;
78 }
79 input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
80 return input;
81 }

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

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

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

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

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 63 of file paint.h.

Referenced by impeller::PaintPassDelegate::CanElide(), impeller::OpacityPeepholePassDelegate::CanElide(), impeller::Canvas::DrawAtlas(), impeller::DlDispatcher::drawColor(), impeller::Canvas::DrawImageRect(), 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 54 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 67 of file paint.h.

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

## ◆ color_source

ColorSource impeller::Paint::color_source

Definition at line 55 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 56 of file paint.h.

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

## ◆ image_filter

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

Definition at line 66 of file paint.h.

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

## ◆ invert_colors

bool impeller::Paint::invert_colors = false

Definition at line 64 of file paint.h.

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

## ◆ mask_blur_descriptor

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

Definition at line 68 of file paint.h.

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

## ◆ stroke_cap

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

Definition at line 59 of file paint.h.

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

## ◆ stroke_join

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

Definition at line 60 of file paint.h.

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

## ◆ stroke_miter

Scalar impeller::Paint::stroke_miter = 4.0

Definition at line 61 of file paint.h.

Referenced by CreateContentsForEntity(), and impeller::DlDispatcher::setStrokeMiter().

## ◆ stroke_width

Scalar impeller::Paint::stroke_width = 0.0

Definition at line 58 of file paint.h.

Referenced by CreateContentsForEntity(), 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 62 of file paint.h.

Referenced by CreateContentsForEntity(), impeller::Paint::MaskBlurDescriptor::CreateMaskBlur(), impeller::DlDispatcher::drawLine(), 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::Paint::stroke_cap
Cap stroke_cap
Definition: paint.h:59
impeller::ColorSource::GetContents
std::shared_ptr< ColorSourceContents > GetContents(const Paint &paint) const
Definition: color_source.cc:238
impeller::Paint::Style::kStroke
@ kStroke
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::Paint::color_source
ColorSource color_source
Definition: paint.h:55
impeller::PolygonMode::kFill
@ kFill
impeller::Paint::stroke_miter
Scalar stroke_miter
Definition: paint.h:61
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:67
impeller::Paint::style
Style style
Definition: paint.h:62
impeller::Paint::Style::kFill
@ kFill
impeller::Entity::RenderingMode::kDirect
@ kDirect
impeller::Entity::RenderingMode::kSubpass
@ kSubpass
impeller::Geometry::MakeCover
static std::unique_ptr< Geometry > MakeCover()
Definition: geometry.cc:138
impeller::Paint::WithImageFilter
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition: paint.cc:92
impeller::Paint::CreateContentsForGeometry
std::shared_ptr< Contents > CreateContentsForGeometry(std::shared_ptr< Geometry > geometry) const
Definition: paint.cc:34
impeller::ColorFilterContents::AbsorbOpacity::kYes
@ kYes
impeller::Paint::mask_blur_descriptor
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:68
impeller::Paint::stroke_width
Scalar stroke_width
Definition: paint.h:58
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:66
impeller::Paint::stroke_join
Join stroke_join
Definition: paint.h:60