-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Match Skia gradient clamping behavior (and document). #44825
[Impeller] Match Skia gradient clamping behavior (and document). #44825
Conversation
/// * 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 |
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 bit is surprising to me. I would have expected it to be sorted but this works too.
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.
Still WIP and confirming :)
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.
What did you end up finding out here?
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 found the w3c notes which basically confirm this behavior is approximately correct
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 |
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.
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.
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.
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.
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.
👍🏽
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 assuming the tests are cleaned up a bit, everything else looks good!
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 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?
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.
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 |
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.
What did you end up finding out here?
ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 1.0f)); | ||
} | ||
|
||
// Missing 0.0 first stop gradient. |
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.
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.
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.
Done
…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 ...
…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 ...
) 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
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