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