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

Commit 854943d

Browse files
authored
[macOS] Set the display refresh rate (#21095)
Fixes: flutter/flutter#49222
1 parent 0de5c0c commit 854943d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
281281

282282
[self sendUserLocales];
283283
[self updateWindowMetrics];
284+
[self updateDisplayConfig];
284285
return YES;
285286
}
286287

@@ -317,6 +318,31 @@ - (NSOpenGLContext*)resourceContext {
317318
return _resourceContext;
318319
}
319320

321+
- (void)updateDisplayConfig {
322+
if (!_engine) {
323+
return;
324+
}
325+
326+
CVDisplayLinkRef displayLinkRef;
327+
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
328+
CVDisplayLinkCreateWithCGDisplay(mainDisplayID, &displayLinkRef);
329+
CVTime nominal = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLinkRef);
330+
if (!(nominal.flags & kCVTimeIsIndefinite)) {
331+
double refreshRate = static_cast<double>(nominal.timeScale) / nominal.timeValue;
332+
333+
FlutterEngineDisplay display;
334+
display.struct_size = sizeof(display);
335+
display.display_id = mainDisplayID;
336+
display.refresh_rate = round(refreshRate);
337+
338+
std::vector<FlutterEngineDisplay> displays = {display};
339+
FlutterEngineNotifyDisplayUpdate(_engine, kFlutterEngineDisplaysUpdateTypeStartup,
340+
displays.data(), displays.size());
341+
}
342+
343+
CVDisplayLinkRelease(displayLinkRef);
344+
}
345+
320346
- (void)updateWindowMetrics {
321347
if (!_engine) {
322348
return;

0 commit comments

Comments
 (0)