| 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 BlendMode blend_mode_ = BlendMode::kSourceOver;
82 AdvancedBlendProc advanced_blend_proc_;
83 std::optional<Color> foreground_color_;
84
85 BlendFilterContents(const BlendFilterContents&) = delete;
86
87 BlendFilterContents& operator=(const BlendFilterContents&) = delete;
88 };
89
90 } // namespace impeller
91
92 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_FILTERS_BLEND_FILTER_CONTENTS_H_
impeller::BlendFilterContents::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: blend_filter_contents.cc:562
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:593
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_blur_unittests.cc:20
impeller::ContentContext
Definition: content_context.h:392
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