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/platform/apple/cocoa-window.mm | 20 +------------------- tools/platform/window.h | 8 ++++---- 2 files changed, 5 insertions(+), 23 deletions(-) (limited to 'tools/platform') diff --git a/tools/platform/apple/cocoa-window.mm b/tools/platform/apple/cocoa-window.mm index 450087dd2..b985cb4f3 100644 --- a/tools/platform/apple/cocoa-window.mm +++ b/tools/platform/apple/cocoa-window.mm @@ -50,8 +50,6 @@ class CocoaPlatformWindow : public Window public: NSWindow* window; WindowDelegate* delegate; - ContentView* view; - CAMetalLayer* layer; bool shouldClose = false; CocoaPlatformWindow(const WindowDesc& desc); @@ -516,26 +514,14 @@ CocoaPlatformWindow::CocoaPlatformWindow(const WindowDesc& desc) else if (desc.style == WindowStyle::FixedSize) [window setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable]; - // Allocate view - rect = [window backingAlignedRect:rect options:NSAlignAllEdgesOutward]; - view = [[ContentView alloc] initWithPlatformWindow:this]; - [view setHidden:NO]; - [view setNeedsDisplay:YES]; - [view setWantsLayer:YES]; - delegate = [[WindowDelegate alloc] initWithPlatformWindow:this]; [window setDelegate:delegate]; - [window setContentView:view]; NSString* title = [NSString stringWithUTF8String:desc.title]; [window setTitle:title]; [window center]; [window makeKeyAndOrderFront:nil]; - - // Setup layer - layer = [[CAMetalLayer alloc] init]; - [view setLayer:layer]; } CocoaPlatformWindow::~CocoaPlatformWindow() @@ -564,13 +550,9 @@ void CocoaPlatformWindow::close() { [window release]; [delegate release]; - [view release]; - [layer release]; window = nil; delegate = nil; - view = nil; - layer = nil; } bool CocoaPlatformWindow::getFocused() @@ -585,7 +567,7 @@ bool CocoaPlatformWindow::getVisible() WindowHandle CocoaPlatformWindow::getNativeHandle() { - return WindowHandle::fromNSView(view); + return WindowHandle::fromNSWindow(window); } void CocoaPlatformWindow::setText(Slang::String text) diff --git a/tools/platform/window.h b/tools/platform/window.h index 7f78b8af9..efbe139a7 100644 --- a/tools/platform/window.h +++ b/tools/platform/window.h @@ -97,7 +97,7 @@ struct WindowHandle { Unknown, Win32Handle, - NSViewHandle, + NSWindowHandle, XLibHandle, }; Type type; @@ -109,11 +109,11 @@ struct WindowHandle handle.handleValues[0] = (intptr_t)(hwnd); return handle; } - static WindowHandle fromNSView(void* nsview) + static WindowHandle fromNSWindow(void* nswindow) { WindowHandle handle = {}; - handle.type = WindowHandle::Type::NSViewHandle; - handle.handleValues[0] = (intptr_t)(nsview); + handle.type = WindowHandle::Type::NSWindowHandle; + handle.handleValues[0] = (intptr_t)(nswindow); return handle; } static WindowHandle fromXWindow(void* xdisplay, uint32_t xwindow) -- cgit v1.2.3