forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macOS] Use CVDisplayLink to drive repaint (flutter#49159)
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 - [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
- Loading branch information
Showing
23 changed files
with
1,112 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDISPLAYLINK_H_ | ||
#define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDISPLAYLINK_H_ | ||
|
||
#import <AppKit/AppKit.h> | ||
|
||
@protocol FlutterDisplayLinkDelegate <NSObject> | ||
- (void)onDisplayLink:(CFTimeInterval)timestamp targetTimestamp:(CFTimeInterval)targetTimestamp; | ||
@end | ||
|
||
/// Provides notifications of display refresh. | ||
/// | ||
/// Internally FlutterDisplayLink will use at most one CVDisplayLink per | ||
/// screen shared for all views belonging to that screen. This is necessary | ||
/// because each CVDisplayLink comes with its own thread. | ||
@interface FlutterDisplayLink : NSObject | ||
|
||
/// Creates new instance tied to provided NSView. FlutterDisplayLink | ||
/// will track view display changes transparently to synchronize | ||
/// update with display refresh. | ||
/// This function must be called on the main thread. | ||
+ (instancetype)displayLinkWithView:(NSView*)view; | ||
|
||
/// Delegate must be set on main thread. Delegate method will be called on | ||
/// on display link thread. | ||
@property(nonatomic, weak) id<FlutterDisplayLinkDelegate> delegate; | ||
|
||
/// Pauses and resumes the display link. May be called from any thread. | ||
@property(readwrite) BOOL paused; | ||
|
||
/// Returns the nominal refresh period of the display to which the view | ||
/// currently belongs (in seconds). If view does not belong to any display, | ||
/// returns 0. Can be called from any thread. | ||
@property(readonly) CFTimeInterval nominalOutputRefreshPeriod; | ||
|
||
/// Invalidates the display link. Must be called on the main thread. | ||
- (void)invalidate; | ||
|
||
@end | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDISPLAYLINK_H_ |
Oops, something went wrong.