[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 4/5] ui/cocoa: Take refresh rate into account
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 4/5] ui/cocoa: Take refresh rate into account |
Date: |
Wed, 13 Jul 2022 00:16:06 +0200 |
From: Akihiko Odaki <akihiko.odaki@gmail.com>
Retrieve 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.
The information will be used as a hint how often the display should
be updated. For example, when we run 30 Hz physical display updates
it is pointless for the guest to update the screen at 60Hz
frequency, the guest can spare some work instead.
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220702142519.12188-1-akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
meson.build | 3 ++-
ui/cocoa.m | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index ad92d288a6..fea3566ea8 100644
--- a/meson.build
+++ b/meson.build
@@ -583,7 +583,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
diff --git a/ui/cocoa.m b/ui/cocoa.m
index e883c7466e..5a8bd5dd84 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -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 {
--
2.36.1
- [PULL 0/5] Darwin patches for 2022-07-12, Philippe Mathieu-Daudé, 2022/07/12
- [PULL 1/5] hvf: Enable RDTSCP support, Philippe Mathieu-Daudé, 2022/07/12
- [PULL 2/5] configure: Restrict TCG to emulation, Philippe Mathieu-Daudé, 2022/07/12
- [PULL 3/5] ui/cocoa: Fix switched_to_fullscreen warning, Philippe Mathieu-Daudé, 2022/07/12
- [PULL 4/5] ui/cocoa: Take refresh rate into account,
Philippe Mathieu-Daudé <=
- [PULL 5/5] avocado: Fix BUILD_DIR if it's equal to SOURCE_DIR, Philippe Mathieu-Daudé, 2022/07/12
- Re: [PULL 0/5] Darwin patches for 2022-07-12, Peter Maydell, 2022/07/14