Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
flutter::DlMatrixColorFilter Class Referencefinal

#include <dl_color_filter.h>

Inheritance diagram for flutter::DlMatrixColorFilter:
flutter::DlColorFilter flutter::DlAttribute< DlColorFilter, DlColorFilterType >

Public Member Functions

 DlMatrixColorFilter (const float matrix[20])
 
 DlMatrixColorFilter (const DlMatrixColorFilter &filter)
 
 DlMatrixColorFilter (const DlMatrixColorFilter *filter)
 
DlColorFilterType type () const override
 
size_t size () const override
 
bool modifies_transparent_black () const override
 
bool can_commute_with_opacity () const override
 
std::shared_ptr< DlColorFiltershared () const override
 
const DlMatrixColorFilterasMatrix () const override
 
const float & operator[] (int index) const
 
void get_matrix (float matrix[20]) const
 
- Public Member Functions inherited from flutter::DlColorFilter
virtual const DlBlendColorFilterasBlend () const
 
- Public Member Functions inherited from flutter::DlAttribute< DlColorFilter, DlColorFilterType >
bool operator== (DlColorFilter const &other) const
 
bool operator!= (DlColorFilter const &other) const
 
virtual ~DlAttribute ()=default
 

Static Public Member Functions

static std::shared_ptr< DlColorFilterMake (const float matrix[20])
 

Protected Member Functions

bool equals_ (const DlColorFilter &other) const override
 

Detailed Description

Definition at line 114 of file dl_color_filter.h.

Constructor & Destructor Documentation

◆ DlMatrixColorFilter() [1/3]

flutter::DlMatrixColorFilter::DlMatrixColorFilter ( const float  matrix[20])
inlineexplicit

Definition at line 116 of file dl_color_filter.h.

116 {
117 memcpy(matrix_, matrix, sizeof(matrix_));
118 }

◆ DlMatrixColorFilter() [2/3]

flutter::DlMatrixColorFilter::DlMatrixColorFilter ( const DlMatrixColorFilter filter)
inline

Definition at line 119 of file dl_color_filter.h.

120 : DlMatrixColorFilter(filter.matrix_) {}
DlMatrixColorFilter(const float matrix[20])

◆ DlMatrixColorFilter() [3/3]

flutter::DlMatrixColorFilter::DlMatrixColorFilter ( const DlMatrixColorFilter filter)
inlineexplicit

Definition at line 121 of file dl_color_filter.h.

122 : DlMatrixColorFilter(filter->matrix_) {}

Member Function Documentation

◆ asMatrix()

const DlMatrixColorFilter * flutter::DlMatrixColorFilter::asMatrix ( ) const
inlineoverridevirtual

Reimplemented from flutter::DlColorFilter.

Definition at line 136 of file dl_color_filter.h.

136{ return this; }

◆ can_commute_with_opacity()

bool flutter::DlMatrixColorFilter::can_commute_with_opacity ( ) const
overridevirtual

Reimplemented from flutter::DlColorFilter.

Definition at line 153 of file dl_color_filter.cc.

153 {
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}

◆ equals_()

bool flutter::DlMatrixColorFilter::equals_ ( const DlColorFilter other) const
inlineoverrideprotectedvirtual

Implements flutter::DlAttribute< DlColorFilter, DlColorFilterType >.

Definition at line 144 of file dl_color_filter.h.

144 {
145 FML_DCHECK(other.type() == DlColorFilterType::kMatrix);
146 auto that = static_cast<DlMatrixColorFilter const*>(&other);
147 return memcmp(matrix_, that->matrix_, sizeof(matrix_)) == 0;
148 }
#define FML_DCHECK(condition)
Definition logging.h:103

◆ get_matrix()

void flutter::DlMatrixColorFilter::get_matrix ( float  matrix[20]) const
inline

Definition at line 139 of file dl_color_filter.h.

139 {
140 memcpy(matrix, matrix_, sizeof(matrix_));
141 }

◆ Make()

std::shared_ptr< DlColorFilter > flutter::DlMatrixColorFilter::Make ( const float  matrix[20])
static

Definition at line 127 of file dl_color_filter.cc.

128 {
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}
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ modifies_transparent_black()

bool flutter::DlMatrixColorFilter::modifies_transparent_black ( ) const
overridevirtual

Implements flutter::DlColorFilter.

Definition at line 141 of file dl_color_filter.cc.

141 {
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}

◆ operator[]()

const float & flutter::DlMatrixColorFilter::operator[] ( int  index) const
inline

Definition at line 138 of file dl_color_filter.h.

138{ return matrix_[index]; }

◆ shared()

std::shared_ptr< DlColorFilter > flutter::DlMatrixColorFilter::shared ( ) const
inlineoverridevirtual

Implements flutter::DlAttribute< DlColorFilter, DlColorFilterType >.

Definition at line 132 of file dl_color_filter.h.

132 {
133 return std::make_shared<DlMatrixColorFilter>(this);
134 }

◆ size()

size_t flutter::DlMatrixColorFilter::size ( ) const
inlineoverridevirtual

Implements flutter::DlAttribute< DlColorFilter, DlColorFilterType >.

Definition at line 127 of file dl_color_filter.h.

127{ return sizeof(*this); }

◆ type()

DlColorFilterType flutter::DlMatrixColorFilter::type ( ) const
inlineoverridevirtual

The documentation for this class was generated from the following files: