Skip to content

Commit

Permalink
vulkan/context: resize context when layout is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sixones committed Feb 13, 2024
1 parent df257b7 commit be6be5e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions video/out/vulkan/context_moltenvk.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,36 @@
#include "context.h"
#include "utils.h"

@interface MetalLayerDelegate : NSObject<CALayerDelegate>
@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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit be6be5e

Please sign in to comment.