summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-04-06 23:31:05 +0200
committerder richter <der.richter@gmx.de>2024-04-10 19:14:20 +0200
commitee6794225d2be8cb56afb9ba441a89d5e1319b87 (patch)
tree5e8e61c5e828a87987523422517f6c1e98c99ab5 /video/out
parent6df07ce90c894d561c179090675f30d811f9629b (diff)
downloadmpv-ee6794225d2be8cb56afb9ba441a89d5e1319b87.tar.bz2
mpv-ee6794225d2be8cb56afb9ba441a89d5e1319b87.tar.xz
mac/vulkan: add support for frame timing via presentation feedback
Diffstat (limited to 'video/out')
-rw-r--r--video/out/mac_common.swift20
-rw-r--r--video/out/vulkan/context_mac.m7
2 files changed, 25 insertions, 2 deletions
diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift
index 4551c47d91..f29815d73d 100644
--- a/video/out/mac_common.swift
+++ b/video/out/mac_common.swift
@@ -20,6 +20,7 @@ import Cocoa
class MacCommon: Common {
@objc var layer: MetalLayer?
+ var presentation: Presentation?
var timer: PreciseTimer?
var swapTime: UInt64 = 0
let swapLock: NSCondition = NSCondition()
@@ -30,6 +31,7 @@ class MacCommon: Common {
super.init(option, log)
self.vo = vo
input = InputHelper(vo.pointee.input_ctx, option)
+ presentation = Presentation(common: self)
timer = PreciseTimer(common: self)
DispatchQueue.main.sync {
@@ -89,7 +91,7 @@ class MacCommon: Common {
}
@objc func swapBuffer() {
- if option.mac.macos_render_timer != RENDER_TIMER_SYSTEM {
+ if option.mac.macos_render_timer > RENDER_TIMER_SYSTEM {
swapLock.lock()
while(swapTime < 1) {
swapLock.wait()
@@ -99,6 +101,15 @@ class MacCommon: Common {
}
}
+ @objc func fillVsync(info: UnsafeMutablePointer<vo_vsync_info>) {
+ if option.mac.macos_render_timer != RENDER_TIMER_PRESENTATION_FEEDBACK { return }
+
+ let next = presentation?.next()
+ info.pointee.vsync_duration = next?.duration ?? -1
+ info.pointee.skipped_vsyncs = next?.skipped ?? -1
+ info.pointee.last_queue_display_time = next?.time ?? -1
+ }
+
override func displayLinkCallback(_ displayLink: CVDisplayLink,
_ inNow: UnsafePointer<CVTimeStamp>,
_ inOutputTime: UnsafePointer<CVTimeStamp>,
@@ -112,13 +123,18 @@ class MacCommon: Common {
self.swapLock.unlock()
}
- if option.mac.macos_render_timer != RENDER_TIMER_SYSTEM {
+ if option.mac.macos_render_timer > RENDER_TIMER_SYSTEM {
if let timer = self.timer, option.mac.macos_render_timer == RENDER_TIMER_PRECISE {
timer.scheduleAt(time: inOutputTime.pointee.hostTime, closure: signalSwap)
return kCVReturnSuccess
}
signalSwap()
+ return kCVReturnSuccess
+ }
+
+ if option.mac.macos_render_timer == RENDER_TIMER_PRESENTATION_FEEDBACK {
+ presentation?.add(time: inOutputTime.pointee)
}
return kCVReturnSuccess
diff --git a/video/out/vulkan/context_mac.m b/video/out/vulkan/context_mac.m
index be5c077155..bedd0d4f9e 100644
--- a/video/out/vulkan/context_mac.m
+++ b/video/out/vulkan/context_mac.m
@@ -44,6 +44,12 @@ static void mac_vk_swap_buffers(struct ra_ctx *ctx)
[p->vo_mac swapBuffer];
}
+static void mac_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
+{
+ struct priv *p = ctx->priv;
+ [p->vo_mac fillVsyncWithInfo:info];
+}
+
static bool mac_vk_init(struct ra_ctx *ctx)
{
struct priv *p = ctx->priv = talloc_zero(ctx, struct priv);
@@ -66,6 +72,7 @@ static bool mac_vk_init(struct ra_ctx *ctx)
struct ra_vk_ctx_params params = {
.swap_buffers = mac_vk_swap_buffers,
+ .get_vsync = mac_vk_get_vsync,
};
VkInstance inst = vk->vkinst->instance;