Skip to content

Commit

Permalink
mac/vulkan: directly retrieve current render size without caching
Browse files Browse the repository at this point in the history
the render size cached in ctx->vo->dwidth/dheight can be outdated in
some circumstances at the time the context needs resizing. instead use
the current render size.
  • Loading branch information
Akemi authored and jeeb committed Mar 6, 2024
1 parent 6016423 commit 68c61fd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion video/out/mac/common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Common: NSObject {
var log: LogHelper
let queue: DispatchQueue = DispatchQueue(label: "io.mpv.queue")

var window: Window?
@objc var window: Window?
var view: View?
var titleBar: TitleBar?

Expand Down
2 changes: 1 addition & 1 deletion video/out/mac/window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Window: NSWindow, NSWindowDelegate {
let animationLock: NSCondition = NSCondition()

var unfsContentFramePixel: NSRect { get { return convertToBacking(unfsContentFrame ?? NSRect(x: 0, y: 0, width: 160, height: 90)) } }
var framePixel: NSRect { get { return convertToBacking(frame) } }
@objc var framePixel: NSRect { get { return convertToBacking(frame) } }

var keepAspect: Bool = true {
didSet {
Expand Down
13 changes: 1 addition & 12 deletions video/out/mac_common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ class MacCommon: Common {
}
}

func updateRenderSize(_ size: NSSize) {
mpv?.vo.pointee.dwidth = Int32(size.width)
mpv?.vo.pointee.dheight = Int32(size.height)
flagEvents(VO_EVENT_RESIZE | VO_EVENT_EXPOSE)
}

override func displayLinkCallback(_ displayLink: CVDisplayLink,
_ inNow: UnsafePointer<CVTimeStamp>,
_ inOutputTime: UnsafePointer<CVTimeStamp>,
Expand Down Expand Up @@ -144,12 +138,7 @@ class MacCommon: Common {
}

override func windowDidResize() {
guard let window = window else {
log.sendWarning("No window available on window resize event")
return
}

updateRenderSize(window.framePixel.size)
flagEvents(VO_EVENT_RESIZE | VO_EVENT_EXPOSE)
}

override func windowDidChangeScreenProfile() {
Expand Down
9 changes: 8 additions & 1 deletion video/out/vulkan/context_mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ static bool mac_vk_init(struct ra_ctx *ctx)

static bool resize(struct ra_ctx *ctx)
{
return ra_vk_ctx_resize(ctx, ctx->vo->dwidth, ctx->vo->dheight);
struct priv *p = ctx->priv;

if (!p->vo_mac.window) {
return false;
}
CGSize size = p->vo_mac.window.framePixel.size;

return ra_vk_ctx_resize(ctx, (int)size.width, (int)size.height);
}

static bool mac_vk_reconfig(struct ra_ctx *ctx)
Expand Down

0 comments on commit 68c61fd

Please sign in to comment.