diff options
| author | Simon Kallweit <simon.kallweit@gmail.com> | 2024-02-27 00:32:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-26 15:32:03 -0800 |
| commit | 4f03eb9d657fd74da341bb2b0d391c6b855073af (patch) | |
| tree | bd091ec05b0878f92757de8b3ac011b856be9a33 /tools/gfx/apple | |
| parent | ceb87b25b387411dbb7978caf04ecd9e948493e3 (diff) | |
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 <yonghe@outlook.com>
Diffstat (limited to 'tools/gfx/apple')
| -rw-r--r-- | tools/gfx/apple/cocoa-util.h | 5 | ||||
| -rw-r--r-- | tools/gfx/apple/cocoa-util.mm | 26 |
2 files changed, 25 insertions, 6 deletions
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 <Cocoa/Cocoa.h> +#import <QuartzCore/CAMetalLayer.h> 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 |
