Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
15namespace impeller {
16
17std::shared_ptr<ColorFilterContents> ColorFilterContents::MakeBlend(
18 BlendMode blend_mode,
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
58std::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
67std::shared_ptr<ColorFilterContents>
69 auto filter = std::make_shared<LinearToSrgbFilterContents>();
70 filter->SetInputs({std::move(input)});
71 return filter;
72}
73
74std::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
93
95 alpha_ = alpha;
96}
97
98std::optional<Scalar> ColorFilterContents::GetAlpha() const {
99 return alpha_;
100}
101
103 const Matrix& effect_transform,
104 const Rect& output_limit) const {
105 return output_limit;
106}
107
108} // namespace impeller
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...
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:24
static constexpr BlendMode kLastPipelineBlendMode
Definition entity.h:23
std::shared_ptr< FilterInput > Ref
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
std::vector< FilterInput::Ref > Vector
static SkColor blend(SkColor dst, SkColor src, void(*mode)(float, float, float, float *, float *, float *))
Definition hsl.cpp:142
float Scalar
Definition scalar.h:18
BlendMode
Definition color.h:59
A 4x4 matrix using column-major storage.
Definition matrix.h:37
#define VALIDATION_LOG
Definition validation.h:73