Skip to content

Commit 184b026

Browse files
committed
Revert "Revert "[macOS] Use CVDisplayLink to drive repaint (flutter#49159)" (flutter#51095)"
This reverts commit dd3383d.
1 parent 2a5a9a6 commit 184b026

23 files changed

+1112
-36
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36586,6 +36586,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCom
3658636586
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm + ../../../flutter/LICENSE
3658736587
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm + ../../../flutter/LICENSE
3658836588
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h + ../../../flutter/LICENSE
36589+
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLinkTest.mm + ../../../flutter/LICENSE
3658936590
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm + ../../../flutter/LICENSE
3659036591
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.h + ../../../flutter/LICENSE
3659136592
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm + ../../../flutter/LICENSE
@@ -36636,6 +36637,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThr
3663636637
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm + ../../../flutter/LICENSE
3663736638
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizerTest.mm + ../../../flutter/LICENSE
3663836639
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterUmbrellaImportTests.m + ../../../flutter/LICENSE
36640+
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiterTest.mm + ../../../flutter/LICENSE
3663936641
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h + ../../../flutter/LICENSE
3664036642
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm + ../../../flutter/LICENSE
3664136643
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm + ../../../flutter/LICENSE
@@ -39445,6 +39447,9 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompo
3944539447
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm
3944639448
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm
3944739449
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h
39450+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.h
39451+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.mm
39452+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLinkTest.mm
3944839453
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm
3944939454
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.h
3945039455
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm
@@ -39495,6 +39500,9 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThrea
3949539500
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm
3949639501
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizerTest.mm
3949739502
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterUmbrellaImportTests.m
39503+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.h
39504+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.mm
39505+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiterTest.mm
3949839506
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h
3949939507
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm
3950039508
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 / 1'000'000'000.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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDISPLAYLINK_H_
2+
#define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDISPLAYLINK_H_
3+
4+
#import <AppKit/AppKit.h>
5+
6+
@protocol FlutterDisplayLinkDelegate <NSObject>
7+
- (void)onDisplayLink:(CFTimeInterval)timestamp targetTimestamp:(CFTimeInterval)targetTimestamp;
8+
@end
9+
10+
/// Provides notifications of display refresh.
11+
///
12+
/// Internally FlutterDisplayLink will use at most one CVDisplayLink per
13+
/// screen shared for all views belonging to that screen. This is necessary
14+
/// because each CVDisplayLink comes with its own thread.
15+
@interface FlutterDisplayLink : NSObject
16+
17+
/// Creates new instance tied to provided NSView. FlutterDisplayLink
18+
/// will track view display changes transparently to synchronize
19+
/// update with display refresh.
20+
/// This function must be called on the main thread.
21+
+ (instancetype)displayLinkWithView:(NSView*)view;
22+
23+
/// Delegate must be set on main thread. Delegate method will be called on
24+
/// on display link thread.
25+
@property(nonatomic, weak) id<FlutterDisplayLinkDelegate> delegate;
26+
27+
/// Pauses and resumes the display link. May be called from any thread.
28+
@property(readwrite) BOOL paused;
29+
30+
/// Returns the nominal refresh period of the display to which the view
31+
/// currently belongs (in seconds). If view does not belong to any display,
32+
/// returns 0. Can be called from any thread.
33+
@property(readonly) CFTimeInterval nominalOutputRefreshPeriod;
34+
35+
/// Invalidates the display link. Must be called on the main thread.
36+
- (void)invalidate;
37+
38+
@end
39+
40+
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDISPLAYLINK_H_

0 commit comments

Comments
 (0)