Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dl_color_filter.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
5#include "flutter/display_list/effects/dl_color_filter.h"
6
7#include "flutter/display_list/dl_color.h"
8
9namespace flutter {
10
11std::shared_ptr<DlColorFilter> DlBlendColorFilter::Make(DlColor color,
13 switch (mode) {
14 case DlBlendMode::kDst: {
15 return nullptr;
16 }
18 if (color.isTransparent()) {
19 return nullptr;
20 }
21 if (color.isOpaque()) {
23 }
24 break;
25 }
31 if (color.isTransparent()) {
32 return nullptr;
33 }
34 break;
35 }
37 if (color.isOpaque()) {
38 return nullptr;
39 }
40 break;
41 }
42 default:
43 break;
44 }
45 return std::make_shared<DlBlendColorFilter>(color, mode);
46}
47
49 switch (mode_) {
50 // These modes all act like kSrc when the dest is all 0s.
51 // So they modify transparent black when the src color is
52 // not transparent.
75 return !color_.isTransparent();
76
77 // These modes are all like kDst when the dest is all 0s.
78 // So they never modify transparent black.
86 return false;
87 }
88}
89
126
127std::shared_ptr<DlColorFilter> DlMatrixColorFilter::Make(
128 const float matrix[20]) {
129 float product = 0;
130 for (int i = 0; i < 20; i++) {
131 product *= matrix[i];
132 }
133 // If any of the elements of the matrix are infinity or NaN, then
134 // |product| will be NaN, otherwise 0.
135 if (product == 0) {
136 return std::make_shared<DlMatrixColorFilter>(matrix);
137 }
138 return nullptr;
139}
140
142 // Values are considered in non-premultiplied form when the matrix is
143 // applied, but we only care about this answer for whether it leaves
144 // an incoming color with a transparent alpha as transparent on output.
145 // Thus, we only need to consider the alpha part of the matrix equation,
146 // which is the last row. Since the incoming alpha value is 0, the last
147 // equation ends up becoming A' = matrix_[19]. Negative results will be
148 // clamped to the range [0,1] so we only care about positive values.
149 // Non-finite values are clamped to a zero alpha.
150 return (std::isfinite(matrix_[19]) && matrix_[19] > 0);
151}
152
154 // We need to check if:
155 // filter(color) * opacity == filter(color * opacity).
156 //
157 // filter(RGBA) = R' = [ R*m[ 0] + G*m[ 1] + B*m[ 2] + A*m[ 3] + m[ 4] ]
158 // G' = [ R*m[ 5] + G*m[ 6] + B*m[ 7] + A*m[ 8] + m[ 9] ]
159 // B' = [ R*m[10] + G*m[11] + B*m[12] + A*m[13] + m[14] ]
160 // A' = [ R*m[15] + G*m[16] + B*m[17] + A*m[18] + m[19] ]
161 //
162 // Applying the opacity only affects the alpha value since the operations
163 // are performed on non-premultiplied colors. (If the data is stored in
164 // premultiplied form, though, there may be rounding errors due to
165 // premul->unpremul->premul conversions.)
166
167 // We test for the successful cases and return false if they fail so that
168 // we fail and return false if any matrix values are NaN.
169
170 // If any of the alpha column are non-zero then the prior alpha affects
171 // the result color, so applying opacity before the filter will change
172 // the incoming alpha and therefore the colors that are produced.
173 if (!(matrix_[3] == 0 && // A does not affect R'
174 matrix_[8] == 0 && // A does not affect G'
175 matrix_[13] == 0)) { // A does not affect B'
176 return false;
177 }
178
179 // Similarly, if any of the alpha row are non-zero then the prior colors
180 // affect the result alpha in a way that prevents opacity from commuting
181 // through the filter operation.
182 if (!(matrix_[15] == 0 && // R does not affect A'
183 matrix_[16] == 0 && // G does not affect A'
184 matrix_[17] == 0 && // B does not affect A'
185 matrix_[19] == 0)) { // A' is not offset by an absolute value
186 return false;
187 }
188
189 return true;
190}
191
192const std::shared_ptr<DlSrgbToLinearGammaColorFilter>
194 std::make_shared<DlSrgbToLinearGammaColorFilter>();
195
196const std::shared_ptr<DlLinearToSrgbGammaColorFilter>
198 std::make_shared<DlLinearToSrgbGammaColorFilter>();
199
200} // namespace flutter
SkColor4f color
static std::shared_ptr< DlColorFilter > Make(DlColor color, DlBlendMode mode)
bool can_commute_with_opacity() const override
bool modifies_transparent_black() const override
static const std::shared_ptr< DlLinearToSrgbGammaColorFilter > kInstance
static std::shared_ptr< DlColorFilter > Make(const float matrix[20])
bool can_commute_with_opacity() const override
bool modifies_transparent_black() const override
static const std::shared_ptr< DlSrgbToLinearGammaColorFilter > kInstance
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228
@ kSrcOut
r = s * (1-da)
@ kExclusion
rc = s + d - two(s*d), ra = kSrcOver
@ kSaturation
saturation of source with hue and luminosity of destination
@ kColorBurn
darken destination to reflect source
@ kPlus
r = min(s + d, 1)
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kHue
hue of source with saturation and luminosity of destination
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kColorDodge
brighten destination to reflect source
@ kScreen
r = s + d - s*d
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kLuminosity
luminosity of source with hue and saturation of destination
@ kSoftLight
lighten or darken, depending on source
@ kDifference
rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
@ kOverlay
multiply or screen, depending on destination
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstATop
r = d*sa + s*(1-da)
@ kDstOver
r = d + (1-da)*s
@ kColor
hue and saturation of source with luminosity of destination
@ kHardLight
multiply or screen, depending on source
@ kDstOut
r = d * (1-sa)
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
constexpr bool isTransparent() const
Definition dl_color.h:36
constexpr bool isOpaque() const
Definition dl_color.h:35