diff options
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 |
