Skip to content

Commit 8e95fe4

Browse files
committed
Move color filter absorption to a new method
1 parent a1d91e2 commit 8e95fe4

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

impeller/aiks/canvas.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
330330
Paint rrect_paint = paint;
331331

332332
// Absorb the color filter, if any.
333-
if (rrect_paint.HasColorFilter()) {
334-
rrect_paint.color =
335-
rrect_paint.GetColorFilter()->GetCPUColorFilterProc()(paint.color);
336-
rrect_paint.color_filter = nullptr;
337-
rrect_paint.invert_colors = false;
338-
}
333+
rrect_paint.AbsorbColorFilterIntoColor();
339334

340335
// In some cases, we need to render the mask blur to a separate layer.
341336
//

impeller/aiks/paint.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,20 @@ bool Paint::HasColorFilter() const {
199199
return !!color_filter || invert_colors;
200200
}
201201

202+
void Paint::AbsorbColorFilterIntoColor() {
203+
// This method should only ever be used when the caller knows that the color
204+
// source is a solid color. This is not a valid way to apply the color filter
205+
// for other color sources.
206+
FML_DCHECK(color_source.GetType() == ColorSource::Type::kColor);
207+
208+
std::shared_ptr<ColorFilter> final_color_filter = GetColorFilter();
209+
if (!final_color_filter) {
210+
return; // Nothing to absorb.
211+
}
212+
213+
color = GetColorFilter()->GetCPUColorFilterProc()(color);
214+
color_filter = nullptr;
215+
invert_colors = false;
216+
}
217+
202218
} // namespace impeller

impeller/aiks/paint.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ struct Paint {
104104
std::shared_ptr<Contents> input,
105105
ColorFilterContents::AbsorbOpacity absorb_opacity =
106106
ColorFilterContents::AbsorbOpacity::kNo) const;
107+
108+
/// @brief Absorbs the color filter (if any) into the Paint's color.
109+
/// There are multiple paint attributes that can result in a
110+
/// filter being applied.
111+
/// This is only valid if the color source is set is a solid
112+
/// color.
113+
void AbsorbColorFilterIntoColor();
114+
115+
friend class Canvas;
107116
};
108117

109118
} // namespace impeller

0 commit comments

Comments
 (0)