Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4d508d2

Browse files
committed
[macOS] Use CVDisplayLink to drive repaint
1 parent 8b839ed commit 4d508d2

23 files changed

+1081
-36
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6751,6 +6751,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCom
67516751
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm + ../../../flutter/LICENSE
67526752
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm + ../../../flutter/LICENSE
67536753
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h + ../../../flutter/LICENSE
6754+
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLinkTest.mm + ../../../flutter/LICENSE
67546755
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm + ../../../flutter/LICENSE
67556756
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.h + ../../../flutter/LICENSE
67566757
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm + ../../../flutter/LICENSE
@@ -6801,6 +6802,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThr
68016802
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm + ../../../flutter/LICENSE
68026803
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizerTest.mm + ../../../flutter/LICENSE
68036804
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterUmbrellaImportTests.m + ../../../flutter/LICENSE
6805+
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiterTest.mm + ../../../flutter/LICENSE
68046806
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h + ../../../flutter/LICENSE
68056807
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm + ../../../flutter/LICENSE
68066808
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm + ../../../flutter/LICENSE
@@ -9588,6 +9590,9 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompo
95889590
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm
95899591
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm
95909592
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h
9593+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.h
9594+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.mm
9595+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLinkTest.mm
95919596
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm
95929597
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.h
95939598
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm
@@ -9638,6 +9643,9 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThrea
96389643
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm
96399644
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizerTest.mm
96409645
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterUmbrellaImportTests.m
9646+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.h
9647+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.mm
9648+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiterTest.mm
96419649
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h
96429650
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm
96439651
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

shell/platform/darwin/macos/BUILD.gn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ source_set("flutter_framework_source") {
6666
"framework/Source/FlutterCompositor.mm",
6767
"framework/Source/FlutterDartProject.mm",
6868
"framework/Source/FlutterDartProject_Internal.h",
69+
"framework/Source/FlutterDisplayLink.h",
70+
"framework/Source/FlutterDisplayLink.mm",
6971
"framework/Source/FlutterEmbedderKeyResponder.h",
7072
"framework/Source/FlutterEmbedderKeyResponder.mm",
7173
"framework/Source/FlutterEngine.mm",
@@ -101,6 +103,8 @@ source_set("flutter_framework_source") {
101103
"framework/Source/FlutterTextureRegistrar.mm",
102104
"framework/Source/FlutterThreadSynchronizer.h",
103105
"framework/Source/FlutterThreadSynchronizer.mm",
106+
"framework/Source/FlutterVSyncWaiter.h",
107+
"framework/Source/FlutterVSyncWaiter.mm",
104108
"framework/Source/FlutterView.h",
105109
"framework/Source/FlutterView.mm",
106110
"framework/Source/FlutterViewController.mm",
@@ -173,6 +177,7 @@ executable("flutter_desktop_darwin_unittests") {
173177
"framework/Source/FlutterAppDelegateTest.mm",
174178
"framework/Source/FlutterAppLifecycleDelegateTest.mm",
175179
"framework/Source/FlutterChannelKeyResponderTest.mm",
180+
"framework/Source/FlutterDisplayLinkTest.mm",
176181
"framework/Source/FlutterEmbedderExternalTextureTest.mm",
177182
"framework/Source/FlutterEmbedderKeyResponderTest.mm",
178183
"framework/Source/FlutterEngineTest.mm",
@@ -187,6 +192,7 @@ executable("flutter_desktop_darwin_unittests") {
187192
"framework/Source/FlutterTextInputPluginTest.mm",
188193
"framework/Source/FlutterTextInputSemanticsObjectTest.mm",
189194
"framework/Source/FlutterThreadSynchronizerTest.mm",
195+
"framework/Source/FlutterVSyncWaiterTest.mm",
190196
"framework/Source/FlutterViewControllerTest.mm",
191197
"framework/Source/FlutterViewControllerTestUtils.h",
192198
"framework/Source/FlutterViewControllerTestUtils.mm",

shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@
6969
}
7070
}
7171

72-
[view.surfaceManager present:surfaces
73-
notify:^{
74-
PresentPlatformViews(view, layers, layers_count);
75-
}];
72+
CFTimeInterval presentation_time = 0;
73+
74+
if (layers_count > 0 && layers[0]->presentation_time != 0) {
75+
presentation_time = layers[0]->presentation_time / 1000000000.0;
76+
}
77+
78+
[view.surfaceManager presentSurfaces:surfaces
79+
atTime:presentation_time
80+
notify:^{
81+
PresentPlatformViews(view, layers, layers_count);
82+
}];
7683

7784
return true;
7885
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#import <AppKit/AppKit.h>
2+
3+
@protocol FlutterDisplayLinkDelegate <NSObject>
4+
- (void)onDisplayLink:(CFTimeInterval)timestamp targetTimestamp:(CFTimeInterval)targetTimestamp;
5+
@end
6+
7+
/// Provides notifications of display refresh.
8+
///
9+
/// Internally FlutterDisplayLink will use at most one CVDisplayLink per
10+
/// screen shared for all views belonging to that screen. This is necessary
11+
/// because each CVDisplayLink comes with its own thread.
12+
@interface FlutterDisplayLink : NSObject
13+
14+
/// Creates new instance tied to provided NSView. FlutterDisplayLink
15+
/// will track view display changes transparently to synchronize
16+
/// update with display refresh.
17+
/// This function must be called on the main thread.
18+
+ (instancetype)displayLinkWithView:(NSView*)view;
19+
20+
/// Delegate must be set on main thread. Delegate method will be called on
21+
/// on display link thread.
22+
@property(nonatomic, weak) id<FlutterDisplayLinkDelegate> delegate;
23+
24+
/// Pauses and resumes the display link. May be called from any thread.
25+
@property(readwrite) BOOL paused;
26+
27+
/// Returns the nominal refresh period of the display to which the view
28+
/// currently belongs (in seconds). If view does not belong to any display,
29+
/// returns 0. Can be called from any thread.
30+
@property(readonly) CFTimeInterval nominalOutputRefreshPeriod;
31+
32+
/// Invalidates the display link. Must be called on the main thread.
33+
- (void)invalidate;
34+
35+
@end

0 commit comments

Comments
 (0)