Flutter Engine
 
Loading...
Searching...
No Matches
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_DISPLAY_LIST_PAINT_H_
6#define FLUTTER_IMPELLER_DISPLAY_LIST_PAINT_H_
7
8#include <memory>
9
24
25namespace impeller {
26
27struct Paint {
28 using ImageFilterProc = std::function<std::shared_ptr<FilterContents>(
30 const Matrix& effect_transform,
31 Entity::RenderingMode rendering_mode)>;
32 using MaskFilterProc = std::function<std::shared_ptr<FilterContents>(
34 bool is_solid_color,
35 const Matrix& effect_transform)>;
36 using ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>;
37
38 /// @brief Whether or not a save layer with the provided paint can perform the
39 /// opacity peephole optimization.
40 static bool CanApplyOpacityPeephole(const Paint& paint) {
41 return paint.blend_mode == BlendMode::kSrcOver &&
42 paint.invert_colors == false &&
43 !paint.mask_blur_descriptor.has_value() &&
44 paint.image_filter == nullptr && paint.color_filter == nullptr;
45 }
46
47 enum class Style {
48 kFill,
49 kStroke,
50 };
51
55 /// Text mask blurs need to not apply the CTM to the blur kernel.
56 /// See: https://github.com/flutter/flutter/issues/115112
57 bool respect_ctm = true;
58
59 std::shared_ptr<FilterContents> CreateMaskBlur(
60 std::shared_ptr<ColorSourceContents> color_source_contents,
62 bool invert_colors,
63 FillRectGeometry* rect_geom) const;
64
65 std::shared_ptr<FilterContents> CreateMaskBlur(
66 std::shared_ptr<TextureContents> texture_contents,
67 FillRectGeometry* rect_geom) const;
68
69 std::shared_ptr<FilterContents> CreateMaskBlur(
71 bool is_solid_color,
72 const Matrix& ctm) const;
73 };
74
79
83 bool invert_colors = false;
84
85 std::optional<MaskBlurDescriptor> mask_blur_descriptor;
86
87 /// @brief Wrap this paint's configured filters to the given contents.
88 /// @param[in] input The contents to wrap with paint's filters.
89 /// @return The filter-wrapped contents. If there are no filters that need
90 /// to be wrapped for the current paint configuration, the
91 /// original contents is returned.
92 std::shared_ptr<Contents> WithFilters(std::shared_ptr<Contents> input) const;
93
94 /// @brief Wrap this paint's configured filters to the given contents of
95 /// subpass target.
96 /// @param[in] input The contents of subpass target to wrap with paint's
97 /// filters.
98 ///
99 /// @return The filter-wrapped contents. If there are no filters that need
100 /// to be wrapped for the current paint configuration, the
101 /// original contents is returned.
102 std::shared_ptr<Contents> WithFiltersForSubpassTarget(
103 std::shared_ptr<Contents> input,
104 const Matrix& effect_transform = Matrix()) const;
105
106 /// @brief Whether this paint has a color filter that can apply opacity
107 bool HasColorFilter() const;
108
109 std::shared_ptr<ColorSourceContents> CreateContents() const;
110
111 std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
112 bool is_solid_color,
113 const Matrix& ctm) const;
114
115 std::shared_ptr<FilterContents> WithImageFilter(
117 const Matrix& effect_transform,
118 Entity::RenderingMode rendering_mode) const;
119
120 /// @brief Convert display list colors + stops into impeller colors and
121 /// stops, taking care to ensure that the stops monotonically
122 /// increase from 0.0 to 1.0.
123 ///
124 /// The general process is:
125 /// * Ensure that the first gradient stop value is 0.0. If not, insert a
126 /// new stop with a value of 0.0 and use the first gradient color as this
127 /// new stops color.
128 /// * Ensure the last gradient stop value is 1.0. If not, insert a new stop
129 /// with a value of 1.0 and use the last gradient color as this stops color.
130 /// * Clamp all gradient values between the values of 0.0 and 1.0.
131 /// * For all stop values, ensure that the values are monotonically
132 /// increasing by clamping each value to a minimum of the previous stop
133 /// value and itself. For example, with stop values of 0.0, 0.5, 0.4, 1.0,
134 /// we would clamp such that the values were 0.0, 0.5, 0.5, 1.0.
135 static void ConvertStops(const flutter::DlGradientColorSourceBase* gradient,
136 std::vector<Color>& colors,
137 std::vector<float>& stops);
138
139 private:
140 std::shared_ptr<Contents> WithColorFilter(
141 std::shared_ptr<Contents> input,
144};
145
146} // namespace impeller
147
148#endif // FLUTTER_IMPELLER_DISPLAY_LIST_PAINT_H_
std::shared_ptr< FilterInput > Ref
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
static int input(yyscan_t yyscanner)
BlendMode
Definition color.h:58
static constexpr Color Black()
Definition color.h:266
A 4x4 matrix using column-major storage.
Definition matrix.h:37
FilterContents::BlurStyle style
Definition paint.h:53
std::shared_ptr< FilterContents > CreateMaskBlur(std::shared_ptr< ColorSourceContents > color_source_contents, const flutter::DlColorFilter *color_filter, bool invert_colors, FillRectGeometry *rect_geom) const
Definition paint.cc:395
std::shared_ptr< Contents > WithFilters(std::shared_ptr< Contents > input) const
Wrap this paint's configured filters to the given contents.
Definition paint.cc:278
const flutter::DlColorFilter * color_filter
Definition paint.h:77
const flutter::DlColorSource * color_source
Definition paint.h:76
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)> ImageFilterProc
Definition paint.h:31
static void ConvertStops(const flutter::DlGradientColorSourceBase *gradient, std::vector< Color > &colors, std::vector< float > &stops)
Convert display list colors + stops into impeller colors and stops, taking care to ensure that the st...
Definition paint.cc:37
const flutter::DlImageFilter * image_filter
Definition paint.h:78
std::function< std::shared_ptr< ColorSourceContents >()> ColorSourceProc
Definition paint.h:36
Style style
Definition paint.h:81
std::shared_ptr< Contents > WithMaskBlur(std::shared_ptr< Contents > input, bool is_solid_color, const Matrix &ctm) const
Definition paint.cc:302
bool invert_colors
Definition paint.h:83
static bool CanApplyOpacityPeephole(const Paint &paint)
Whether or not a save layer with the provided paint can perform the opacity peephole optimization.
Definition paint.h:40
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition paint.h:85
Color color
Definition paint.h:75
BlendMode blend_mode
Definition paint.h:82
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, bool is_solid_color, const Matrix &effect_transform)> MaskFilterProc
Definition paint.h:35
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:289
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition paint.cc:312
StrokeParameters stroke
Definition paint.h:80
std::shared_ptr< ColorSourceContents > CreateContents() const
Definition paint.cc:62
bool HasColorFilter() const
Whether this paint has a color filter that can apply opacity.
Definition paint.cc:469
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition sigma.h:32
A structure to store all of the parameters related to stroking a path or basic geometry object.