Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move color filter absorption to a new method
  • Loading branch information
bdero committed Mar 8, 2024
commit 8e95fe4ccb11271f06f177763cf4658124f3ee46
7 changes: 1 addition & 6 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
Paint rrect_paint = paint;

// Absorb the color filter, if any.
if (rrect_paint.HasColorFilter()) {
rrect_paint.color =
rrect_paint.GetColorFilter()->GetCPUColorFilterProc()(paint.color);
rrect_paint.color_filter = nullptr;
rrect_paint.invert_colors = false;
}
rrect_paint.AbsorbColorFilterIntoColor();

// In some cases, we need to render the mask blur to a separate layer.
//
Expand Down
16 changes: 16 additions & 0 deletions impeller/aiks/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,20 @@ bool Paint::HasColorFilter() const {
return !!color_filter || invert_colors;
}

void Paint::AbsorbColorFilterIntoColor() {
// This method should only ever be used when the caller knows that the color
// source is a solid color. This is not a valid way to apply the color filter
// for other color sources.
FML_DCHECK(color_source.GetType() == ColorSource::Type::kColor);

std::shared_ptr<ColorFilter> final_color_filter = GetColorFilter();
if (!final_color_filter) {
return; // Nothing to absorb.
}

color = GetColorFilter()->GetCPUColorFilterProc()(color);
color_filter = nullptr;
invert_colors = false;
}

} // namespace impeller
9 changes: 9 additions & 0 deletions impeller/aiks/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ struct Paint {
std::shared_ptr<Contents> input,
ColorFilterContents::AbsorbOpacity absorb_opacity =
ColorFilterContents::AbsorbOpacity::kNo) const;

/// @brief Absorbs the color filter (if any) into the Paint's color.
/// There are multiple paint attributes that can result in a
/// filter being applied.
/// This is only valid if the color source is set is a solid
/// color.
void AbsorbColorFilterIntoColor();

friend class Canvas;
};

} // namespace impeller
Expand Down