Flutter Impeller
color_filter_contents.cc
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 
6 
7 #include <utility>
8 
14 
15 namespace impeller {
16 
17 std::shared_ptr<ColorFilterContents> ColorFilterContents::MakeBlend(
18  BlendMode blend_mode,
19  FilterInput::Vector inputs,
20  std::optional<Color> foreground_color) {
21  if (blend_mode > Entity::kLastAdvancedBlendMode) {
22  VALIDATION_LOG << "Invalid blend mode " << static_cast<int>(blend_mode)
23  << " passed to ColorFilterContents::MakeBlend.";
24  return nullptr;
25  }
26 
27  size_t total_inputs = inputs.size() + (foreground_color.has_value() ? 1 : 0);
28  if (total_inputs < 2 || blend_mode <= Entity::kLastPipelineBlendMode) {
29  auto blend = std::make_shared<BlendFilterContents>();
30  blend->SetInputs(inputs);
31  blend->SetBlendMode(blend_mode);
32  blend->SetForegroundColor(foreground_color);
33  return blend;
34  }
35 
36  auto blend_input = inputs[0];
37  std::shared_ptr<BlendFilterContents> new_blend;
38  for (auto in_i = inputs.begin() + 1; in_i < inputs.end(); in_i++) {
39  new_blend = std::make_shared<BlendFilterContents>();
40  new_blend->SetInputs({blend_input, *in_i});
41  new_blend->SetBlendMode(blend_mode);
42  if (in_i < inputs.end() - 1 || foreground_color.has_value()) {
43  blend_input = FilterInput::Make(
44  std::static_pointer_cast<FilterContents>(new_blend));
45  }
46  }
47 
48  if (foreground_color.has_value()) {
49  new_blend = std::make_shared<BlendFilterContents>();
50  new_blend->SetInputs({blend_input});
51  new_blend->SetBlendMode(blend_mode);
52  new_blend->SetForegroundColor(foreground_color);
53  }
54 
55  return new_blend;
56 }
57 
58 std::shared_ptr<ColorFilterContents> ColorFilterContents::MakeColorMatrix(
59  FilterInput::Ref input,
60  const ColorMatrix& color_matrix) {
61  auto filter = std::make_shared<ColorMatrixFilterContents>();
62  filter->SetInputs({std::move(input)});
63  filter->SetMatrix(color_matrix);
64  return filter;
65 }
66 
67 std::shared_ptr<ColorFilterContents>
69  auto filter = std::make_shared<LinearToSrgbFilterContents>();
70  filter->SetInputs({std::move(input)});
71  return filter;
72 }
73 
74 std::shared_ptr<ColorFilterContents>
76  auto filter = std::make_shared<SrgbToLinearFilterContents>();
77  filter->SetInputs({std::move(input)});
78  return filter;
79 }
80 
82 
84 
86  absorb_opacity_ = absorb_opacity;
87 }
88 
90  const {
91  return absorb_opacity_;
92 }
93 
95  alpha_ = alpha;
96 }
97 
98 std::optional<Scalar> ColorFilterContents::GetAlpha() const {
99  return alpha_.value_or(1.0) * inherited_opacity_;
100 }
101 
103  inherited_opacity_ = opacity;
104 }
105 
107  const Matrix& effect_transform,
108  const Rect& output_limit) const {
109  return output_limit;
110 }
111 
112 } // namespace impeller
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
std::optional< Scalar > GetAlpha() const
static std::shared_ptr< ColorFilterContents > MakeColorMatrix(FilterInput::Ref input, const ColorMatrix &color_matrix)
static std::shared_ptr< ColorFilterContents > MakeSrgbToLinearFilter(FilterInput::Ref input)
void SetAbsorbOpacity(AbsorbOpacity absorb_opacity)
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
AbsorbOpacity GetAbsorbOpacity() const
void SetAlpha(Scalar alpha)
Sets an alpha that is applied to the final blended result.
static std::shared_ptr< ColorFilterContents > MakeLinearToSrgbFilter(FilterInput::Ref input)
static std::shared_ptr< ColorFilterContents > MakeBlend(BlendMode blend_mode, FilterInput::Vector inputs, std::optional< Color > foreground_color=std::nullopt)
the [inputs] are expected to be in the order of dst, src.
static constexpr BlendMode kLastAdvancedBlendMode
Definition: entity.h:29
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:28
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
float Scalar
Definition: scalar.h:19
BlendMode
Definition: color.h:58
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
#define VALIDATION_LOG
Definition: validation.h:91