| Flutter Impeller |

blend_filter_contents.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_ENTITY_CONTENTS_FILTERS_BLEND_FILTER_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_BLEND_FILTER_CONTENTS_H_
7
8 #include <optional>
9 #include "impeller/entity/contents/filters/color_filter_contents.h"
10 #include "impeller/entity/contents/filters/inputs/filter_input.h"
11 #include "impeller/geometry/color.h"
12
13 namespace impeller {
14
15 constexpr std::array<std::array<Scalar, 5>, 15> kPorterDuffCoefficients = {{
16 {0, 0, 0, 0, 0}, // Clear
17 {1, 0, 0, 0, 0}, // Source
18 {0, 0, 1, 0, 0}, // Destination
19 {1, 0, 1, -1, 0}, // SourceOver
20 {1, -1, 1, 0, 0}, // DestinationOver
21 {0, 1, 0, 0, 0}, // SourceIn
22 {0, 0, 0, 1, 0}, // DestinationIn
23 {1, -1, 0, 0, 0}, // SourceOut
24 {0, 0, 1, -1, 0}, // DestinationOut
25 {0, 1, 1, -1, 0}, // SourceATop
26 {1, -1, 0, 1, 0}, // DestinationATop
27 {1, -1, 1, -1, 0}, // Xor
28 {1, 0, 1, 0, 0}, // Plus
29 {0, 0, 0, 0, 1}, // Modulate
30 {0, 0, 1, 0, -1}, // Screen
31 }};
32
33 std::optional<BlendMode> InvertPorterDuffBlend(BlendMode blend_mode);
34
35 class BlendFilterContents : public ColorFilterContents {
36 public:
37 using AdvancedBlendProc = std::function<std::optional<Entity>(
38 const FilterInput::Vector& inputs,
39 const ContentContext& renderer,
40 const Entity& entity,
41 const Rect& coverage,
42 BlendMode blend_mode,
43 std::optional<Color> foreground_color,
44 ColorFilterContents::AbsorbOpacity absorb_opacity,
45 std::optional<Scalar> alpha)>;
46
47 BlendFilterContents();
48
49 ~BlendFilterContents() override;
50
51 void SetBlendMode(BlendMode blend_mode);
52
53 /// @brief Sets a source color which is blended after all of the inputs have
54 /// been blended.
55 void SetForegroundColor(std::optional<Color> color);
56
57 private:
58 // |FilterContents|
59 std::optional<Entity> RenderFilter(
60 const FilterInput::Vector& inputs,
61 const ContentContext& renderer,
62 const Entity& entity,
63 const Matrix& effect_transform,
64 const Rect& coverage,
65 const std::optional<Rect>& coverage_hint) const override;
66
67 /// @brief Optimized advanced blend that avoids a second subpass when there is
68 /// only a single input and a foreground color.
69 ///
70 /// These contents cannot absorb opacity.
71 std::optional<Entity> CreateForegroundAdvancedBlend(
72 const std::shared_ptr<FilterInput>& input,
73 const ContentContext& renderer,
74 const Entity& entity,
75 const Rect& coverage,
76 Color foreground_color,
77 BlendMode blend_mode,
78 std::optional<Scalar> alpha,
79 ColorFilterContents::AbsorbOpacity absorb_opacity) const;
80
81 /// @brief Optimized porter-duff blend that avoids a second subpass when there
82 /// is only a single input and a foreground color.
83 ///
84 /// These contents cannot absorb opacity.
85 std::optional<Entity> CreateForegroundPorterDuffBlend(
86 const std::shared_ptr<FilterInput>& input,
87 const ContentContext& renderer,
88 const Entity& entity,
89 const Rect& coverage,
90 Color foreground_color,
91 BlendMode blend_mode,
92 std::optional<Scalar> alpha,
93 ColorFilterContents::AbsorbOpacity absorb_opacity) const;
94
95 BlendMode blend_mode_ = BlendMode::kSourceOver;
96 AdvancedBlendProc advanced_blend_proc_;
97 std::optional<Color> foreground_color_;
98
99 BlendFilterContents(const BlendFilterContents&) = delete;
100
101 BlendFilterContents& operator=(const BlendFilterContents&) = delete;
102 };
103
104 } // namespace impeller
105
106 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_BLEND_FILTER_CONTENTS_H_
impeller::BlendFilterContents::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: blend_filter_contents.cc:682
impeller::BlendFilterContents::SetForegroundColor
void SetForegroundColor(std::optional< Color > color)
Sets a source color which is blended after all of the inputs have been blended.
Definition: blend_filter_contents.cc:713
impeller::ColorFilterContents
Definition: color_filter_contents.h:12
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::Color
Definition: color.h:124
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:26
impeller::Entity
Definition: entity.h:21
impeller::kPorterDuffCoefficients
constexpr std::array< std::array< Scalar, 5 >, 15 > kPorterDuffCoefficients
Definition: blend_filter_contents.h:15
impeller::BlendFilterContents::AdvancedBlendProc
std::function< std::optional< Entity >(const FilterInput::Vector &inputs, const ContentContext &renderer, const Entity &entity, const Rect &coverage, BlendMode blend_mode, std::optional< Color > foreground_color, ColorFilterContents::AbsorbOpacity absorb_opacity, std::optional< Scalar > alpha)> AdvancedBlendProc
Definition: blend_filter_contents.h:45
filter_input.h
color_filter_contents.h
impeller::BlendFilterContents::~BlendFilterContents
~BlendFilterContents() override
impeller::BlendFilterContents
Definition: blend_filter_contents.h:35
color.h
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:14
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332
impeller::BlendFilterContents::BlendFilterContents
BlendFilterContents()
Definition: blend_filter_contents.cc:61
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::BlendMode::kSourceOver
@ kSourceOver