Skip to content

[framework] introduce repaint boundary in Opacity widgets #101601

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

Merged

Conversation

jonahwilliams
Copy link
Member

Fixes #101597

@flutter-dashboard flutter-dashboard bot added a: animation Animation APIs f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 8, 2022
@jonahwilliams jonahwilliams marked this pull request as ready for review April 8, 2022 19:17
/// to reuse textures on subsequent frames if the opacity is changing but
/// the child layer is not. If the child layers are usually changing along
/// with the opacity, setting this value to `false` will reduce the size of the
/// layer tree.
Copy link
Member

Choose a reason for hiding this comment

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

Document the default value.

///
/// This value defaults to true. The repaint boundary allows the engine
/// to reuse textures on subsequent frames if the opacity is changing but
/// the child layer is not. If the child layers are usually changing along
Copy link
Member

Choose a reason for hiding this comment

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

See also my note here: #101597 (comment)

If we decide to keep it on Opacity, we may want to link to AnimatedOpacity and FadeTransition from here and emphasize that those may be better choices if the opacity changes frequently?

Copy link
Member

Choose a reason for hiding this comment

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

The fact that we need a switch to turn this off makes me wonder if we should actually just omit this feature from the Opacity widget. Did you see a use case where this helped? I would have assumed that this is mostly helpful for animated opacities (and for those one should use AnimatedOpacity or FadeTransition).

Copy link
Member Author

Choose a reason for hiding this comment

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

So this optimiztion isn't really about animated opacities, its just easier to see when the opacity is animated. Anytime you repaint anything above an opacity, whether or not the opacity or its children have changed - you will go down a much slower path if the engine thinks the child layers have been updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this particular case though, I'm not really in love with this flag. I think we should just update the progress spinner to not use an opacity widget and instead paint with opacity.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should just update the progress spinner to not use an opacity widget and instead paint with opacity.

+1 to that if that's possible.

@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 #101601 at sha 89ce7c4

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Apr 9, 2022
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

return _Opacity(
opacity: opacity,
alwaysIncludeSemantics: alwaysIncludeSemantics,
child: RepaintBoundary(child: child),
Copy link
Member

Choose a reason for hiding this comment

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

uber-nit: maybe format this as:

Suggested change
child: RepaintBoundary(child: child),
child: RepaintBoundary(
child: child,
),

to make it clear to the casual reader (i.e. me right now) where the repaint boundary is getting introduced...

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

assert(alwaysIncludeSemantics != null),
super(key: key, child: child);


Copy link
Member

Choose a reason for hiding this comment

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

nit: remove one extra line of white space

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

@@ -1759,7 +1759,7 @@ class _AnimatedOpacityState extends ImplicitlyAnimatedWidgetState<AnimatedOpacit
return FadeTransition(
opacity: _opacityAnimation,
alwaysIncludeSemantics: widget.alwaysIncludeSemantics,
child: widget.child,
child: RepaintBoundary(child: widget.child),
Copy link
Member

Choose a reason for hiding this comment

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

Same formatting nit

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

return _FadeTransition(
opacity: opacity,
alwaysIncludeSemantics: alwaysIncludeSemantics,
child: RepaintBoundary(child: child),
Copy link
Member

Choose a reason for hiding this comment

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

and here as well

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

@fluttergithubbot fluttergithubbot merged commit 6def159 into flutter:master Apr 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 12, 2022
@jonahwilliams jonahwilliams deleted the opacity_repaint_boundary branch April 12, 2022 18:13
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 12, 2022
jonahwilliams added a commit to jonahwilliams/flutter that referenced this pull request Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: animation Animation APIs f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material 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.

Opacity/FadeTransition should allow child widgets to avoid repainting
3 participants