-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Update Color to do all calculations with floating point components #54981
Update Color to do all calculations with floating point components #54981
Conversation
64bd33e
to
4880770
Compare
issue: #127855 This is a forward fix to help flutter/engine#54981 land. It makes the following changes: 1) Removes hardcoded `Color.toString()` assumptions in asserts 1) Switches some lerp tests to use numbers that are more friendly to uint8_t and floating point numbers 1) implements custom matchers for color 1) removes word wrapping for some asserts since it makes them fragile to changes in `Color.toString()` invocations ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…54934) This migrates the last failing test for flutter/engine#54981. In order to effectively resolve that test I had to make `equalsIgnoringHashCodes` more usable by printing out the line that differs instead of just a huge blob of "expected" vs "actual. ## example Here's the output after the change. ### test ``` test('equalsIgnoringHashCodes - wrong line', () { expect( '1\n2\n3\n4\n5\n6\n7\n8\n9\n10', equalsIgnoringHashCodes('1\n2\n3\n4\n5\n6\na\n8\n9\n10'), ); }); ``` ### output ``` Expected: normalized value matches '1\n' '2\n' '3\n' '4\n' '5\n' '6\n' 'a\n' '8\n' '9\n' '10' Actual: '1\n' '2\n' '3\n' '4\n' '5\n' '6\n' '7\n' '8\n' '9\n' '10' Which: Lines 7 differed, expected: 'a' but got '7' ```
a2d1430
to
aa290db
Compare
@@ -121,22 +121,22 @@ Future<void> testMain() async { | |||
|
|||
test('color filter as image filter', () async { | |||
const ui.ColorFilter colorFilter = ui.ColorFilter.mode( | |||
ui.Color.fromRGBO(0, 0, 255, 128), | |||
ui.Color.fromARGB(128, 0, 0, 255), |
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.
This test was incorrectly using the fromRGBO
method, so I fixed it. The opacity component was supposed to be in [0,1.0].
@override | ||
String toString() => 'Color(0x${value.toRadixString(16).padLeft(8, '0')})'; | ||
String toString() => |
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.
4 sig figs was chosen since hdmi 1.3 can support 12 bits per color component and 1/2^12 = 0.00024
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.
Scientific notation could have been another option if we wanted ( 2.4e-4 ).
@@ -60,7 +60,8 @@ void main() { | |||
])); | |||
final runResult = io.Process.runSync(dart, <String>[regularDill]); | |||
checkProcessResult(runResult); | |||
var paintString = '"Paint.toString":"Paint(Color(0xffffffff))"'; | |||
var paintString = | |||
'"Paint.toString":"Paint(Color(alpha: 1.0000, red: 1.0000, green: 1.0000, blue: 1.0000, colorSpace: ColorSpace.sRGB))"'; |
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.
typically I'd call Color.toString()
here but I'm unable to import dart:ui
here for some reason.
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.
This is a VM test, so that is why.
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.
But it's weird that I'm asserting behavior for dart:ui
, so it's there, it's just not visible to me.
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.
Its basically a compiler test though
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.
LGTM
final double R = _linearizeColorComponent(red / 0xFF); | ||
final double G = _linearizeColorComponent(green / 0xFF); | ||
final double B = _linearizeColorComponent(blue / 0xFF); | ||
final double R = _linearizeColorComponent(r); |
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.
Now that we have colorspaces, should these be taught to clamp or convert to a non-extended CS as well?
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.
I added an assert that extended srgb is in't used. I don't think it will make sense with that.
…nents" (#55153) Reverts #54981 This is causing failures in customer tests that need to be updated: https://github.com/flutter/flutter/pull/155107/checks?check_run_id=30069840819
…155128) flutter/engine@48ddaf5...8609af6 2024-09-12 [email protected] Revert "Update Color to do all calculations with floating point components" (flutter/engine#55153) 2024-09-12 [email protected] Migrate more tests from `litetest` to `package:test` (flutter/engine#55119) 2024-09-12 [email protected] Roll Skia from acff7f24ddbe to 26b048c6a53b (1 revision) (flutter/engine#55151) 2024-09-12 [email protected] Roll Dart SDK from a438066d634f to aa27c61f5859 (8 revisions) (flutter/engine#55147) 2024-09-12 [email protected] Update Skia build for Vulkan headers (flutter/engine#55143) 2024-09-12 [email protected] Roll Skia from 2b40b50ea423 to acff7f24ddbe (1 revision) (flutter/engine#55144) 2024-09-12 [email protected] Update Color to do all calculations with floating point components (flutter/engine#54981) 2024-09-12 [email protected] Roll Fuchsia Linux SDK from fKNT8lbGh8JzxjE6m... to 3YH1DEYJ-s93fHBw5... (flutter/engine#55142) 2024-09-12 [email protected] Migrate `const_finder_test` to use `package:test` (flutter/engine#55132) 2024-09-12 [email protected] [engine] make UI thread the platform thread for Android. Still allows opt out as g3 escape hatch. (flutter/engine#55111) 2024-09-12 [email protected] Roll Skia from b750cbedc114 to 2b40b50ea423 (1 revision) (flutter/engine#55141) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from fKNT8lbGh8Jz to 3YH1DEYJ-s93 If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
## _Description of what this PR is changing or adding, and why:_ Adding more details about the changing of Color equality. ## _Issues fixed by this PR (if any):_ flutter/flutter#127855 ## _PRs or commits this PR depends on (if any):_ flutter/engine#54981 ## Presubmit checklist - [x] This PR is marked as draft with an explanation if not meant to land until a future stable release. - [x] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: Shams Zakhour (ignore Sfshaza) <[email protected]>
…lutter#54981) This transforms the rest of Color to use the floating point parameters. This will likely break existing tests very subtly. For example, colors will be slightly different in golden tests if `lerp` was ever used. issue: flutter/flutter#127855 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…lutter#54981) This transforms the rest of Color to use the floating point parameters. This will likely break existing tests very subtly. For example, colors will be slightly different in golden tests if `lerp` was ever used. issue: flutter/flutter#127855 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…lutter#54981) This transforms the rest of Color to use the floating point parameters. This will likely break existing tests very subtly. For example, colors will be slightly different in golden tests if `lerp` was ever used. issue: flutter/flutter#127855 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…lutter#54981) This transforms the rest of Color to use the floating point parameters. This will likely break existing tests very subtly. For example, colors will be slightly different in golden tests if `lerp` was ever used. issue: flutter/flutter#127855 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Note: this is expected to create slight golden diff changes
This transforms the rest of Color to use the floating point parameters. This will likely break existing tests very subtly. For example, colors will be slightly different in golden tests if
lerp
was ever used.issue: flutter/flutter#127855
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.