| 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/contents/texture_contents.h"
17 #include "impeller/entity/entity.h"
18 #include "impeller/entity/geometry/geometry.h"
19 #include "impeller/geometry/color.h"
20
21 namespace impeller {
22
23 struct Paint {
24 using ImageFilterProc = std::function<std::shared_ptr<FilterContents>(
25 FilterInput::Ref,
26 const Matrix& effect_transform,
27 Entity::RenderingMode rendering_mode)>;
28 using MaskFilterProc = std::function<std::shared_ptr<FilterContents>(
29 FilterInput::Ref,
30 bool is_solid_color,
31 const Matrix& effect_transform)>;
32 using ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>;
33
34 enum class Style {
35 kFill,
36 kStroke,
37 };
38
39 struct MaskBlurDescriptor {
40 FilterContents::BlurStyle style;
41 Sigma sigma;
42
43 std::shared_ptr<FilterContents> CreateMaskBlur(
44 std::shared_ptr<ColorSourceContents> color_source_contents,
45 const std::shared_ptr<ColorFilter>& color_filter) const;
46
47 std::shared_ptr<FilterContents> CreateMaskBlur(
48 std::shared_ptr<TextureContents> texture_contents) const;
49
50 std::shared_ptr<FilterContents> CreateMaskBlur(
51 const FilterInput::Ref& input,
52 bool is_solid_color) const;
53 };
54
55 Color color = Color::Black();
56 ColorSource color_source;
57 bool dither = false;
58
59 Scalar stroke_width = 0.0;
60 Cap stroke_cap = Cap::kButt;
61 Join stroke_join = Join::kMiter;
62 Scalar stroke_miter = 4.0;
63 Style style = Style::kFill;
64 BlendMode blend_mode = BlendMode::kSourceOver;
65 bool invert_colors = false;
66
67 std::shared_ptr<ImageFilter> image_filter;
68 std::shared_ptr<ColorFilter> color_filter;
69 std::optional<MaskBlurDescriptor> mask_blur_descriptor;
70
71 std::shared_ptr<ColorFilter> GetColorFilter() const;
72
73 /// @brief Wrap this paint's configured filters to the given contents.
74 /// @param[in] input The contents to wrap with paint's filters.
75 /// @return The filter-wrapped contents. If there are no filters that need
76 /// to be wrapped for the current paint configuration, the
77 /// original contents is returned.
78 std::shared_ptr<Contents> WithFilters(std::shared_ptr<Contents> input) const;
79
80 /// @brief Wrap this paint's configured filters to the given contents of
81 /// subpass target.
82 /// @param[in] input The contents of subpass target to wrap with paint's
83 /// filters.
84 ///
85 /// @return The filter-wrapped contents. If there are no filters that need
86 /// to be wrapped for the current paint configuration, the
87 /// original contents is returned.
88 std::shared_ptr<Contents> WithFiltersForSubpassTarget(
89 std::shared_ptr<Contents> input,
90 const Matrix& effect_transform = Matrix()) const;
91
92 std::shared_ptr<Contents> CreateContentsForGeometry(
93 const std::shared_ptr<Geometry>& geometry) const;
94
95 /// @brief Whether this paint has a color filter that can apply opacity
96 bool HasColorFilter() const;
97
98 std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
99 bool is_solid_color) const;
100
101 std::shared_ptr<FilterContents> WithImageFilter(
102 const FilterInput::Variant& input,
103 const Matrix& effect_transform,
104 Entity::RenderingMode rendering_mode) const;
105
106 private:
107 std::shared_ptr<Contents> WithColorFilter(
108 std::shared_ptr<Contents> input,
109 ColorFilterContents::AbsorbOpacity absorb_opacity =
110 ColorFilterContents::AbsorbOpacity::kNo) const;
111 };
112
113 } // namespace impeller
114
115 #endif // FLUTTER_IMPELLER_AIKS_PAINT_H_
impeller::Paint::stroke_cap
Cap stroke_cap
Definition: paint.h:60
impeller::Paint::WithMaskBlur
std::shared_ptr< Contents > WithMaskBlur(std::shared_ptr< Contents > input, bool is_solid_color) const
Definition: paint.cc:79
contents.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
image_filter.h
texture_contents.h
impeller::Paint::Style::kStroke
@ kStroke
entity.h
impeller::Paint
Definition: paint.h:23
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:26
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:27
impeller::Paint::MaskBlurDescriptor::sigma
Sigma sigma
Definition: paint.h:41
impeller::Paint::color
Color color
Definition: paint.h:55
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:40
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:153
impeller::Paint::MaskBlurDescriptor
Definition: paint.h:39
impeller::Cap::kButt
@ kButt
impeller::Paint::color_source
ColorSource color_source
Definition: paint.h:56
impeller::Join::kMiter
@ kMiter
impeller::Paint::stroke_miter
Scalar stroke_miter
Definition: paint.h:62
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:68
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:213
impeller::Paint::style
Style style
Definition: paint.h:63
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:31
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:88
impeller::Paint::ColorSourceProc
std::function< std::shared_ptr< ColorSourceContents >()> ColorSourceProc
Definition: paint.h:32
impeller::Join
Join
Definition: path.h:23
impeller::Color::Black
static constexpr Color Black()
Definition: color.h:258
impeller::Paint::invert_colors
bool invert_colors
Definition: paint.h:65
color.h
impeller::Paint::HasColorFilter
bool HasColorFilter() const
Whether this paint has a color filter that can apply opacity.
Definition: paint.cc:227
color_filter.h
impeller::Paint::Style
Style
Definition: paint.h:34
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:28
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:14
impeller
Definition: aiks_blur_unittests.cc:20
impeller::Paint::dither
bool dither
Definition: paint.h:57
impeller::Paint::mask_blur_descriptor
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:69
impeller::Paint::stroke_width
Scalar stroke_width
Definition: paint.h:59
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:56
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:67
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::Paint::blend_mode
BlendMode blend_mode
Definition: paint.h:64
impeller::Cap
Cap
Definition: path.h:17
impeller::Paint::CreateContentsForGeometry
std::shared_ptr< Contents > CreateContentsForGeometry(const std::shared_ptr< Geometry > &geometry) const
Definition: paint.cc:30
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:67
impeller::Paint::stroke_join
Join stroke_join
Definition: paint.h:61