From 93b79fac90523f3954212d3e17d2c323878c33a7 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sun, 15 Jul 2018 15:54:36 -0700 Subject: [PATCH 1/8] fix(gfx): Move enum to end to avoid breaking existing configurations * `aspect_ratio_index` relies on the ordinal values not changing --- gfx/video_defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/video_defines.h b/gfx/video_defines.h index 61b09d393a..b3aa82ce43 100644 --- a/gfx/video_defines.h +++ b/gfx/video_defines.h @@ -35,7 +35,6 @@ enum aspect_ratio ASPECT_RATIO_16_9, ASPECT_RATIO_16_10, ASPECT_RATIO_16_15, - ASPECT_RATIO_21_9, ASPECT_RATIO_1_1, ASPECT_RATIO_2_1, ASPECT_RATIO_3_2, @@ -55,6 +54,7 @@ enum aspect_ratio ASPECT_RATIO_SQUARE, ASPECT_RATIO_CORE, ASPECT_RATIO_CUSTOM, + ASPECT_RATIO_21_9, ASPECT_RATIO_END }; From 1264e9c533fdb5c80aff9e7355dfb03eb741f8eb Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sun, 15 Jul 2018 15:56:47 -0700 Subject: [PATCH 2/8] fix(Metal): Use ifdef syntax; add correct default for Metal build --- frontend/drivers/platform_darwin.m | 6 ++++++ ui/drivers/ui_cocoa.m | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index e63bd59056..2e367ec0f7 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -347,9 +347,15 @@ static void frontend_darwin_get_environment_settings(int *argc, char *argv[], #endif strlcat(home_dir_buf, "/RetroArch", sizeof(home_dir_buf)); +#ifdef HAVE_METAL + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER], + home_dir_buf, "shaders_slang", + sizeof(g_defaults.dirs[DEFAULT_DIR_SHADER])); +#else fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER], home_dir_buf, "shaders_glsl", sizeof(g_defaults.dirs[DEFAULT_DIR_SHADER])); +#endif #if TARGET_OS_IPHONE int major, minor; get_ios_version(&major, &minor); diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 05259411e0..bf66477fe6 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -37,7 +37,7 @@ #include "../../retroarch.h" #include "../../tasks/tasks_internal.h" -#if HAVE_METAL +#ifdef HAVE_METAL #import #import #endif From 577d81071eae21541359a3443d7993cb02601162 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sun, 15 Jul 2018 15:58:23 -0700 Subject: [PATCH 3/8] fix(Metal): Cleanup shader logging messages --- gfx/common/metal_common.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index ad433da056..007f451abf 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -1204,7 +1204,7 @@ static vertex_t vertex_bytes[] = { if (lib == nil) { save_msl = true; - RARCH_ERR("Metal]: unable to compile vertex shader: %s\n", err.localizedDescription.UTF8String); + RARCH_ERR("[Metal]: unable to compile vertex shader: %s\n", err.localizedDescription.UTF8String); return NO; } #if DEBUG @@ -1220,7 +1220,7 @@ static vertex_t vertex_bytes[] = { if (lib == nil) { save_msl = true; - RARCH_ERR("Metal]: unable to compile fragment shader: %s\n", err.localizedDescription.UTF8String); + RARCH_ERR("[Metal]: unable to compile fragment shader: %s\n", err.localizedDescription.UTF8String); return NO; } #if DEBUG @@ -1234,7 +1234,8 @@ static vertex_t vertex_bytes[] = { if (err != nil) { save_msl = true; - RARCH_ERR("error creating pipeline state: %s", err.localizedDescription.UTF8String); + RARCH_ERR("[Metal]: error creating pipeline state for pass %d: %s\n", i, + err.localizedDescription.UTF8String); return NO; } @@ -1253,10 +1254,11 @@ static vertex_t vertex_bytes[] = { { if (save_msl) { - RARCH_LOG("[Metal]: saving metal shader files\n"); + NSString *basePath = [[NSString stringWithUTF8String:shader->pass[i].source.path] stringByDeletingPathExtension]; + + RARCH_LOG("[Metal]: saving metal shader files to %s\n", basePath.UTF8String); NSError *err = nil; - NSString *basePath = [[NSString stringWithUTF8String:shader->pass[i].source.path] stringByDeletingPathExtension]; [vs_src writeToFile:[basePath stringByAppendingPathExtension:@"vs.metal"] atomically:NO encoding:NSStringEncodingConversionAllowLossy From 802697fdecfd767f87deaa4e29d31fcbc0b66a7c Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Tue, 17 Jul 2018 20:59:06 -0700 Subject: [PATCH 4/8] fix(Metal): Use textures for pixel conversion --- gfx/common/metal/Context.h | 2 +- gfx/common/metal/Context.m | 34 ++++++++++---- gfx/common/metal/Shaders.metal | 54 ++++++++++----------- gfx/common/metal/TexturedView.m | 42 ++++++----------- gfx/common/metal_common.m | 83 +++++++++++++++------------------ ui/drivers/ui_cocoa.m | 2 + 6 files changed, 102 insertions(+), 115 deletions(-) diff --git a/gfx/common/metal/Context.h b/gfx/common/metal/Context.h index 497da8e44d..62a799a389 100644 --- a/gfx/common/metal/Context.h +++ b/gfx/common/metal/Context.h @@ -52,7 +52,7 @@ typedef struct - (Texture *)newTexture:(struct texture_image)image filter:(enum texture_filter_type)filter; - (id)newTexture:(struct texture_image)image mipmapped:(bool)mipmapped; -- (void)convertFormat:(RPixelFormat)fmt from:(id)src to:(id)dst; +- (void)convertFormat:(RPixelFormat)fmt from:(id)src to:(id)dst; - (id)getStockShader:(int)index blend:(bool)blend; /*! @brief resets the viewport for the main render encoder to the drawable size */ diff --git a/gfx/common/metal/Context.m b/gfx/common/metal/Context.m index f610320c24..70f7f66643 100644 --- a/gfx/common/metal/Context.m +++ b/gfx/common/metal/Context.m @@ -65,7 +65,9 @@ _inflightSemaphore = dispatch_semaphore_create(MAX_INFLIGHT); _device = d; _layer = layer; +#if TARGET_OS_OSX _layer.displaySyncEnabled = YES; +#endif _library = l; _commandQueue = [_device newCommandQueue]; _clearColor = MTLClearColorMake(0, 0, 0, 1); @@ -127,7 +129,16 @@ - (void)setDisplaySyncEnabled:(bool)displaySyncEnabled { +#if TARGET_OS_OSX _layer.displaySyncEnabled = displaySyncEnabled; +#endif +} + +- (bool)displaySyncEnabled +{ +#if TARGET_OS_OSX + return _layer.displaySyncEnabled; +#endif } #pragma mark - shaders @@ -154,11 +165,6 @@ return _states[index][blend ? 1 : 0]; } -- (bool)displaySyncEnabled -{ - return _layer.displaySyncEnabled; -} - - (MTLVertexDescriptor *)_spriteVertexDescriptor { MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; @@ -441,13 +447,13 @@ return _drawable; } -- (void)convertFormat:(RPixelFormat)fmt from:(id)src to:(id)dst +- (void)convertFormat:(RPixelFormat)fmt from:(id)src to:(id)dst { - assert(dst.width * dst.height == src.length / RPixelFormatToBPP(fmt)); + assert(src.width == dst.width && src.height == dst.height); assert(fmt >= 0 && fmt < RPixelFormatCount); Filter *conv = _filters[fmt]; assert(conv != nil); - [conv apply:self.blitCommandBuffer inBuf:src outTex:dst]; + [conv apply:self.blitCommandBuffer in:src out:dst]; } - (id)blitCommandBuffer @@ -615,6 +621,7 @@ static const NSUInteger kConstantAlignment = 4; - (void)commitRanges { +#if TARGET_OS_OSX for (BufferNode *n = _head; n != nil; n = n.next) { if (n.allocated > 0) @@ -622,6 +629,7 @@ static const NSUInteger kConstantAlignment = 4; [n.src didModifyRange:NSMakeRange(0, n.allocated)]; } } +#endif } - (void)discard @@ -635,9 +643,15 @@ static const NSUInteger kConstantAlignment = 4; { bzero(range, sizeof(*range)); +#if TARGET_OS_OSX + MTLResourceOptions opts = MTLResourceStorageModeManaged; +#else + MTLResourceOptions opts = MTLResourceStorageModeShared; +#endif + if (!_head) { - _head = [[BufferNode alloc] initWithBuffer:[_device newBufferWithLength:_blockLen options:MTLResourceStorageModeManaged]]; + _head = [[BufferNode alloc] initWithBuffer:[_device newBufferWithLength:_blockLen options:opts]]; _length += _blockLen; _current = _head; _offset = 0; @@ -659,7 +673,7 @@ static const NSUInteger kConstantAlignment = 4; blockLen = length; } - _current.next = [[BufferNode alloc] initWithBuffer:[_device newBufferWithLength:blockLen options:MTLResourceStorageModeManaged]]; + _current.next = [[BufferNode alloc] initWithBuffer:[_device newBufferWithLength:blockLen options:opts]]; if (!_current.next) return NO; diff --git a/gfx/common/metal/Shaders.metal b/gfx/common/metal/Shaders.metal index c5449b2989..396eafd050 100644 --- a/gfx/common/metal/Shaders.metal +++ b/gfx/common/metal/Shaders.metal @@ -81,38 +81,32 @@ fragment half4 stock_fragment_color(FontFragmentIn in [[ stage_in ]]) #pragma mark - filter kernels -kernel void convert_bgra4444_to_bgra8888(device uint16_t * in [[ buffer(0) ]], - texture2d out [[ texture(0) ]], - uint id [[ thread_position_in_grid ]]) +kernel void convert_bgra4444_to_bgra8888(texture2d in [[ texture(0) ]], + texture2d out [[ texture(1) ]], + uint2 gid [[ thread_position_in_grid ]]) { - uint16_t pix = in[id]; - uchar4 pix2 = uchar4( - extract_bits(pix, 4, 4), - extract_bits(pix, 8, 4), - extract_bits(pix, 12, 4), - extract_bits(pix, 0, 4) - ); - - uint ypos = id / out.get_width(); - uint xpos = id % out.get_width(); - - out.write(half4(pix2) / 15.0, uint2(xpos, ypos)); + ushort pix = in.read(gid).r; + uchar4 pix2 = uchar4( + extract_bits(pix, 4, 4), + extract_bits(pix, 8, 4), + extract_bits(pix, 12, 4), + extract_bits(pix, 0, 4) + ); + + out.write(half4(pix2) / 15.0, gid); } -kernel void convert_rgb565_to_bgra8888(device uint16_t * in [[ buffer(0) ]], - texture2d out [[ texture(0) ]], - uint id [[ thread_position_in_grid ]]) +kernel void convert_rgb565_to_bgra8888(texture2d in [[ texture(0) ]], + texture2d out [[ texture(1) ]], + uint2 gid [[ thread_position_in_grid ]]) { - uint16_t pix = in[id]; - uchar4 pix2 = uchar4( - extract_bits(pix, 11, 5), - extract_bits(pix, 5, 6), - extract_bits(pix, 0, 5), - 0xf - ); - - uint ypos = id / out.get_width(); - uint xpos = id % out.get_width(); - - out.write(half4(pix2) / half4(0x1f, 0x3f, 0x1f, 0xf), uint2(xpos, ypos)); + ushort pix = in.read(gid).r; + uchar4 pix2 = uchar4( + extract_bits(pix, 11, 5), + extract_bits(pix, 5, 6), + extract_bits(pix, 0, 5), + 0xf + ); + + out.write(half4(pix2) / half4(0x1f, 0x3f, 0x1f, 0xf), gid); } diff --git a/gfx/common/metal/TexturedView.m b/gfx/common/metal/TexturedView.m index f89346a654..89859ec2b0 100644 --- a/gfx/common/metal/TexturedView.m +++ b/gfx/common/metal/TexturedView.m @@ -16,8 +16,8 @@ CGRect _frame; NSUInteger _bpp; - id _pixels; // frame buffer in _srcFmt - bool _pixelsDirty; + id _src; // source texture + bool _srcDirty; } - (instancetype)initWithDescriptor:(ViewDescriptor *)d context:(Context *)c @@ -53,7 +53,6 @@ _size = size; - // create new texture { MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm width:(NSUInteger)size.width @@ -65,8 +64,11 @@ if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm) { - _pixels = [_context.device newBufferWithLength:(NSUInteger)(size.width * size.height * 2) - options:MTLResourceStorageModeManaged]; + MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint + width:(NSUInteger)size.width + height:(NSUInteger)size.height + mipmapped:NO]; + _src = [_context.device newTextureWithDescriptor:td]; } } @@ -112,11 +114,11 @@ if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm) return; - if (!_pixelsDirty) + if (!_srcDirty) return; - [_context convertFormat:_format from:_pixels to:_texture]; - _pixelsDirty = NO; + [_context convertFormat:_format from:_src to:_texture]; + _srcDirty = NO; } - (void)drawWithContext:(Context *)ctx @@ -141,26 +143,10 @@ } else { - void *dst = _pixels.contents; - size_t len = (size_t)(_bpp * _size.width); - assert(len <= pitch); // the length can't be larger? - - if (len < pitch) - { - for (int i = 0; i < _size.height; i++) - { - memcpy(dst, src, len); - dst += len; - src += pitch; - } - } - else - { - memcpy(dst, src, _pixels.length); - } - - [_pixels didModifyRange:NSMakeRange(0, _pixels.length)]; - _pixelsDirty = YES; + [_src replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)_size.width, (NSUInteger)_size.height) + mipmapLevel:0 withBytes:src + bytesPerRow:(NSUInteger)(pitch)]; + _srcDirty = YES; } } diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index 007f451abf..f1c146bd40 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -299,30 +299,29 @@ settings_t *settings = config_get_ptr(); if (settings && settings->bools.video_msg_bgcolor_enable) { - int msg_width = + int msg_width = font_driver_get_message_width(NULL, msg, (unsigned)strlen(msg), 1.0f); - - float x = video_info->font_msg_pos_x; - float y = 1.0f - video_info->font_msg_pos_y; - float width = msg_width / (float)_viewport->full_width; - float height = + + float x = video_info->font_msg_pos_x; + float y = 1.0f - video_info->font_msg_pos_y; + float width = msg_width / (float)_viewport->full_width; + float height = settings->floats.video_font_size / (float)_viewport->full_height; y -= height; - - float x2 = 0.005f; /* extend background around text */ - float y2 = 0.005f; - - x -= x2; - y -= y2; - width += x2; - height += y2; - - float r = settings->uints.video_msg_bgcolor_red / 255.0f; - float g = settings->uints.video_msg_bgcolor_green / 255.0f; - float b = settings->uints.video_msg_bgcolor_blue / 255.0f; - float a = settings->floats.video_msg_bgcolor_opacity; + float x2 = 0.005f; /* extend background around text */ + float y2 = 0.005f; + + x -= x2; + y -= y2; + width += x2; + height += y2; + + float r = settings->uints.video_msg_bgcolor_red / 255.0f; + float g = settings->uints.video_msg_bgcolor_green / 255.0f; + float b = settings->uints.video_msg_bgcolor_blue / 255.0f; + float a = settings->floats.video_msg_bgcolor_opacity; [_context resetRenderViewport]; [_context drawQuadX:x y:y w:width h:height r:r g:g b:b a:a]; } @@ -332,7 +331,12 @@ - (void)_beginFrame { + video_viewport_t vp = *_viewport; video_driver_update_viewport(_viewport, NO, _keepAspect); + if (memcmp(&vp, _viewport, sizeof(vp)) != 0) + { + _context.viewport = _viewport; + } [_context begin]; [self _updateUniforms]; } @@ -546,8 +550,8 @@ typedef struct MTLALIGN(16) CGRect _frame; NSUInteger _bpp; - id _pixels; // frame buffer in _srcFmt - bool _pixelsDirty; + id _src; // src texture + bool _srcDirty; id _samplers[RARCH_FILTER_MAX][RARCH_WRAP_MAX]; struct video_shader *_shader; @@ -655,8 +659,11 @@ typedef struct MTLALIGN(16) if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm) { - _pixels = [_context.device newBufferWithLength:(NSUInteger)(size.width * size.height * 2) - options:MTLResourceStorageModeManaged]; + MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint + width:(NSUInteger)size.width + height:(NSUInteger)size.height + mipmapped:NO]; + _src = [_context.device newTextureWithDescriptor:td]; } } @@ -702,11 +709,11 @@ typedef struct MTLALIGN(16) if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm) return; - if (!_pixelsDirty) + if (!_srcDirty) return; - [_context convertFormat:_format from:_pixels to:_texture]; - _pixelsDirty = NO; + [_context convertFormat:_format from:_src to:_texture]; + _srcDirty = NO; } - (void)_updateHistory @@ -778,26 +785,10 @@ typedef struct MTLALIGN(16) } else { - void *dst = _pixels.contents; - size_t len = (size_t)(_bpp * _size.width); - assert(len <= pitch); // the length can't be larger? - - if (len < pitch) - { - for (int i = 0; i < _size.height; i++) - { - memcpy(dst, src, len); - dst += len; - src += pitch; - } - } - else - { - memcpy(dst, src, _pixels.length); - } - - [_pixels didModifyRange:NSMakeRange(0, _pixels.length)]; - _pixelsDirty = YES; + [_src replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)_size.width, (NSUInteger)_size.height) + mipmapLevel:0 withBytes:src + bytesPerRow:(NSUInteger)(pitch)]; + _srcDirty = YES; } } diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index bf66477fe6..5de129189a 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -297,6 +297,8 @@ static char** waiting_argv; [self performSelectorOnMainThread:@selector(rarch_main) withObject:nil waitUntilDone:NO]; } +#pragma mark - ApplePlatform + - (void)setViewType:(apple_view_type_t)vt { if (vt == _vt) { return; From 6b7572d166621d6dec4b19e8687cd7177b12c83a Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sat, 1 Sep 2018 16:12:43 -0700 Subject: [PATCH 5/8] fix(macOS): Fix stack overflow when raising Metal shader load event --- ui/drivers/ui_cocoa.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 5de129189a..aee410946e 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -741,7 +741,7 @@ static void *ui_companion_cocoa_init(void) static void ui_companion_cocoa_event_command(void *data, enum event_command cmd) { (void)data; - command_event(cmd, NULL); + (void)cmd; } static void ui_companion_cocoa_notify_list_pushed(void *data, From eadc3f4a918d507324d720c25e2949fa0c501907 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sat, 1 Sep 2018 16:13:23 -0700 Subject: [PATCH 6/8] fix(Metal): Fix SIGFAULT if any attribute is 0 --- gfx/common/metal/Context.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gfx/common/metal/Context.m b/gfx/common/metal/Context.m index 70f7f66643..021de465d9 100644 --- a/gfx/common/metal/Context.m +++ b/gfx/common/metal/Context.m @@ -382,7 +382,7 @@ { assert(filter >= TEXTURE_FILTER_LINEAR && filter <= TEXTURE_FILTER_MIPMAP_NEAREST); - if (!image.pixels && !image.width && !image.height) + if (!image.pixels || !image.width || !image.height) { /* Create a dummy texture instead. */ #define T0 0xff000000u @@ -403,6 +403,7 @@ image.pixels = (uint32_t *)checkerboard; image.width = 8; image.height = 8; + filter = TEXTURE_FILTER_MIPMAP_NEAREST; } BOOL mipmapped = filter == TEXTURE_FILTER_MIPMAP_LINEAR || filter == TEXTURE_FILTER_MIPMAP_NEAREST; From 611e4846338d1d9428d5343949374ddbfac68736 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sun, 2 Sep 2018 12:49:44 -0700 Subject: [PATCH 7/8] fix(xmb): Fix buffer overflow --- menu/drivers/xmb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index c97d052893..a79d783c6d 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2007,7 +2007,8 @@ static void xmb_context_reset_horizontal_list( { struct texture_image ti; - char sysname[256]; + char *sysname = (char*) + malloc(PATH_MAX_LENGTH * sizeof(char)); char *iconpath = (char*) malloc(PATH_MAX_LENGTH * sizeof(char)); char *texturepath = (char*) @@ -2018,7 +2019,8 @@ static void xmb_context_reset_horizontal_list( iconpath[0] = sysname[0] = texturepath[0] = content_texturepath[0] = '\0'; - fill_pathname_base_noext(sysname, path, sizeof(sysname)); + fill_pathname_base_noext(sysname, path, + PATH_MAX_LENGTH * sizeof(char)); fill_pathname_application_special(iconpath, PATH_MAX_LENGTH * sizeof(char), @@ -2080,6 +2082,7 @@ static void xmb_context_reset_horizontal_list( image_texture_free(&ti); } + free(sysname); free(iconpath); free(texturepath); free(content_texturepath); From f1ad1ff4447cc319bba5fd4a0571569aff6db17a Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sun, 2 Sep 2018 12:51:34 -0700 Subject: [PATCH 8/8] fix(Metal): Fix invalid selector Removed selector logic and wrapped in HAVE_METAL, given this is only called when Metal is enabled. --- ui/drivers/ui_cocoa.m | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index aee410946e..159395497f 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -361,19 +361,16 @@ static char** waiting_argv; return [NSApp isActive]; } -#define NS_FULLSCREEN_WINDOW_MASK (1 << 14) - - (void)setVideoMode:(gfx_ctx_mode_t)mode { - BOOL isFullScreen = (self.window.styleMask & NS_FULLSCREEN_WINDOW_MASK) == NS_FULLSCREEN_WINDOW_MASK; - SEL fselector = NSSelectorFromString(BOXSTRING("toggleFullScreen")); - - if (mode.fullscreen && !isFullScreen && [self.window respondsToSelector:fselector]) +#ifdef HAVE_METAL + BOOL isFullScreen = (self.window.styleMask & NSFullScreenWindowMask) == NSFullScreenWindowMask; + if (mode.fullscreen && !isFullScreen) { [self.window toggleFullScreen:self]; return; } - if (!mode.fullscreen && isFullScreen && [self.window respondsToSelector:fselector]) + if (!mode.fullscreen && isFullScreen) { [self.window toggleFullScreen:self]; } @@ -384,6 +381,7 @@ static char** waiting_argv; [self.window setContentSize:NSMakeSize(mode.width-1, mode.height)]; } [self.window setContentSize:NSMakeSize(mode.width, mode.height)]; +#endif } - (void)setCursorVisible:(bool)v {