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

Allow GestureBinding subclasses to know hitTest information #113831

Closed
wants to merge 1 commit into from

Conversation

fzyzcjy
Copy link
Contributor

@fzyzcjy fzyzcjy commented Oct 21, 2022

  1. I will finish code details, refine code, add tests, make tests pass, etc, after a code review that thinks the rough idea is acceptable. It is because, from my past experience, reviews may request changing a lot. If the general idea is to be changed, all detailed implementation efforts are wasted :)
  2. The PR has an already-working counterpart, and it produces ~60FPS smooth experimental results. The benchmark results and detailed analysis is in chapter https://cjycode.com/flutter_smooth/benchmark/. All the source code is in https://github.com/fzyzcjy/engine/tree/flutter-smooth and https://github.com/fzyzcjy/flutter/tree/flutter-smooth.
  3. Possibly useful as a context to this PR, there is a whole chapter discussing the internals - how flutter_smooth is implemented. (Link: https://cjycode.com/flutter_smooth/design/)

This PR allows the subclasses of GestureBinding to read the hitTest information. It is directly needed in flutter_smooth, because flutter_smooth has extra call to dispatchEvent and only execute those who are in auxiliary tree (and omit those in the main tree) during preempt render. I can copy-and-paste the content of dispatchEvent to mimic the behavior, but there is one missing piece: the hitTest information. By adding this PR, it can work.

An alternative solution, which the flutter-smooth branch is currently using (but more hacky), may be to add a filter to dispatchEvent. Then, we can utilize the filter to skip those RenderObjects in the main tree.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt. -- see above
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 21, 2022
@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 Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on 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.

@@ -330,6 +330,8 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
///
/// The state of hovering pointers is not tracked because that would require
/// hit-testing on every frame.
@protected
Map<int, HitTestResult> get hitTests => _hitTests;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should make this part of the public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm what about the "alternative soluution" described above?

An alternative solution, which the flutter-smooth branch is currently using (but more hacky), may be to add a filter to dispatchEvent. Then, we can utilize the filter to skip those RenderObjects in the main tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, as for this one: Is it acceptable to expose a readonly version? For example:

UnmodifiableMapView<int, UnmodifiableHitTestResultView> get hitTests => ...;

where unmodifiable map is https://api.flutter.dev/flutter/dart-collection/UnmodifiableMapView-class.html
and UnmodifiableHitTestResultView can be something like:

class UnmodifiableHitTestResultView {
  final HitTestResult _actual;
  ... only provide a few readonly method, so users have no possibility to write anything to it...
}

@goderbauer
Copy link
Member

This is internal state that nobody should depend on. If you have a use case for this, I suggest filing an issue that describes what you want to achieve instead of describing a solution.

@goderbauer goderbauer closed this Nov 16, 2022
@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Nov 16, 2022

Ok, I will explain why this is needed in a separate issue later.

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Nov 23, 2022

Issue created describing this: #115899

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants