ui/cocoa: Take refresh rate into account
PATCH v3 1/1 ui/cocoa: Take refresh rate into account
Retreieve the refresh rate of the display and reflect it with dpy_set_ui_info() and update_displaychangelistener(), allowing the guest and DisplayChangeListener to consume the information.
--- meson.build | 3 ++- ui/cocoa.m | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
meson.build +2 -1
@@ -575,7 +575,8 @@ if get_option('attr').allowed() endif endif -cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa')) +cocoa = dependency('appleframeworks', modules: ['Cocoa', 'CoreVideo'], + required: get_option('cocoa')) if cocoa.found() and get_option('sdl').enabled() error('Cocoa and SDL cannot be enabled at the same time') endif
ui/cocoa.m +12 -0
@@ -561,8 +561,20 @@ - (void) updateUIInfoLocked CGDirectDisplayID display = [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]; NSSize screenSize = [[[self window] screen] frame].size; CGSize screenPhysicalSize = CGDisplayScreenSize(display); + CVDisplayLinkRef displayLink; frameSize = isFullscreen ? screenSize : [self frame].size; + + if (!CVDisplayLinkCreateWithCGDisplay(display, &displayLink)) { + CVTime period = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink); + CVDisplayLinkRelease(displayLink); + if (!(period.flags & kCVTimeIsIndefinite)) { + update_displaychangelistener(&dcl, + 1000 * period.timeValue / period.timeScale); + info.refresh_rate = (int64_t)1000 * period.timeScale / period.timeValue; + } + } + info.width_mm = frameSize.width / screenSize.width * screenPhysicalSize.width; info.height_mm = frameSize.height / screenSize.height * screenPhysicalSize.height; } else {
Signature · 1 line
2.32.1 (Apple Git-133)
Quoted 4 lines · Akihiko Odaki
Retreieve the refresh rate of the display and reflect it with
dpy_set_ui_info()andupdate_displaychangelistener(), allowing the guest and DisplayChangeListener to consume the information.
But why? What goes wrong if we don't bother to do this?
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 4 lines · Akihiko Odaki
Retreieve the refresh rate of the display and reflect it with
dpy_set_ui_info()andupdate_displaychangelistener(), allowing the guest and DisplayChangeListener to consume the information.But why? What goes wrong if we don't bother to do this?
thanks
-- PMM
Regarding dpy_set_ui_info(), it depends on the guest. update_displaychangelistener() would change the frequency of the calls of the DisplayChangeListener.
I think it is obvious that delivering the refresh rate with dpy_set_ui_info() and update_displaychangelistener() makes sense, considering that those functions actually exist. They shouldn't exist at first place if we don't have to bother to do this.
Regards,
Akihiko Odaki
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Akihiko Odaki
Retreieve the refresh rate of the display and reflect it with
dpy_set_ui_info()andupdate_displaychangelistener(), allowing the guest and DisplayChangeListener to consume the information.But why? What goes wrong if we don't bother to do this?
Nothing goes wrong. This provides a hint to the guest how often the display is updated, so the guest has the chance to adapt to that. When we run 30 Hz display updates on the host side it is pointless for the guest to update the screen at 60Hz frequency, the guest can spare some cpu cycles instead.
[ this should be better explained in the commit message ]
take care,
Gerd
Quoted 10 lines · Gerd Hoffmann
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Akihiko Odaki
Retreieve the refresh rate of the display and reflect it with
dpy_set_ui_info()andupdate_displaychangelistener(), allowing the guest and DisplayChangeListener to consume the information.But why? What goes wrong if we don't bother to do this?
Quoted 7 lines
Nothing goes wrong. This provides a hint to the guest how often the display is updated, so the guest has the chance to adapt to that. When we run 30 Hz display updates on the host side it is pointless for the guest to update the screen at 60Hz frequency, the guest can spare some cpu cycles instead.
[ this should be better explained in the commit message ]
Thanks for the explanation.
-- PMM