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

Update Color to do all calculations with floating point components #54981

Merged
merged 15 commits into from
Sep 12, 2024

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Sep 5, 2024

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Sep 5, 2024
@gaaclarke gaaclarke changed the title Wide gamut framework breaker Update Color to do all calculations with floating point components Sep 5, 2024
@gaaclarke gaaclarke force-pushed the wide-gamut-framework-breaker branch from 64bd33e to 4880770 Compare September 6, 2024 16:15
gaaclarke added a commit to flutter/flutter that referenced this pull request Sep 10, 2024
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
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Sep 11, 2024
…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'
```
@gaaclarke gaaclarke force-pushed the wide-gamut-framework-breaker branch from a2d1430 to aa290db Compare September 11, 2024 18:02
@@ -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),
Copy link
Member Author

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() =>
Copy link
Member Author

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

Copy link
Member Author

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 ).

@gaaclarke gaaclarke marked this pull request as ready for review September 11, 2024 22:13
@@ -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))"';
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

@jonahwilliams jonahwilliams left a 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);
Copy link
Contributor

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?

Copy link
Member Author

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.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 12, 2024
@auto-submit auto-submit bot merged commit e24aa4d into flutter:main Sep 12, 2024
32 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 12, 2024
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Sep 12, 2024
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 12, 2024
gaaclarke added a commit that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 12, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Sep 12, 2024
…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
gaaclarke added a commit to flutter/website that referenced this pull request Sep 13, 2024
## _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]>
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Sep 16, 2024
…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
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Sep 17, 2024
…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
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Sep 19, 2024
…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
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Sep 23, 2024
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants