Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default TileMode for blur ImageFilter objects to null #55552

Merged

Conversation

flar
Copy link
Contributor

@flar flar commented Oct 1, 2024

Fixes flutter/flutter#154935

Historically ImageFilter.blur supported setting a TileMode and had a default mode of clamp, but few developers actually set the value and the default was not appropriate for some common uses like as a backdrop filter where the clamp mode produces flashing when scrolling high frequency pixel content underneath a blurred title bar.

This PR removes the default tile mode instead allowing a null value as the default which will allow the engine to use an appropriate context-dependent default tile mode depending on the action being performed. Typically:

  • decal for rendering operations and saveLayers and ImageFilterLayer
  • clamp for image operations
  • mirror for backdrop filters

@flar flar force-pushed the ui-blur-image-filter-null-default-tile-mode branch from 4c5d450 to 56a2fcb Compare October 1, 2024 19:56
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.

I'm not sure that I followed the discussion on clamp for image operations vs decal. I think it can be a bit fuzzy whether or not something is an image operation, because different paint settings (like mask filter) can lead to something ending up as a saveLayer more or less.

We also need to change this for the web engine.

@flar
Copy link
Contributor Author

flar commented Oct 3, 2024

I'm not sure that I followed the discussion on clamp for image operations vs decal. I think it can be a bit fuzzy whether or not something is an image operation, because different paint settings (like mask filter) can lead to something ending up as a saveLayer more or less.

We also need to change this for the web engine.

drawImage(Rect/Nine/Atlas) are image operations.
saveLayer is not.

I figure that saveLayer is a collection of rendering and rendering operations have space all around them out to infinity so they should reflect that in the choice of mode.

drawImage et al, the source is a physical image that has edges. Within the bounds of the image it should be smeared from its contents. Granted it will spill over the theoretical "frame" which they might clip out.

If we take some other operation and render it to a temp layer then we need to respect whatever tile mode was chosen for the content even as we perform that operation (whether it is a defaulted tile mode or whether they explicitly set it), so I don't think that case should affect the defaults. It's an implementation detail. The defaults were chosen based on the base operation itself and what is happening...

@chinmaygarde
Copy link
Member

Triage: This is waiting on an update to the web engine.

@flar flar force-pushed the ui-blur-image-filter-null-default-tile-mode branch from 56a2fcb to 1b20a34 Compare October 21, 2024 23:51
@github-actions github-actions bot added the platform-web Code specifically for the web engine label Oct 21, 2024
@flar flar requested a review from yjbanov October 21, 2024 23:55
@flar
Copy link
Contributor Author

flar commented Oct 21, 2024

I've plumbed most of the web stuff, but haven't yet gotten it all working. I think I got canvaskit renderer to accept the defaults, but it doesn't implement the tile mode in saveLayer so you can't really tell. web gives me some sort of "null canvas" and "width/height > 0" assertion failure. I haven't tried with skwasm as I don't have that building in my local engine case...

@flar flar force-pushed the ui-blur-image-filter-null-default-tile-mode branch from c5ca242 to 30e02d2 Compare October 23, 2024 02:00
@flar
Copy link
Contributor Author

flar commented Oct 23, 2024

I'm hoping this last commit fixes all of the tests, but I still want to have a rendering test for the various blur tile mode values to catch specific regressions.

@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 #55552 at sha a0d7867

Copy link
Contributor

@eyebrowsoffire eyebrowsoffire 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 to me, have just a couple non-blocking requests.

@@ -60,7 +60,7 @@ abstract class SkwasmImageFilter implements SceneImageFilter {
///
/// The handle is deleted immediately after [borrow] returns. The [borrow]
/// function must not store the handle to avoid dangling pointer bugs.
void withRawImageFilter(ImageFilterHandleBorrow borrow);
void withRawImageFilter(ImageFilterHandleBorrow borrow, {ui.TileMode defaultMode = ui.TileMode.clamp});
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things: can you actually call this defaultTileMode to be a bit more clear, and secondly can you modify the doc comment to mention this parameter and what it does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with defaultBlurTileMode since it only applies to blurs...

@flar
Copy link
Contributor Author

flar commented Oct 23, 2024

Triage: This is waiting on an update to the web engine.

-ish.

For optics it would be nice if the new default for the backdropfilters worked on all platforms since that is the primary reason to make this change to the defaults. That requires changes to CanvasKit. There are similar changes needed to Skwasm which could be made as part of this PR or as part of the PR that adopts the CanvasKit changes - either way. Then the backdropfilter's tile mode will start working on web (except HTML where there's little hope).

But, meanwhile, this PR could be landed and effect the API change without those changes, it would work for most rendering on CK and Skwasm, but not for BDFs until the above changes are made.

If we can get the web engine to honor the filter mode for BDFs while I finish up some details on this PR, that would be a good path forward so we can announce the breaking change along with "and this works on all platforms (except the deprecated HTML renderer)".

@jonahwilliams
Copy link
Member

We're a long way out from a release cut, so assuming the only web change that needs to happen is exposing an API on the canvaskit side, landing this earlier SGTM

@jonahwilliams jonahwilliams self-requested a review October 23, 2024 19:28
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

@flar flar force-pushed the ui-blur-image-filter-null-default-tile-mode branch from 64bb51b to 9bb40b3 Compare October 25, 2024 00:34
@flutter-dashboard
Copy link

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

Changes reported for pull request #55552 at sha 768f91b

@jonahwilliams
Copy link
Member

The breaking change notice is now waiting on this PR to land: flutter/website#11338

@flar
Copy link
Contributor Author

flar commented Oct 28, 2024

I have now completed all of the golden tests for this PR. It is ready for final reviews.

@flutter-dashboard
Copy link

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

Changes reported for pull request #55552 at sha bb0b87d

@flar
Copy link
Contributor Author

flar commented Oct 29, 2024

The goldens look good to me, leaving them untriaged for reviewers.

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

Copy link
Contributor

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

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

LGTM. I have one tiny non-blocking nitpick.

final SkwasmImageFilter nativeFilter = SkwasmImageFilter.fromUiFilter(imageFilter);
final paintHandle = (paint as SkwasmPaint).toRawPaint();
final ui.TileMode? backdropTileMode = nativeFilter.backdropTileMode;
final paintHandle = (paint as SkwasmPaint).toRawPaint(/*ui.TileMode.decal*/);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really love this little inline comment here. Either we actually want the argument to be visible, and we shouldn't provide a default value, or we should just nix this comment and allow the default argument to be implicit and not visible in the code. (Also, the comment should probably be like /*defaultBlurTileMode: ui.TileMode.decal*/ since it is a named argument, but I we should just remove it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment above this talks about how there are 2 different filters involved in this operation and one uses mirror and the other uses decal as the defaults. If this comment isn't there then you can see where "mirror" is used, but there is no indication of where "decal" is used because it is implicit. I tried just specifying it manually (without the comments), but the analyzer rejected the idea of manually supplying the value that is the default (why?). So, I put it in comments to satisfy the analyzer while still be indicative of the "2 different defaults" I had described earlier.

Why won't the analyzer just let me say the default without complaining?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I provide no default in the call arguments then every draw command in this file has to supply decal even though it is the default.

@flar flar added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 29, 2024
@auto-submit auto-submit bot merged commit cfb19e4 into flutter:main Oct 29, 2024
35 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 30, 2024
…157833)

flutter/engine@999797a...57ed5d3

2024-10-29 [email protected] [Flutter GPU] Fix MSAA sample size and HostBuffer alignment. (flutter/engine#56218)
2024-10-29 [email protected] Change default TileMode for blur ImageFilter objects to null (flutter/engine#55552)
2024-10-29 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] Reland: disable AHBs on devices that were upgraded to 29. (#56213)" (flutter/engine#56220)
2024-10-29 [email protected] Made et compilation errors relative to the CWD (flutter/engine#56177)
2024-10-29 [email protected] [Impeller] Reland: disable AHBs on devices that were upgraded to 29. (flutter/engine#56213)

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] 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
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…/engine#55552)

Fixes flutter#154935

Historically ImageFilter.blur supported setting a TileMode and had a default mode of `clamp`, but few developers actually set the value and the default was not appropriate for some common uses like as a backdrop filter where the clamp mode produces flashing when scrolling high frequency pixel content underneath a blurred title bar.

This PR removes the default tile mode instead allowing a null value as the default which will allow the engine to use an appropriate context-dependent default tile mode depending on the action being performed. Typically:

- decal for rendering operations and saveLayers and ImageFilterLayer
- clamp for image operations
- mirror for backdrop filters
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 platform-web Code specifically for the web engine will affect goldens
Projects
None yet
5 participants