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

[Impeller] Match Skia gradient clamping behavior (and document). #44825

Merged
merged 6 commits into from
Sep 27, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Aug 17, 2023

Skia clamps any gradient stops to values of 0.0 to 1.0. Implement this behavior in Impeller and document it in dart:ui (Framework also needs to be documented). This also matches the w3c gradient behavior: https://www.w3.org/TR/2000/CR-SVG-20000802/pservers.html - almost. We might be slightly off with how we're inserting additional stops for 0.0 and 1.0, but at least its closer.

Fixes flutter/flutter#132792

/// * Clamp all gradient values between the values of 0.0 and 1.0.
/// * For all stop values, ensure that the values are monotonically increasing
/// by clamping each value to a minimum of the previous stop value and itself.
/// For example, with stop values of 0.0, 0.5, 0.4, 1.0, we would clamp such
Copy link
Member

Choose a reason for hiding this comment

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

This bit is surprising to me. I would have expected it to be sorted but this works too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Still WIP and confirming :)

Copy link
Contributor

Choose a reason for hiding this comment

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

What did you end up finding out here?

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 found the w3c notes which basically confirm this behavior is approximately correct

@chinmaygarde chinmaygarde changed the title [Impeller] match Skia gradient clamping behavior (and document) [Impeller] Mmatch Skia gradient clamping behavior (and document). Aug 21, 2023
@chinmaygarde chinmaygarde changed the title [Impeller] Mmatch Skia gradient clamping behavior (and document). [Impeller] Match Skia gradient clamping behavior (and document). Aug 22, 2023
@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Aug 22, 2023
@jonahwilliams jonahwilliams marked this pull request as ready for review September 27, 2023 16:51
@jonahwilliams jonahwilliams removed the Work in progress (WIP) Not ready (yet) for review! label Sep 27, 2023
@jonahwilliams
Copy link
Member Author

Okay, I think this is approximately correct. Would appreciate criticism of the additional docstring I've put in dart:ui in particular.

@@ -4233,7 +4237,11 @@ base class Gradient extends Shader {
/// If `colorStops` is provided, `colorStops[i]` is a number from 0.0 to 1.0
/// that specifies where `color[i]` begins in the gradient. If `colorStops` is
/// not provided, then only two stops, at 0.0 and 1.0, are implied (and
/// `color` must therefore only have two entries).
/// `color` must therefore only have two entries). Stop values less than 0.0
Copy link
Member

Choose a reason for hiding this comment

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

The docstring in the C++ header indicates that the second color is optional and the first will be repeated. Perhaps add that here too. Unless the framework has additional checks in place.

Copy link
Member Author

Choose a reason for hiding this comment

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

That isn't a valid gradient according to our docs, but w3c says this should degrade to a solid color fill. I'd rather punt on this behavior.

Copy link
Member

Choose a reason for hiding this comment

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

👍🏽

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

LGTM assuming the tests are cleaned up a bit, everything else looks good!

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach generally and the docstring LGTM!

One question though, does that mean we could enforce (with DCHECKs?) deeper in the stack that stops/colors are valid?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does not, because we've never enforced this so adding more enforcement is breaking.

/// * Clamp all gradient values between the values of 0.0 and 1.0.
/// * For all stop values, ensure that the values are monotonically increasing
/// by clamping each value to a minimum of the previous stop value and itself.
/// For example, with stop values of 0.0, 0.5, 0.4, 1.0, we would clamp such
Copy link
Contributor

Choose a reason for hiding this comment

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

What did you end up finding out here?

ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 1.0f));
}

// Missing 0.0 first stop gradient.
Copy link
Contributor

Choose a reason for hiding this comment

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

Move these tests into separate TEST clauses, i.e.

  • ValidGradientsAreUnaffected
  • MissingFirstStopImplicitlyIsAdded
  • MissingLastStopImplicitlyIsAdded
  • ClampValuesGreaterThan1_0
  • ClampValuesLessThan0_0
  • ...

Not only will (hypothetically) the tests run in parallel, but if there is a failure/refactor, we'll understand what broke. It also makes the tests match the docstring more easily.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 27, 2023
@auto-submit auto-submit bot merged commit 82c78ad into flutter:main Sep 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 28, 2023
zanderso pushed a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 28, 2023
zanderso pushed a commit to flutter/flutter that referenced this pull request Sep 28, 2023
…sions) (#135637)

Manual roll Flutter Engine from f70f65f7a622 to be32dcc9117a (31
revisions)

Manual roll requested by [email protected]

Cannot build log URL because revision "be32dcc9117a" is invalid: Luci
builds of "Linux linux_unopt" for
be32dcc9117a462760cb52c18d0d050f067f2463 was STARTED

2023-09-28 [email protected] Rollback Dart SDK to 3.2.0-119.
(flutter/engine#46339)
2023-09-28 [email protected] [canvaskit]
Do not double-apply ImageFilter transform to children
(flutter/engine#46336)
2023-09-28 [email protected] Reland "Reverts "[ios] Fix app extension
not able to find assets from… (flutter/engine#46329)
2023-09-27 [email protected] Revert "[Impeller]
Fixes stroke path geometry that can draw outside o…
(flutter/engine#46334)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
jQHACBU4Fi2wMElkm... to U334SygIkffMJVmdu... (flutter/engine#46333)
2023-09-27 [email protected] Roll Skia from 952e8dd66560 to
b048b468d641 (1 revision) (flutter/engine#46332)
2023-09-27 [email protected] [Impeller] Destroy all
per-thread command pools tied to a context before deleting the context
(flutter/engine#46286)
2023-09-27 [email protected] Roll Skia from d78aba2524b3 to
952e8dd66560 (1 revision) (flutter/engine#46331)
2023-09-27 [email protected] [Impeller] Match Skia gradient
clamping behavior (and document). (flutter/engine#44825)
2023-09-27 [email protected] Roll Dart SDK from
97647bb1666b to 80a965ee48ab (1 revision) (flutter/engine#46330)
2023-09-27 [email protected] Roll Skia from ff5474eed6b4 to
d78aba2524b3 (3 revisions) (flutter/engine#46327)
2023-09-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts
"[ios] Fix app extension not able to find assets from unloaded bundle"
(flutter/engine#46328)
2023-09-27 [email protected] [Windows] Improve
logic to update swap intervals (flutter/engine#46172)
2023-09-27 [email protected] [Impeller] Fallback to no index
buffer when tesselation count is large, split up nonZero contours.
(flutter/engine#46282)
2023-09-27 [email protected] Roll Skia from 4731ccd6342c to
ff5474eed6b4 (1 revision) (flutter/engine#46325)
2023-09-27 [email protected] Declare native wrapper
classes in Fuchsia packages as base classes (flutter/engine#46305)
2023-09-27 [email protected] Remove fuchsia from recipes cq.
(flutter/engine#46324)
2023-09-27 [email protected] Roll Dart SDK from
c2a455113e39 to 97647bb1666b (1 revision) (flutter/engine#46323)
2023-09-27 [email protected] [macOS] Synchronise modifiers from
mouse events for RawKeyboard (flutter/engine#46230)
2023-09-27 [email protected] Roll Fuchsia Linux SDK from
Lg6FR6iDnZeV6y-E8... to 6Y22MutFhgL7ua18F... (flutter/engine#46322)
2023-09-27 [email protected] Roll Skia from 2991bb799d3f to
4731ccd6342c (1 revision) (flutter/engine#46321)
2023-09-27 [email protected] Declare native wrapper
classes in the GPU package as base classes (flutter/engine#46304)
2023-09-27 [email protected] Do not call
DrawTextBlob for performance overlay text when using Impeller
(flutter/engine#46307)
2023-09-27 [email protected] Update to use
GrDirectContexts::MakeGL (flutter/engine#46308)
2023-09-27 [email protected] Roll Skia from 0f4f31127ac5 to
2991bb799d3f (1 revision) (flutter/engine#46319)
2023-09-27 [email protected] Roll Skia from fc629215398f to
0f4f31127ac5 (1 revision) (flutter/engine#46318)
2023-09-27 [email protected] Roll Dart SDK from
6c4eb86ecd25 to c2a455113e39 (1 revision) (flutter/engine#46317)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
OMrTgAfDg9PKXTzq0... to jQHACBU4Fi2wMElkm... (flutter/engine#46314)
2023-09-27 [email protected] Roll Skia from 960325c13009 to
fc629215398f (1 revision) (flutter/engine#46313)
2023-09-27 [email protected] Roll Skia from 76aecbaea259 to
960325c13009 (2 revisions) (flutter/engine#46311)
2023-09-27 [email protected] Roll Dart SDK from
7c3588c05f87 to 6c4eb86ecd25 (3 revisions) (flutter/engine#46310)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lg6FR6iDnZeV to 6Y22MutFhgL7
  fuchsia/sdk/core/mac-amd64 from OMrTgAfDg9PK to U334SygIkffM

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

...
Mairramer pushed a commit to Mairramer/flutter that referenced this pull request Oct 10, 2023
…sions) (flutter#135637)

Manual roll Flutter Engine from f70f65f7a622 to be32dcc9117a (31
revisions)

Manual roll requested by [email protected]

Cannot build log URL because revision "be32dcc9117a" is invalid: Luci
builds of "Linux linux_unopt" for
be32dcc9117a462760cb52c18d0d050f067f2463 was STARTED

2023-09-28 [email protected] Rollback Dart SDK to 3.2.0-119.
(flutter/engine#46339)
2023-09-28 [email protected] [canvaskit]
Do not double-apply ImageFilter transform to children
(flutter/engine#46336)
2023-09-28 [email protected] Reland "Reverts "[ios] Fix app extension
not able to find assets from… (flutter/engine#46329)
2023-09-27 [email protected] Revert "[Impeller]
Fixes stroke path geometry that can draw outside o…
(flutter/engine#46334)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
jQHACBU4Fi2wMElkm... to U334SygIkffMJVmdu... (flutter/engine#46333)
2023-09-27 [email protected] Roll Skia from 952e8dd66560 to
b048b468d641 (1 revision) (flutter/engine#46332)
2023-09-27 [email protected] [Impeller] Destroy all
per-thread command pools tied to a context before deleting the context
(flutter/engine#46286)
2023-09-27 [email protected] Roll Skia from d78aba2524b3 to
952e8dd66560 (1 revision) (flutter/engine#46331)
2023-09-27 [email protected] [Impeller] Match Skia gradient
clamping behavior (and document). (flutter/engine#44825)
2023-09-27 [email protected] Roll Dart SDK from
97647bb1666b to 80a965ee48ab (1 revision) (flutter/engine#46330)
2023-09-27 [email protected] Roll Skia from ff5474eed6b4 to
d78aba2524b3 (3 revisions) (flutter/engine#46327)
2023-09-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts
"[ios] Fix app extension not able to find assets from unloaded bundle"
(flutter/engine#46328)
2023-09-27 [email protected] [Windows] Improve
logic to update swap intervals (flutter/engine#46172)
2023-09-27 [email protected] [Impeller] Fallback to no index
buffer when tesselation count is large, split up nonZero contours.
(flutter/engine#46282)
2023-09-27 [email protected] Roll Skia from 4731ccd6342c to
ff5474eed6b4 (1 revision) (flutter/engine#46325)
2023-09-27 [email protected] Declare native wrapper
classes in Fuchsia packages as base classes (flutter/engine#46305)
2023-09-27 [email protected] Remove fuchsia from recipes cq.
(flutter/engine#46324)
2023-09-27 [email protected] Roll Dart SDK from
c2a455113e39 to 97647bb1666b (1 revision) (flutter/engine#46323)
2023-09-27 [email protected] [macOS] Synchronise modifiers from
mouse events for RawKeyboard (flutter/engine#46230)
2023-09-27 [email protected] Roll Fuchsia Linux SDK from
Lg6FR6iDnZeV6y-E8... to 6Y22MutFhgL7ua18F... (flutter/engine#46322)
2023-09-27 [email protected] Roll Skia from 2991bb799d3f to
4731ccd6342c (1 revision) (flutter/engine#46321)
2023-09-27 [email protected] Declare native wrapper
classes in the GPU package as base classes (flutter/engine#46304)
2023-09-27 [email protected] Do not call
DrawTextBlob for performance overlay text when using Impeller
(flutter/engine#46307)
2023-09-27 [email protected] Update to use
GrDirectContexts::MakeGL (flutter/engine#46308)
2023-09-27 [email protected] Roll Skia from 0f4f31127ac5 to
2991bb799d3f (1 revision) (flutter/engine#46319)
2023-09-27 [email protected] Roll Skia from fc629215398f to
0f4f31127ac5 (1 revision) (flutter/engine#46318)
2023-09-27 [email protected] Roll Dart SDK from
6c4eb86ecd25 to c2a455113e39 (1 revision) (flutter/engine#46317)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
OMrTgAfDg9PKXTzq0... to jQHACBU4Fi2wMElkm... (flutter/engine#46314)
2023-09-27 [email protected] Roll Skia from 960325c13009 to
fc629215398f (1 revision) (flutter/engine#46313)
2023-09-27 [email protected] Roll Skia from 76aecbaea259 to
960325c13009 (2 revisions) (flutter/engine#46311)
2023-09-27 [email protected] Roll Dart SDK from
7c3588c05f87 to 6c4eb86ecd25 (3 revisions) (flutter/engine#46310)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lg6FR6iDnZeV to 6Y22MutFhgL7
  fuchsia/sdk/core/mac-amd64 from OMrTgAfDg9PK to U334SygIkffM

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

...
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
)

Skia clamps any gradient stops to values of 0.0 to 1.0. Implement this behavior in Impeller and document it in dart:ui (Framework also needs to be documented). This also matches the w3c gradient behavior: https://www.w3.org/TR/2000/CR-SVG-20000802/pservers.html - almost. We might be slightly off with how we're inserting additional stops for 0.0 and 1.0, but at least its closer.

Fixes flutter/flutter#132792
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
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Impeller] Impeller and Skia gradients disagree on behavior for invalid color stops (outside of the range of 0.0 to 1.0)
3 participants