From 4f03eb9d657fd74da341bb2b0d391c6b855073af Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Tue, 27 Feb 2024 00:32:03 +0100 Subject: switch to vkCreateMetalSurfaceEXT and create metal layer in swapchain (#3627) * switch to vkCreateMetalSurfaceEXT and create metal layer in swapchain * fix window content size on macos --------- Co-authored-by: Yong He --- tools/gfx/apple/cocoa-util.h | 5 ++++- tools/gfx/apple/cocoa-util.mm | 26 +++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'tools/gfx/apple') diff --git a/tools/gfx/apple/cocoa-util.h b/tools/gfx/apple/cocoa-util.h index 80467d8a4..565783ee9 100644 --- a/tools/gfx/apple/cocoa-util.h +++ b/tools/gfx/apple/cocoa-util.h @@ -5,7 +5,10 @@ namespace gfx { // Utility functions for Cocoa struct CocoaUtil { - static void getNSViewRectSize(void* nsview, int* widthOut, int* heightOut); + static void getNSWindowContentSize(void* nswindow, int* widthOut, int* heightOut); + + static void* createMetalLayer(void* nswindow); + static void destroyMetalLayer(void* metalLayer); }; diff --git a/tools/gfx/apple/cocoa-util.mm b/tools/gfx/apple/cocoa-util.mm index 45b1c3df0..29c3056a9 100644 --- a/tools/gfx/apple/cocoa-util.mm +++ b/tools/gfx/apple/cocoa-util.mm @@ -1,15 +1,31 @@ #include "cocoa-util.h" #import +#import namespace gfx { -void CocoaUtil::getNSViewRectSize(void* nsview, int* widthOut, int* heightOut) +void CocoaUtil::getNSWindowContentSize(void* nswindow, int* widthOut, int* heightOut) { - NSView* view = (NSView*)nsview; - NSRect rect = [view frame]; - *widthOut = rect.size.width; - *heightOut = rect.size.height; + NSWindow* window = (NSWindow*)nswindow; + const NSRect contentRect = [window.contentView frame]; + *widthOut = contentRect.size.width; + *heightOut = contentRect.size.height; +} + +void* CocoaUtil::createMetalLayer(void* nswindow) +{ + CAMetalLayer *layer = [CAMetalLayer layer]; + NSWindow* window = (NSWindow*)nswindow; + window.contentView.layer = layer; + window.contentView.wantsLayer = YES; + return layer; +} + +void CocoaUtil::destroyMetalLayer(void* metalLayer) +{ + CAMetalLayer* layer = (CAMetalLayer*)metalLayer; + [layer release]; } } \ No newline at end of file -- cgit v1.2.3