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

Changes DlColor to support wide gamut colors (#54473) #54648

Merged
merged 5 commits into from
Aug 20, 2024

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Aug 20, 2024

relands #54473
issue: flutter/flutter#127855
integration test: #54415

This is the engine side changes required for wide gamut framework support. It changes the internal representation of DlColor to be floats. It will be married with #54415 when it lands in #54567.

Difference from last attempt

  1. The default color is now opaque black, not transparent black (not the issue for revert)
  2. Updated a test to send in valid numbers when constructing a color and added asserts to avoid those problems in the future.

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.

issue: flutter/flutter#127855
integration test: flutter#54415

This is the engine side changes required for wide gamut framework support.  It changes the internal representation of DlColor to be floats.  It will be married with flutter#54415 when it lands in flutter#54567.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
@gaaclarke gaaclarke marked this pull request as ready for review August 20, 2024 18:09
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #54648 at sha 65d4573

@jonahwilliams
Copy link
Member

impeller_Play_AiksTest_BlendModeSrcAlphaColorBurn_Metal still looks very wrong.

Copy link
Contributor

@flar flar left a comment

Choose a reason for hiding this comment

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

Looks good, but I had a question about clamping vs dcheck...

color_space_(colorspace) {}
color_space_(colorspace) {
FML_DCHECK(alpha >= 0.0);
FML_DCHECK(alpha <= 1.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we dcheck or clamp? This is currently, in this PR, helping to catch a problem in a test conversion that we crossed paths with, but that bug-in-a-test would have normally been caught by the test creator. If we dcheck then we might annoy someone who calculated the alpha and ended up with a barely-out-of-range value. They could just have easily have provided 255 for one of the color values and we'd take it as a potential non-normalized Color Space float...?

Copy link
Member

Choose a reason for hiding this comment

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

Rather than dcheck I think we should clamp right? Certain blend modes (plus) can lead to alpha greater than one without a clamp

Copy link
Member Author

Choose a reason for hiding this comment

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

Rather than dcheck I think we should clamp right? Certain blend modes (plus) can lead to alpha greater than one without a clamp

My concern with that is that it will mask problems like we had where someone is sending in 255 to create a color. The assert forces people creating colors to have a clamp if they are doing arithmetic that will get it out of bounds. I didn't have to change any code as a result of all our tests, so that's a good sign. I think this leaves us in a better position considering we control all the locations where DlColors are created. A public API would be a different story.

Copy link
Member

Choose a reason for hiding this comment

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

You should clamp.

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 removed the asserts to duplicate the behavior of impeller::Color. There may be transitory colors that are not valid, clamping or the asserts could mess with that. I don't think we blend with DlColor today, it's more of a transmission format, but I think we plan to use it more broadly in the future.

Copy link
Member

Choose a reason for hiding this comment

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

We will be CPU blending once we merge DlColor and impeller::Color. This will happen sooner than you'd think

@gaaclarke
Copy link
Member Author

impeller_Play_AiksTest_BlendModeSrcAlphaColorBurn_Metal still looks very wrong.

@jonahwilliams very wrong? The only thing I'm seeing is the checkerboard looks more that 1/255th brighter. I can dig into those colors to see if this is expected. Different colors will be expected since we were converting floats to uint8 before. We don't want to duplicate that behavior.

before

2519aa83a4ef18e4a09a29c8f923d791

after

74b7fb09b0fef9971d23e90935dff8e1

@jonahwilliams
Copy link
Member

image

@gaaclarke
Copy link
Member Author

Here are the before and after colors for SolidColorContents 0.000630527 0.000630527 0.000630527 0.00392157 is very different from 0.160784 0.160784 0.160784 1. Looks like maybe a number getting normalized twice? That's definitely beyond the range of what we'd expect.

before

[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.74902 0.74902 0.74902 0.74902 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.146867 0.602153 0.146867 0.74902 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0 0 0 0.74902 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.481492 0.624837 0.885798 0.937255 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.110265 0.532949 0.569704 0.937255 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0735102 0.110265 0.172749 0.937255 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.000630527 0.000630527 0.000630527 0.00392157 
2500
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0588235 0.0588235 0.0588235 1 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.74902 0.74902 0.74902 0.74902 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.146867 0.602153 0.146867 0.74902 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0 0 0 0.74902 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.481492 0.624837 0.885798 0.937255 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.110265 0.532949 0.569704 0.937255 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0735102 0.110265 0.172749 0.937255 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.000630527 0.000630527 0.000630527 0.00392157 
2500
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0588235 0.0588235 0.0588235 1 

after

[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.75 0.75 0.75 0.75 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.147059 0.602941 0.147059 0.75 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0 0 0 0.75 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.481618 0.625735 0.884559 0.9375 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.110294 0.53194 0.571029 0.9375 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0735294 0.109559 0.174265 0.9375 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.160784 0.160784 0.160784 1 
2500
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0588235 0.0588235 0.0588235 1 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.75 0.75 0.75 0.75 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.147059 0.602941 0.147059 0.75 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0 0 0 0.75 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.481618 0.625735 0.884559 0.9375 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.110294 0.53194 0.571029 0.9375 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0735294 0.109559 0.174265 0.9375 
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.160784 0.160784 0.160784 1 
2500
[ERROR:flutter/impeller/entity/contents/solid_color_contents.cc(60)] 0.0588235 0.0588235 0.0588235 1 

@jonahwilliams
Copy link
Member

It looks like the grid moved? or changed colors.

@gaaclarke
Copy link
Member Author

gaaclarke commented Aug 20, 2024

It looks like the grid moved? or changed colors.

@jonahwilliams oh, yea this was a bug with the old code. This is coming from the same colors defined in

paint.setColor(DlColor::RGBA(41 / 255.0, 41 / 255.0, 41 / 255.0, 255));
.

Notice that the old colors would be drawn as ((41/255)/255). Now they are drawn as 41/255. Looking at the test, the intention was actually to draw 41/255.

@jonahwilliams
Copy link
Member

ack ack!

@gaaclarke gaaclarke requested a review from flar August 20, 2024 20:32
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

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #54648 at sha db4f334

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 20, 2024
Copy link
Contributor

@flar flar left a comment

Choose a reason for hiding this comment

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

LGTM

@auto-submit auto-submit bot merged commit d52fe13 into flutter:main Aug 20, 2024
34 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 20, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 21, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 21, 2024
…153804)

flutter/engine@3d18f65...5cbf96d

2024-08-20 [email protected] Roll Dart SDK from 04c57423f90d to 49f655b526c7 (2 revisions) (flutter/engine#54660)
2024-08-20 [email protected] Roll Skia from b472cacb48d6 to 51d7e221fef0 (2 revisions) (flutter/engine#54656)
2024-08-20 [email protected] Changes DlColor to support wide gamut colors (#54473) (flutter/engine#54648)

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
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…lutter#153804)

flutter/engine@3d18f65...5cbf96d

2024-08-20 [email protected] Roll Dart SDK from 04c57423f90d to 49f655b526c7 (2 revisions) (flutter/engine#54660)
2024-08-20 [email protected] Roll Skia from b472cacb48d6 to 51d7e221fef0 (2 revisions) (flutter/engine#54656)
2024-08-20 [email protected] Changes DlColor to support wide gamut colors (flutter#54473) (flutter/engine#54648)

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
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 e: impeller will affect goldens
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants