Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Warn about invalid arguments to ColorFilter.mode #32269

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ class SkMaskFilter {

@JS()
class SkColorFilterNamespace {
external SkColorFilter MakeBlend(Float32List color, SkBlendMode blendMode);
external SkColorFilter? MakeBlend(Float32List color, SkBlendMode blendMode);
external SkColorFilter MakeMatrix(
Float32List matrix, // 20-element matrix
);
Expand Down
6 changes: 5 additions & 1 deletion lib/web_ui/lib/src/engine/canvaskit/color_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ class CkBlendModeColorFilter extends CkColorFilter {

@override
SkColorFilter _initRawColorFilter() {
return canvasKit.ColorFilter.MakeBlend(
final SkColorFilter? filter = canvasKit.ColorFilter.MakeBlend(
toSharedSkColor1(color),
toSkBlendMode(blendMode),
);
if (filter == null) {
throw ArgumentError('Invalid parameters for blend mode ColorFilter');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what combinations of color/blendMode we support? The message would be more helpful if we could give the user more information.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules for which combinations are usable are implemented in https://github.com/google/skia/blob/main/src/core/SkModeColorFilter.cpp#L126

AFAIK Skia does not provide a concise summary of the valid arguments for this function.

}
return filter;
}

@override
Expand Down