| Flutter Impeller |

paint.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_AIKS_PAINT_H_
6 #define FLUTTER_IMPELLER_AIKS_PAINT_H_
7
8 #include <memory>
9
10 #include "impeller/aiks/color_filter.h"
11 #include "impeller/aiks/color_source.h"
12 #include "impeller/aiks/image_filter.h"
13 #include "impeller/entity/contents/contents.h"
14 #include "impeller/entity/contents/filters/color_filter_contents.h"
15 #include "impeller/entity/contents/filters/filter_contents.h"
16 #include "impeller/entity/entity.h"
17 #include "impeller/entity/geometry/geometry.h"
18 #include "impeller/geometry/color.h"
19
20 namespace impeller {
21
22 struct Paint {
23 using ImageFilterProc = std::function<std::shared_ptr<FilterContents>(
24 FilterInput::Ref,
25 const Matrix& effect_transform,
26 Entity::RenderingMode rendering_mode)>;
27 using MaskFilterProc = std::function<std::shared_ptr<FilterContents>(
28 FilterInput::Ref,
29 bool is_solid_color,
30 const Matrix& effect_transform)>;
31 using ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>;
32
33 enum class Style {
34 kFill,
35 kStroke,
36 };
37
38 struct MaskBlurDescriptor {
39 FilterContents::BlurStyle style;
40 Sigma sigma;
41
42 std::shared_ptr<FilterContents> CreateMaskBlur(
43 std::shared_ptr<ColorSourceContents> color_source_contents,
44 const std::shared_ptr<ColorFilter>& color_filter) const;
45
46 std::shared_ptr<FilterContents> CreateMaskBlur(
47 const FilterInput::Ref& input,
48 bool is_solid_color) const;
49 };
50
51 Color color = Color::Black();
52 ColorSource color_source;
53 bool dither = false;
54
55 Scalar stroke_width = 0.0;
56 Cap stroke_cap = Cap::kButt;
57 Join stroke_join = Join::kMiter;
58 Scalar stroke_miter = 4.0;
59 Style style = Style::kFill;
60 BlendMode blend_mode = BlendMode::kSourceOver;
61 bool invert_colors = false;
62
63 std::shared_ptr<ImageFilter> image_filter;
64 std::shared_ptr<ColorFilter> color_filter;
65 std::optional<MaskBlurDescriptor> mask_blur_descriptor;
66
67 std::shared_ptr<ColorFilter> GetColorFilter() const;
68
69 /// @brief Wrap this paint's configured filters to the given contents.
70 /// @param[in] input The contents to wrap with paint's filters.
71 /// @return The filter-wrapped contents. If there are no filters that need
72 /// to be wrapped for the current paint configuration, the
73 /// original contents is returned.
74 std::shared_ptr<Contents> WithFilters(std::shared_ptr<Contents> input) const;
75
76 /// @brief Wrap this paint's configured filters to the given contents of
77 /// subpass target.
78 /// @param[in] input The contents of subpass target to wrap with paint's
79 /// filters.
80 ///
81 /// @return The filter-wrapped contents. If there are no filters that need
82 /// to be wrapped for the current paint configuration, the
83 /// original contents is returned.
84 std::shared_ptr<Contents> WithFiltersForSubpassTarget(
85 std::shared_ptr<Contents> input,
86 const Matrix& effect_transform = Matrix()) const;
87
88 std::shared_ptr<Contents> CreateContentsForGeometry(
89 const std::shared_ptr<Geometry>& geometry) const;
90
91 /// @brief Whether this paint has a color filter that can apply opacity
92 bool HasColorFilter() const;
93
94 std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
95 bool is_solid_color) const;
96
97 std::shared_ptr<FilterContents> WithImageFilter(
98 const FilterInput::Variant& input,
99 const Matrix& effect_transform,
100 Entity::RenderingMode rendering_mode) const;
101
102 private:
103 std::shared_ptr<Contents> WithColorFilter(
104 std::shared_ptr<Contents> input,
105 ColorFilterContents::AbsorbOpacity absorb_opacity =
106 ColorFilterContents::AbsorbOpacity::kNo) const;
107 };
108
109 } // namespace impeller
110
111 #endif // FLUTTER_IMPELLER_AIKS_PAINT_H_
impeller::Paint::stroke_cap
Cap stroke_cap
Definition: paint.h:56
impeller::Paint::WithMaskBlur
std::shared_ptr< Contents > WithMaskBlur(std::shared_ptr< Contents > input, bool is_solid_color) const
Definition: paint.cc:78
contents.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
image_filter.h
impeller::Paint::Style::kStroke
@ kStroke
entity.h
impeller::Paint
Definition: paint.h:22
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:23
impeller::Color
Definition: color.h:124
impeller::Paint::ImageFilterProc
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)> ImageFilterProc
Definition: paint.h:26
impeller::Paint::MaskBlurDescriptor::sigma
Sigma sigma
Definition: paint.h:40
impeller::Paint::color
Color color
Definition: paint.h:51
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:39
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
impeller::ColorFilterContents::AbsorbOpacity::kNo
@ kNo
impeller::Paint::MaskBlurDescriptor::CreateMaskBlur
std::shared_ptr< FilterContents > CreateMaskBlur(std::shared_ptr< ColorSourceContents > color_source_contents, const std::shared_ptr< ColorFilter > &color_filter) const
Definition: paint.cc:124
impeller::Paint::MaskBlurDescriptor
Definition: paint.h:38
impeller::Cap::kButt
@ kButt
impeller::Paint::color_source
ColorSource color_source
Definition: paint.h:52
impeller::Join::kMiter
@ kMiter
impeller::Paint::stroke_miter
Scalar stroke_miter
Definition: paint.h:58
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:64
filter_contents.h
impeller::ColorSource
Definition: color_source.h:28
color_source.h
impeller::Paint::GetColorFilter
std::shared_ptr< ColorFilter > GetColorFilter() const
Definition: paint.cc:184
impeller::Paint::style
Style style
Definition: paint.h:59
impeller::Paint::Style::kFill
@ kFill
impeller::Paint::MaskFilterProc
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, bool is_solid_color, const Matrix &effect_transform)> MaskFilterProc
Definition: paint.h:30
geometry.h
impeller::Sigma
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32
impeller::FilterInput::Variant
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
Definition: filter_input.h:37
color_filter_contents.h
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::ColorSourceProc
std::function< std::shared_ptr< ColorSourceContents >()> ColorSourceProc
Definition: paint.h:31
impeller::Join
Join
Definition: path.h:24
impeller::Color::Black
static constexpr Color Black()
Definition: color.h:258
impeller::Paint::invert_colors
bool invert_colors
Definition: paint.h:61
color.h
impeller::Paint::HasColorFilter
bool HasColorFilter() const
Whether this paint has a color filter that can apply opacity.
Definition: paint.cc:198
color_filter.h
impeller::Paint::Style
Style
Definition: paint.h:33
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:26
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:14
impeller
Definition: aiks_context.cc:10
impeller::Paint::dither
bool dither
Definition: paint.h:53
impeller::Paint::mask_blur_descriptor
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:65
impeller::Paint::stroke_width
Scalar stroke_width
Definition: paint.h:55
impeller::Paint::WithFilters
std::shared_ptr< Contents > WithFilters(std::shared_ptr< Contents > input) const
Wrap this paint's configured filters to the given contents.
Definition: paint.cc:55
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
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::BlendMode::kSourceOver
@ kSourceOver
impeller::Paint::blend_mode
BlendMode blend_mode
Definition: paint.h:60
impeller::Cap
Cap
Definition: path.h:18
impeller::Paint::CreateContentsForGeometry
std::shared_ptr< Contents > CreateContentsForGeometry(const std::shared_ptr< Geometry > &geometry) const
Definition: paint.cc:29
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:63
impeller::Paint::stroke_join
Join stroke_join
Definition: paint.h:57