-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to invert paint colors to be used for smart invert accessibility on iOS #6176
Changes from all commits
9e340b7
d4a2707
1b374e7
5263e0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ constexpr int kColorFilterBlendModeIndex = 11; | |
constexpr int kMaskFilterIndex = 12; | ||
constexpr int kMaskFilterBlurStyleIndex = 13; | ||
constexpr int kMaskFilterSigmaIndex = 14; | ||
constexpr int kInvertColorIndex = 15; | ||
constexpr size_t kDataByteCount = 75; // 4 * (last index + 1) | ||
|
||
// Indices for objects. | ||
|
@@ -47,6 +48,16 @@ constexpr uint32_t kBlendModeDefault = | |
// default SkPaintDefaults_MiterLimit in Skia (which is not in a public header). | ||
constexpr double kStrokeMiterLimitDefault = 4.0; | ||
|
||
// A color matrix which inverts colors. | ||
// clang-format off | ||
constexpr SkScalar invert_colors[20] = { | ||
-1.0, 0, 0, 1.0, 0, | ||
0, -1.0, 0, 1.0, 0, | ||
0, 0, -1.0, 1.0, 0, | ||
1.0, 1.0, 1.0, 1.0, 0 | ||
}; | ||
// clang-format on | ||
|
||
// Must be kept in sync with the MaskFilter private constants in painting.dart. | ||
enum MaskFilterType { Null, Blur }; | ||
|
||
|
@@ -116,7 +127,19 @@ Paint::Paint(Dart_Handle paint_objects, Dart_Handle paint_data) { | |
if (filter_quality) | ||
paint_.setFilterQuality(static_cast<SkFilterQuality>(filter_quality)); | ||
|
||
if (uint_data[kColorFilterIndex]) { | ||
if (uint_data[kColorFilterIndex] && uint_data[kInvertColorIndex]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we have unit tests or golden tests in flutter/flutter that exercise the two new branches that you added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't but I can add some, like solid paint with invert applied, solid paint with invert and color filter applied. That should cover this branch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the existing set of golden tests should cover everything, and then when I map the invert color flag to the accessibility setting after rolling the engine I can add special test cases? I'm not sure of another way I could write the tests for this |
||
SkColor color = uint_data[kColorFilterColorIndex]; | ||
SkBlendMode blend_mode = | ||
static_cast<SkBlendMode>(uint_data[kColorFilterBlendModeIndex]); | ||
sk_sp<SkColorFilter> color_filter = | ||
SkColorFilter::MakeModeFilter(color, blend_mode); | ||
sk_sp<SkColorFilter> invert_filter = | ||
SkColorFilter::MakeMatrixFilterRowMajor255(invert_colors); | ||
paint_.setColorFilter(invert_filter->makeComposed(color_filter)); | ||
} else if (uint_data[kInvertColorIndex]) { | ||
paint_.setColorFilter( | ||
SkColorFilter::MakeMatrixFilterRowMajor255(invert_colors)); | ||
} else if (uint_data[kColorFilterIndex]) { | ||
SkColor color = uint_data[kColorFilterColorIndex]; | ||
SkBlendMode blend_mode = | ||
static_cast<SkBlendMode>(uint_data[kColorFilterBlendModeIndex]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @Hixie - this calculation seems to be a bit off