Skip to content

Conversation

@davidhicks980
Copy link
Contributor

@davidhicks980 davidhicks980 commented Jul 8, 2024

This PR makes the CupertinoPopupSurface more vibrant. Also, the gaussian kernel was switched to 30 from 20 based on comparisons.

@dkwingsmt - Looking forward to your dialog and fixes!

After is on bottom:
image

Notably, because the borders are very transparent, the new version looks more colorful in the sample screencap than it actually is. As such, focus on the individual colors to get a feel for the change.

actual old new
image image image
image image image
image image image

Partially addresses #29483

This will need tests, which I will add once I know which tests break due to this commit.

Blockers:

Pre-launch Checklist

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

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Jul 8, 2024
@davidhicks980 davidhicks980 marked this pull request as ready for review July 8, 2024 19:41
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@dkwingsmt
Copy link
Contributor

cc @matthew-carroll @xster

The difference is phenomenal!

I have the following problems:

  1. How do we verify this is the closest we can get, or I mean, how do we document these magic numbers? If future readers don't know how these numbers are derived, then we can never improve them and are essentially marking them as "magic, don't touch".
  2. How do we unit test them? According to my past experience on golden tests, golden tests do not apply the filters (at least the blurring is not applied).

@davidhicks980
Copy link
Contributor Author

davidhicks980 commented Jul 9, 2024

  1. I started with a straight saturation filter (from https://docs.rainmeter.net/tips/colormatrix-guide/), but spent a bit of time tweaking until it looked good. I'm not actually sure if we have all of the backdrop convolutions that would be needed to perfectly recreate a surface material, as it doesn't appear to just use a gaussian blur and color filter. However, this is pretty close.
static List<double> buildLightColorFilterMatrix() {
    const double lightLumR = 0.26;
    const double lightLumG = 0.4;
    const double lightLumB = 0.17;
    const double saturation = 2.0;
    const double sr = (1 - saturation) * lightLumR;
    const double sg = (1 - saturation) * lightLumG;
    const double sb = (1 - saturation) * lightLumB;
    return <double>[
      sr + saturation, sg, sb, 0.0, 0.0, //
      sr, sg + saturation, sb, 0.0, 0.0, //
      sr, sg, sb + saturation, 0.0, 0.0, //
      0.0, 0.0, 0.0, 1.0, 0.0, //
    ];
  }

 
  static List<double> buildDarkColorFilterMatrix() {
    const double additive = 0.3;
    const double darkLumR = 0.45;
    const double darkLumG = 0.8;
    const double darkLumB = 0.16;
    const double saturation = 1.7;
    const double sr = (1 - saturation) * darkLumR;
    const double sg = (1 - saturation) * darkLumG;
    const double sb = (1 - saturation) * darkLumB;
    return <double>[
      sr + saturation, sg, sb, 0.0, additive, //
      sr, sg + saturation, sb, 0.0, additive, //
      sr, sg, sb + saturation, 0.0, additive, //
      0.0, 0.0, 0.0, 1.0, 0.0, //
    ];
  }
  1. I'm also not sure what the best way to unit test this would be. A basic test would just be looking up the BackdropFilter and printing out the image filter (e.g. ImageFilter.compose(source -> ColorFilter.matrix([1.74, -0.4, -0.17, 0.0, 0.0, -0.26, 1.6, -0.17, 0.0, 0.0, -0.26, -0.4, 1.83, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]) -> blur(30.0, 30.0, clamp) -> result)). The color filter affects the appearance of the menu a bit more, so a golden may be more useful. I haven't done golden testing yet, so I need to look into it!

Added equation to derive color filter
Add whitespace back
@dkwingsmt
Copy link
Contributor

dkwingsmt commented Jul 10, 2024

About unit test, my idea is:

  1. Blurring is hard to test, and is technically not the target of this PR. So we're only testing the change of color through this filter.
  2. With these matrices, I assume we can derive what a certain color will be converted to without going through the engine. If this is true...
  3. We can set up a few tests, each testing what a certain background color will be converted to by these matrices. Denote them as A and B respectively, therefore B = M A.
  4. The expected color (C) can be obtained by drawing a dialog over a solid background of A.
  5. B and C will not match exactly, but we can note the true value C in the doc, and expect the distance between B and C to be less than a certain threshold.
  6. For example, we pick 27 colors by having R, G, B each being 0, 127, 255, and calculate the average squared distance.

davidhicks980 and others added 2 commits July 10, 2024 09:54
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
@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.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #151430 at sha 996d22f

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Jul 10, 2024
@davidhicks980
Copy link
Contributor Author

davidhicks980 commented Jul 16, 2024

About unit test, my idea is:

  1. Blurring is hard to test, and is technically not the target of this PR. So we're only testing the change of color through this filter.
  2. With these matrices, I assume we can derive what a certain color will be converted to without going through the engine. If this is true...

I'm not sure if this is easily done without reaching into the engine, but correct me if I'm wrong. ColorFilters appear to be composed and applied directly by skia (at least, as far as I can tell... I'm not too familiar with the native layer of Flutter):

class ColorFilterLayer extends ContainerLayer {

https://api.skia.org/classSkColorFilters.html

I added a few Goldens to test the surface changes, but I'm interested to hear if there is a better way to handle this.

@flutter-dashboard
Copy link

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

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #151430 at sha 4aa2544

@dkwingsmt
Copy link
Contributor

I think the tests make sense, but here is what it looks like:

Unpainted:
image

Light:
image

I'm not sure if the light mode result has the color filter applied or it is just the translucent backdrop, but the unpainted one definitely isn't affected by anything at all. :/

@dkwingsmt
Copy link
Contributor

Ok, I've found the reasons.

First, in "unpainted" tests, the two golden files are using the same name and the doc says that the theme shouldn't affect the result. This is incorrect, because the theme does affect the result, since the color filters are different.

Second, in "unpainted" tests, the filters isn't applied at all, because there's nothing within the filter and the layer is dropped. By adding an empty Container to the child, the result is obviously different:

image

While this shouldn't be a problem for production code (since there'll always be a child), I suggest making PopUpSurface.child required and explain the reason, and add an Container to the child in the test.

// popup_surface_test.dart, L100
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: CupertinoPopupSurface(
                isSurfacePainted: isSurfacePainted,
                child: child,
              ),
            ),

Third, as I pointed in the comment, I wonder why a 3rd layer of 18 strips is painted on top of the pop up surface. Is it used as the master for comparison? I don't think this is very useful though. Without it the result is very obvious and beautiful:

image

My suggestion: I thought the backdrop filters don't apply to golden images, but it turns out they do. In this case, I still think most of the test cases should be used to test the color change (since that's the most complicated part), and these test should be done without the blurring effect for accuracy, while some separate tests should be used to verify the blurring effect.

  • CupertinoPopUpSurface should allow customizing the blurring radius. This is only used for unit tests as below.
  • The current unit tests that verify the color change for both themes are great, but they should use a blurring radius of 0, should not have the "top layer" of strips, and there can be a larger variety of colors.
  • I suggest we remove the unpainted tests, because in practice the pop up surface is only used with the correct background. If the surface is unpainted, then it's the children's responsibility to paint the correct background afterwards, otherwise the behavior is not guaranteed.
  • One or a few additional tests should be used to verify the blurring effect. We'll probably want it to be just black and white to avoid the effect of colors.

@flutter-dashboard
Copy link

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

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #151430 at sha 718071e

@davidhicks980
Copy link
Contributor Author

This should now be updated with skip annotations, i.e.

skip: kIsWasm, // https://github.com/flutter/flutter/issues/152026

I also updated a few tests to make them more specific based on the testing guidelines -- I think I had skipped one of the testing documents from the contributing guidelines, so sorry for the late update! Largest difference was splitting 'Nonpositive blurSigma removes blur' into 'Setting blurSigma to a negative number throws' and 'Setting blurSigma to zero removes blur'.

///
/// The saturation effect can be removed for debugging by setting
/// [debugIsVibrancePainted] to false. The saturation effect is not supported on
/// the html web renderer and will not be applied regardless of the value of
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// the html web renderer and will not be applied regardless of the value of
/// web with the skwasm renderer and will not be applied regardless of the value of

The HTML renderer has been deprecated and removed https://docs.flutter.dev/platform-integration/web/renderers so we only mention skwasm here.

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Sep 4, 2024

Thank you for your update! Being unsupported by skwasm is unfortunate but it'll probably be solved in the future and doesn't reduce the value of this PR. I found a fix to the doc and otherwise we're ready to go.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 6, 2024
@dkwingsmt
Copy link
Contributor

Look perfect :)

@dkwingsmt
Copy link
Contributor

I've created an issue to remind us the skwasm issue. #154698

@auto-submit auto-submit bot merged commit 35b0349 into flutter:master Sep 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 6, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 6, 2024
flutter/flutter@45ef8f3...2e221e7

2024-09-06 leroux_bruno@yahoo.fr Fix DropdownMenu focused item styles (flutter/flutter#153159)
2024-09-06 phucloi.nguyen@manabie.com Support custom transition duration for `DialogRoute`, `CupertinoDialogRoute` and show dialog methods. (flutter/flutter#154048)
2024-09-06 51940183+Sameri11@users.noreply.github.com [tool] Add `dartFileName` setting for platform plugins  (flutter/flutter#153099)
2024-09-06 reidbaker@google.com [Conductor] Add ability to override mirror, add tests for default arg parsing and custom arg parsing (flutter/flutter#154363)
2024-09-06 59215665+davidhicks980@users.noreply.github.com Improve CupertinoPopupSurface appearance (flutter/flutter#151430)
2024-09-06 engine-flutter-autoroll@skia.org Roll Packages from 71e827e to 56df73e (1 revision) (flutter/flutter#154725)
2024-09-06 goderbauer@google.com Quick access to style guide (flutter/flutter#154689)
2024-09-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Flutter Engine from c50eb8a65097 to 015f3b1dec53 (2 revisions) (#154691)" (flutter/flutter#154726)
2024-09-05 737941+loic-sharma@users.noreply.github.com Improve iOS unpack target's error messages (flutter/flutter#154649)
2024-09-05 30870216+gaaclarke@users.noreply.github.com Made some pixel tests fuzzy (flutter/flutter#154680)
2024-09-05 engine-flutter-autoroll@skia.org Roll Flutter Engine from c50eb8a65097 to 015f3b1dec53 (2 revisions) (flutter/flutter#154691)
2024-09-05 49699333+dependabot[bot]@users.noreply.github.com Bump peter-evans/create-pull-request from 7.0.0 to 7.0.1 (flutter/flutter#154690)
2024-09-05 36861262+QuncCccccc@users.noreply.github.com Normalize Dialog theme (flutter/flutter#153982)
2024-09-05 chris@bracken.jp iOS,macOS: Do not copy unsigned_binaries.txt to build outputs (flutter/flutter#154684)
2024-09-05 engine-flutter-autoroll@skia.org Roll Flutter Engine from e042ff5df7af to c50eb8a65097 (1 revision) (flutter/flutter#154679)
2024-09-05 34871572+gmackall@users.noreply.github.com Add proguard rule to keep the class for all implementations of FlutterPlugin (flutter/flutter#154677)
2024-09-05 bruno.leroux@gmail.com Fix DropdownMenu menu does not follow the text field (flutter/flutter#154667)
2024-09-05 engine-flutter-autoroll@skia.org Roll Flutter Engine from a156e713f4dc to e042ff5df7af (1 revision) (flutter/flutter#154678)
2024-09-05 103767860+dy0gu@users.noreply.github.com Fix ZoomPageTransitionsBuilder hardcoded fill color (flutter/flutter#154057)
2024-09-05 engine-flutter-autoroll@skia.org Roll Flutter Engine from 34b61eb53b99 to a156e713f4dc (1 revision) (flutter/flutter#154672)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
davidhicks980 added a commit to davidhicks980/flutter that referenced this pull request Sep 10, 2024
dkwingsmt added a commit that referenced this pull request Sep 10, 2024
Reverts #151430 to fix
#154887 until I can investigate
further.

Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Nov 27, 2024
#151430 had to be reverted
because of a black square appearing during animations. This PR fixes the
issue by switching from BlendMode.src -> BlendMode.srcOver. I visually
checked to make sure the issue was fixed on MacOS and iOS/Android
simulators.

Fixes #154887

## 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

---------

Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants