Flutter Engine
The Flutter Engine
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
20
21namespace impeller {
22
23struct Paint {
24 using ImageFilterProc = std::function<std::shared_ptr<FilterContents>(
26 const Matrix& effect_transform,
27 Entity::RenderingMode rendering_mode)>;
28 using MaskFilterProc = std::function<std::shared_ptr<FilterContents>(
30 bool is_solid_color,
31 const Matrix& effect_transform)>;
32 using ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>;
33
34 /// @brief Whether or not a save layer with the provided paint can perform the
35 /// opacity peephole optimization.
36 static bool CanApplyOpacityPeephole(const Paint& paint) {
37 return paint.blend_mode == BlendMode::kSourceOver &&
38 paint.invert_colors == false &&
39 !paint.mask_blur_descriptor.has_value() &&
40 paint.image_filter == nullptr && paint.color_filter == nullptr;
41 }
42
43 enum class Style {
44 kFill,
45 kStroke,
46 };
47
51 /// Text mask blurs need to not apply the CTM to the blur kernel.
52 /// See: https://github.com/flutter/flutter/issues/115112
53 bool respect_ctm = true;
54
55 std::shared_ptr<FilterContents> CreateMaskBlur(
56 std::shared_ptr<ColorSourceContents> color_source_contents,
57 const std::shared_ptr<ColorFilter>& color_filter) const;
58
59 std::shared_ptr<FilterContents> CreateMaskBlur(
60 std::shared_ptr<TextureContents> texture_contents) const;
61
62 std::shared_ptr<FilterContents> CreateMaskBlur(
63 const FilterInput::Ref& input,
64 bool is_solid_color,
65 const Matrix& ctm) const;
66 };
67
70
77 bool invert_colors = false;
78
79 std::shared_ptr<ImageFilter> image_filter;
80 std::shared_ptr<ColorFilter> color_filter;
81 std::optional<MaskBlurDescriptor> mask_blur_descriptor;
82
83 std::shared_ptr<ColorFilter> GetColorFilter() const;
84
85 /// @brief Wrap this paint's configured filters to the given contents.
86 /// @param[in] input The contents to wrap with paint's filters.
87 /// @return The filter-wrapped contents. If there are no filters that need
88 /// to be wrapped for the current paint configuration, the
89 /// original contents is returned.
90 std::shared_ptr<Contents> WithFilters(std::shared_ptr<Contents> input) const;
91
92 /// @brief Wrap this paint's configured filters to the given contents of
93 /// subpass target.
94 /// @param[in] input The contents of subpass target to wrap with paint's
95 /// filters.
96 ///
97 /// @return The filter-wrapped contents. If there are no filters that need
98 /// to be wrapped for the current paint configuration, the
99 /// original contents is returned.
100 std::shared_ptr<Contents> WithFiltersForSubpassTarget(
101 std::shared_ptr<Contents> input,
102 const Matrix& effect_transform = Matrix()) const;
103
104 std::shared_ptr<Contents> CreateContentsForGeometry(
105 const std::shared_ptr<Geometry>& geometry) const;
106
107 /// @brief Whether this paint has a color filter that can apply opacity
108 bool HasColorFilter() const;
109
110 std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
111 bool is_solid_color,
112 const Matrix& ctm) const;
113
114 std::shared_ptr<FilterContents> WithImageFilter(
115 const FilterInput::Variant& input,
116 const Matrix& effect_transform,
117 Entity::RenderingMode rendering_mode) const;
118
119 private:
120 std::shared_ptr<Contents> WithColorFilter(
121 std::shared_ptr<Contents> input,
124};
125
126} // namespace impeller
127
128#endif // FLUTTER_IMPELLER_AIKS_PAINT_H_
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
Definition: filter_input.h:37
const Paint & paint
Definition: color_source.cc:38
Join
Definition: path.h:24
float Scalar
Definition: scalar.h:18
Cap
Definition: path.h:18
BlendMode
Definition: color.h:59
SK_API sk_sp< PrecompileColorFilter > Matrix()
static constexpr Color Black()
Definition: color.h:268
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
std::shared_ptr< FilterContents > CreateMaskBlur(std::shared_ptr< ColorSourceContents > color_source_contents, const std::shared_ptr< ColorFilter > &color_filter) const
Definition: paint.cc:155
FilterContents::BlurStyle style
Definition: paint.h:49
ColorSource color_source
Definition: paint.h:69
std::shared_ptr< ColorFilter > GetColorFilter() const
Definition: paint.cc:222
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)> ImageFilterProc
Definition: paint.h:27
bool HasColorFilter() const
Whether this paint has a color filter that can apply opacity.
Definition: paint.cc:236
Cap stroke_cap
Definition: paint.h:72
Join stroke_join
Definition: paint.h:73
Scalar stroke_miter
Definition: paint.h:74
std::function< std::shared_ptr< ColorSourceContents >()> ColorSourceProc
Definition: paint.h:32
std::shared_ptr< Contents > CreateContentsForGeometry(const std::shared_ptr< Geometry > &geometry) const
Definition: paint.cc:30
Style style
Definition: paint.h:75
bool invert_colors
Definition: paint.h:77
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:79
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:36
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:81
Color color
Definition: paint.h:68
BlendMode blend_mode
Definition: paint.h:76
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, bool is_solid_color, const Matrix &effect_transform)> MaskFilterProc
Definition: paint.h:31
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
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
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition: paint.cc:90
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:80
std::shared_ptr< Contents > WithMaskBlur(std::shared_ptr< Contents > input, bool is_solid_color, const Matrix &ctm) const
Definition: paint.cc:80
Scalar stroke_width
Definition: paint.h:71
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32