From be6be5e25e0be6320c72dddc6fc3d5d9384b2261 Mon Sep 17 00:00:00 2001 From: Adam Livesley Date: Tue, 13 Feb 2024 15:48:44 +0000 Subject: [PATCH] vulkan/context: resize context when layout is changed --- video/out/vulkan/context_moltenvk.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/video/out/vulkan/context_moltenvk.m b/video/out/vulkan/context_moltenvk.m index c9c51642505df..01887e195f057 100644 --- a/video/out/vulkan/context_moltenvk.m +++ b/video/out/vulkan/context_moltenvk.m @@ -23,14 +23,36 @@ #include "context.h" #include "utils.h" +@interface MetalLayerDelegate : NSObject +@property (nonatomic, weak) ra_ctx *ra_ctx; +- (id) initWithContext: (ra_ctx*) cxt; +@end + +@implementation MetalLayerDelegate : NSObject + +- (id)initWithContext: (ra_ctx*) ctx +{ + _ra_ctx = ctx; + return self; +} + +- (void)layoutSublayers: (CALayer*) layer +{ + moltenvk_reconfig(_ra_ctx); +} + +@end + struct priv { struct mpvk_ctx vk; CAMetalLayer *layer; + MetalLayerDelegate *delegate; }; static void moltenvk_uninit(struct ra_ctx *ctx) { struct priv *p = ctx->priv; + p->delegate = nil; ra_vk_ctx_uninit(ctx); mpvk_uninit(&p->vk); } @@ -67,6 +89,8 @@ static bool moltenvk_init(struct ra_ctx *ctx) if (!ra_vk_ctx_init(ctx, vk, params, VK_PRESENT_MODE_FIFO_KHR)) goto fail; + p->delegate = [[MetalLayerDelegate alloc] initWithContext: ctx]; + return true; fail: moltenvk_uninit(ctx);