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

[macOS] Use CVDisplayLink to drive repaint #49159

Merged
merged 8 commits into from
Feb 27, 2024
Merged

Conversation

knopp
Copy link
Member

@knopp knopp commented Dec 17, 2023

Fixes flutter/flutter#49757

This PR synchronises updates with display refresh allowing for true 120hz repaint. It also enforces frame pacing resulting in smoother experience at both 60hz and 120hz.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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 and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

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

@flutter-dashboard

This comment was marked as outdated.

@knopp knopp changed the title WIP [macOS] Use CVDisplayLink to drive repaint [macOS] Use CVDisplayLink to drive repaint Dec 20, 2023
@knopp knopp force-pushed the macos_display_link branch 2 times, most recently from 9423f12 to e06c2c6 Compare December 20, 2023 19:51
@knopp
Copy link
Member Author

knopp commented Dec 21, 2023

@cbracken, I think this is in good enough shape for review.

@knopp knopp force-pushed the macos_display_link branch 2 times, most recently from 4d508d2 to c579a92 Compare December 25, 2023 13:49
@lesnitsky
Copy link

@knopp is anything blocking this PR?

@knopp
Copy link
Member Author

knopp commented Feb 1, 2024

@knopp is anything blocking this PR?

Not that I know of, possibly a bandwidth issue. @cbracken ?

@loic-sharma
Copy link
Member

@knopp Chris is out sick and may be delayed in reviewing this. Apologies for the delay.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

A few more quick comments.

@@ -1029,6 +1088,13 @@ - (void)engineCallbackOnPreEngineRestart {
}
}

- (void)onVSync:(uintptr_t)baton {
@synchronized(_vsyncWaiters) {
FlutterVSyncWaiter* waiter = [_vsyncWaiters objectForKey:@(kFlutterImplicitViewId)];
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming we'll need to generalise this for multi-views, in which case, you'll want to add a TODO here to wire up the proper view ID with an issue link. You may need to file a new subissue under flutter/flutter#142845 if nothing existing fits.

Copy link
Member Author

@knopp knopp Feb 21, 2024

Choose a reason for hiding this comment

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

I added a TODO for this. Right now it seems a bit unclear how exactly vsync is going to work with multiview. We might not have a viewId available.

At least for the multiview MVP we'll probably use some heuristic for this - i.e. if views are on different displays use waiter for view on primary display, or with display with higher refresh. We'll cross that bridge when we get there, but either way this should be a minor change.

@knopp knopp force-pushed the macos_display_link branch 2 times, most recently from b9c3e77 to 5c2c131 Compare February 26, 2024 13:28
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

Awesome - thanks so much for your patience on this one! Looks great! Ship it! 🚀

if (screen != nil) {
// https://developer.apple.com/documentation/appkit/nsscreen/1388360-devicedescription?language=objc
_display_id = (CGDirectDisplayID)[
[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
Copy link
Member

Choose a reason for hiding this comment

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

Sure would have been nice if they'd provided a const NSString for this key! Thanks for the doc link to explain it.

#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/testing/testing.h"

#import <AppKit/AppKit.h>
Copy link
Member

Choose a reason for hiding this comment

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

nit: standard C/Obj-C headers like this go after the associated header (FlutterDisplayLink.h) but before the local flutter headers.

At some point we'll get round do adding a better header lint, though the associated header is sometimes tricky to figure out.

@knopp knopp merged commit 21474ee into flutter:main Feb 27, 2024
25 checks passed
@knopp knopp deleted the macos_display_link branch February 27, 2024 19:48
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 28, 2024
2461280c38 Roll Fuchsia Linux SDK from JCdhkDSFXzHyPuP4I... to T1xAi_ww_mWEiDkVN... (flutter/engine#51011)
8940ea0887 Code consistency fixes in FlScrollingManager (flutter/engine#50959)
21474ee4a4 [macOS] Use CVDisplayLink to drive repaint (flutter/engine#49159)
6f7b939568 Fail lazily when 1+ Skia gold comparions fail. (flutter/engine#51010)
249daf5512 Adjust Android emulator test timeouts (flutter/engine#51004)
knopp added a commit to knopp/engine that referenced this pull request Feb 29, 2024
cbracken pushed a commit that referenced this pull request Feb 29, 2024
The original PR assumed that `fml::TimePoint` has same base as
`CACurrentMediaTime()`. However due to recent change in Dart SDK that's
no longer true. Dart SDK
[replaced](https://dart-review.googlesource.com/c/sdk/+/348044?tab=comments)
call to `mach_absolute_time` with
`clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)`, while
`CACurrentMediaTime()` corresponds to `CLOCK_UPTIME_RAW`.

This needs to be fixed either in Dart SDK
dart-lang/sdk#55071 or the original PR needs
to be relanded with appropriate conversions.

This reverts commit 21474ee.

*Replace this paragraph with a description of what this PR is changing
or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one
issue.*

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## 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] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [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/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
knopp added a commit to knopp/engine that referenced this pull request Mar 1, 2024
knopp added a commit to knopp/engine that referenced this pull request Mar 4, 2024
@alterhuman
Copy link

Is there any possibility of this getting merged again?

@knopp
Copy link
Member Author

knopp commented Mar 13, 2024

Is there any possibility of this getting merged again?

#51210

@alterhuman
Copy link

@knopp thank you so much for this! Can't wait to see the difference. Very excited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants