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

ImageFilter default tile mode automatic selection breaking change notice #11338

Merged

Conversation

jonahwilliams
Copy link
Member

Breaking change notice for flutter/flutter#154935 . Engine PR should land shortly...

Presubmit checklist

  • This PR is marked as draft with an explanation if not meant to land until a future stable release.
  • This PR doesn’t contain automatically generated corrections (Grammarly or similar).
  • This PR follows the Google Developer Documentation Style Guidelines — for example, it doesn’t use i.e. or e.g., and it avoids I and we (first person).
  • This PR uses semantic line breaks of 80 characters or fewer.

Copy link
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

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

Thanks so much for writing this, @jonahwilliams! I have one clarification question.

Comment on lines 12 to 13
was specified. A value of `null` when passed to the filter's constructor
specifies automatic selection.
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
was specified. A value of `null` when passed to the filter's constructor
specifies automatic selection.
Passing a value of `null` to the filter's constructor specifies
automatic selection.

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

Comment on lines 19 to 24
`Tilemode.repeated`, `TileMode.mirror`, and `TileMode.decal`. The default for
ui.ImageFilter is `TileMode.clamp`. We've observed that the behavior of clamp
does not match most developer's expections about filter operations. Instead,
decal better matches the intuition for saveLayers, as edge pixels are left
as transparent black. For backdrop filters, `mirror` is used which prevents
falloff on blurs.
Copy link
Contributor

Choose a reason for hiding this comment

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

So.... why are you giving this advice? Is the default behavior now decal? I think you are saying how the automatic selection process works?

Suggested change
`Tilemode.repeated`, `TileMode.mirror`, and `TileMode.decal`. The default for
ui.ImageFilter is `TileMode.clamp`. We've observed that the behavior of clamp
does not match most developer's expections about filter operations. Instead,
decal better matches the intuition for saveLayers, as edge pixels are left
as transparent black. For backdrop filters, `mirror` is used which prevents
falloff on blurs.
`Tilemode.repeated`, `TileMode.mirror`, and `TileMode.decal`.
Previously, `ImageFilter` defaulted to `clamp` mode if the
behavior wasn't specified, which sometimes surprised developers
as it didn't always match expectations.
As of this change, the filter
automatically selects `decal` mode when using `saveLayers`,
which leave edge pixels as transparent black.
The filter selects `mirror` mode for backdrop filters because
falloff on blurs.

When is the repeated mode used?

Copy link
Contributor

Choose a reason for hiding this comment

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

That looks better to me too. Repeated is never a default, but can be selected by the developer by specifying it manually when constructing the blur.

There is also drawImage(and variants) that use a default of clamp. And all Canvas.draw methods other than the image (and Atlas) versions will also default to decal.

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 replaced this with a list that described the automatic behavior, PTAL?

@sfshaza2
Copy link
Contributor

/gcbrun

@sfshaza2
Copy link
Contributor

Was this PR in draft mode when I started reviewing it? I didn't notice that. :)

@jonahwilliams
Copy link
Member Author

No worries, i appreciate the review as always :)

The tile mode of a `ImageFilter` declares what happens to edge pixels of
the applied filter. There are four options, `TileMode.clamp`,
`Tilemode.repeated`, `TileMode.mirror`, and `TileMode.decal`. The default for
ui.ImageFilter is `TileMode.clamp`. We've observed that the behavior of clamp
Copy link
Contributor

Choose a reason for hiding this comment

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

Used to be clamp, or has been clamp, or was previously clamp?

Code after migration:

```dart
// Set tile mode to old default.
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless the new defaults look better to you? This makes it sound like developers must specify clamp now, but they may not want to.

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.

Just left some comments.

@jonahwilliams jonahwilliams marked this pull request as ready for review October 29, 2024 16:43
@jonahwilliams jonahwilliams requested a review from a team as a code owner October 29, 2024 16:43
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.

Some non-blocking suggestions for completeness.

The `ui.ImageFilter.blur`'s default tile mode is now automatically selected
by the backend. Previously `TileMode.clamp` was used unless a different tile
mode was specified. Passing a value of `null` to the filter's constructor
specifies automatic selection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this imply that you need to manually pass a null to get the behavior? How about:

"Previously the default was clamp unless a different tile mode was specified. Now, the default is null and specifies automatic selection unless a specific tile mode is specified."


## Background

`ImageFilter`'s _tile mode_ specifies what happens to edge pixels for the
Copy link
Contributor

Choose a reason for hiding this comment

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

Add .blur to mentions of ImageFilter?

As of this change, the filter automatically selects the following tile modes
based on context:

* `decal` with save layers and when applied to individual draws.
Copy link
Contributor

Choose a reason for hiding this comment

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

drawShape?


## Migration guide

Only image filters that don't specify an explicit tile mode are
Copy link
Contributor

Choose a reason for hiding this comment

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

blur

Only image filters that don't specify an explicit tile mode are
impacted by this change. In these cases, you can specify an explicit tile
mode to retain the prior behavior. However, we believe the automatic
selection of behavior will be a superior choice in most cases.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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 again

Copy link
Contributor

@domesticmouse domesticmouse left a comment

Choose a reason for hiding this comment

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

PTAL @sfshaza2


```dart
// Set tile mode to old default.
var filter = ui.ImageFilter.blur(sigmaX: 4, sigmaY: 4, tileMode: 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.

Should this be turned into a lint with a fix to maintain consistent behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

We want folks to use the automatic selection though and not provide a default. maybe this section isn't clear and we should just not include it?

Copy link
Contributor

Choose a reason for hiding this comment

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

That intent wasn't obvious from my reading, nor was the work that has gone into creating this proposal. I'm happy to work with y'all to build a proposal that better communicates what you are attempting to achieve this, if that would be helpful. Otherwise I can suggest some minor edits?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mentioned this confusion in an earlier comment. I think this part of the section needs to indicate that it is optional and only needed if the developer preferred the previous behavior. I think it might be worthwhile to include it if the comment in the "after" section made it clear that nothing needs to be done, but if you really want the old behavior then this is the way to restore it. There has to be a concise way to express that the change is optional and probably not desired, but here it is if you need it.

Copy link
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

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

This PR is better but still seems to cause some confusion. Can we land it?

@jonahwilliams
Copy link
Member Author

I was waiting for some FYI that the website infra was working again.

@sfshaza2
Copy link
Contributor

/gcbrun

@sfshaza2
Copy link
Contributor

@jonahwilliams, the website build is working again!

@flutter-website-bot
Copy link
Collaborator

flutter-website-bot commented Oct 31, 2024

Visit the preview URL for this PR (updated for commit c24df86):

https://flutter-docs-prod--pr11338-add-tile-mode-breaking-chan-skjvf1ad.web.app

@jonahwilliams jonahwilliams merged commit 547da8f into flutter:main Nov 1, 2024
9 checks passed
@jonahwilliams jonahwilliams deleted the add_tile_mode_breaking_change branch November 1, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants