macOS: always use Objective-C ARC (automatic ref counting).

Change Cocoa SDL_VideoData and SDL_WindowData implementations from C structs to Objective-C objects, since bridging between C and ObjC is easier that way.
This commit is contained in:
Alex Szpakowski 2022-05-07 21:57:23 -03:00 committed by Sam Lantinga
parent d35c737f1c
commit ec8fa57750
19 changed files with 395 additions and 468 deletions

View File

@ -2902,7 +2902,7 @@ if(ANDROID)
target_include_directories(sdl-build-options INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures") target_include_directories(sdl-build-options INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures")
endif() endif()
if(IOS OR TVOS) if(APPLE)
target_compile_options(sdl-build-options INTERFACE "-fobjc-arc") target_compile_options(sdl-build-options INTERFACE "-fobjc-arc")
endif() endif()

View File

@ -3469,13 +3469,13 @@
F395C1A22569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; }; F395C1A22569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; };
F395C1A32569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; }; F395C1A32569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; };
F395C1A42569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; }; F395C1A42569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; };
F395C1B12569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; F395C1B12569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B22569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; }; F395C1B22569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B32569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; }; F395C1B32569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B42569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; F395C1B42569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B52569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; }; F395C1B52569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B62569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; }; F395C1B62569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B72569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; F395C1B72569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B82569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; }; F395C1B82569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1B92569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; }; F395C1B92569C6A000942BFF /* SDL_mfijoystick.m in Sources */ = {isa = PBXBuildFile; fileRef = F395C1AF2569C6A000942BFF /* SDL_mfijoystick.m */; };
F395C1BA2569C6A000942BFF /* SDL_mfijoystick_c.h in Headers */ = {isa = PBXBuildFile; fileRef = F395C1B02569C6A000942BFF /* SDL_mfijoystick_c.h */; }; F395C1BA2569C6A000942BFF /* SDL_mfijoystick_c.h in Headers */ = {isa = PBXBuildFile; fileRef = F395C1B02569C6A000942BFF /* SDL_mfijoystick_c.h */; };
@ -9188,6 +9188,7 @@
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES; CLANG_WARN_COMMA = YES;
@ -9273,6 +9274,7 @@
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES; CLANG_WARN_COMMA = YES;

View File

@ -4041,6 +4041,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../SDL/build/$(CONFIGURATION)", "$(SRCROOT)/../SDL/build/$(CONFIGURATION)",
"$(HOME)/Library/Frameworks", "$(HOME)/Library/Frameworks",
@ -4168,6 +4169,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../SDL/build/$(CONFIGURATION)", "$(SRCROOT)/../SDL/build/$(CONFIGURATION)",
"$(HOME)/Library/Frameworks", "$(HOME)/Library/Frameworks",

View File

@ -142,24 +142,6 @@ typedef struct METAL_ShaderPipelines
@end @end
@implementation METAL_RenderData @implementation METAL_RenderData
#if !__has_feature(objc_arc)
- (void)dealloc
{
[_mtldevice release];
[_mtlcmdqueue release];
[_mtlcmdbuffer release];
[_mtlcmdencoder release];
[_mtllibrary release];
[_mtlbackbuffer release];
[_mtlsamplernearest release];
[_mtlsamplerlinear release];
[_mtlbufconstants release];
[_mtlbufquadindices release];
[_mtllayer release];
[_mtlpassdesc release];
[super dealloc];
}
#endif
@end @end
@interface METAL_TextureData : NSObject @interface METAL_TextureData : NSObject
@ -178,16 +160,6 @@ typedef struct METAL_ShaderPipelines
@end @end
@implementation METAL_TextureData @implementation METAL_TextureData
#if !__has_feature(objc_arc)
- (void)dealloc
{
[_mtltexture release];
[_mtltexture_uv release];
[_mtlsampler release];
[_lockedbuffer release];
[super dealloc];
}
#endif
@end @end
static int static int
@ -342,13 +314,6 @@ MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
METAL_PipelineState *states = SDL_realloc(cache->states, (cache->count + 1) * sizeof(pipeline)); METAL_PipelineState *states = SDL_realloc(cache->states, (cache->count + 1) * sizeof(pipeline));
#if !__has_feature(objc_arc)
[mtlpipedesc release]; // !!! FIXME: can these be reused for each creation, or does the pipeline obtain it?
[mtlvertfn release];
[mtlfragfn release];
[state release];
#endif
if (states) { if (states) {
states[cache->count++] = pipeline; states[cache->count++] = pipeline;
cache->states = states; cache->states = states;
@ -632,9 +597,6 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (yuv || nv12) { if (yuv || nv12) {
mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc]; mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
if (mtltexture_uv == nil) { if (mtltexture_uv == nil) {
#if !__has_feature(objc_arc)
[mtltexture release];
#endif
return SDL_SetError("Texture allocation failed"); return SDL_SetError("Texture allocation failed");
} }
} }
@ -677,12 +639,6 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
#endif #endif
texture->driverdata = (void*)CFBridgingRetain(texturedata); texture->driverdata = (void*)CFBridgingRetain(texturedata);
#if !__has_feature(objc_arc)
[texturedata release];
[mtltexture release];
[mtltexture_uv release];
#endif
return 0; return 0;
}} }}
@ -742,10 +698,6 @@ METAL_UpdateTextureInternal(SDL_Renderer * renderer, METAL_TextureData *textured
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
#if !__has_feature(objc_arc)
[stagingtex autorelease];
#endif
METAL_UploadTextureData(stagingtex, stagingrect, 0, pixels, pitch); METAL_UploadTextureData(stagingtex, stagingrect, 0, pixels, pitch);
if (data.mtlcmdencoder != nil) { if (data.mtlcmdencoder != nil) {
@ -917,11 +869,6 @@ METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
texturedata.lockedbuffer = lockedbuffer; texturedata.lockedbuffer = lockedbuffer;
*pixels = [lockedbuffer contents]; *pixels = [lockedbuffer contents];
/* METAL_TextureData.lockedbuffer retains. */
#if !__has_feature(objc_arc)
[lockedbuffer release];
#endif
return 0; return 0;
}} }}
@ -1209,13 +1156,8 @@ METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
typedef struct typedef struct
{ {
#if __has_feature(objc_arc)
__unsafe_unretained id<MTLRenderPipelineState> pipeline; __unsafe_unretained id<MTLRenderPipelineState> pipeline;
__unsafe_unretained id<MTLBuffer> vertex_buffer; __unsafe_unretained id<MTLBuffer> vertex_buffer;
#else
id<MTLRenderPipelineState> pipeline;
id<MTLBuffer> vertex_buffer;
#endif
size_t constants_offset; size_t constants_offset;
SDL_Texture *texture; SDL_Texture *texture;
SDL_bool cliprect_dirty; SDL_bool cliprect_dirty;
@ -1365,9 +1307,6 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
* TODO: this buffer is also used for constants. Is performance still * TODO: this buffer is also used for constants. Is performance still
* good for those, or should we have a managed buffer for them? */ * good for those, or should we have a managed buffer for them? */
mtlbufvertex = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModeShared]; mtlbufvertex = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModeShared];
#if !__has_feature(objc_arc)
[mtlbufvertex autorelease];
#endif
mtlbufvertex.label = @"SDL vertex data"; mtlbufvertex.label = @"SDL vertex data";
SDL_memcpy([mtlbufvertex contents], vertices, vertsize); SDL_memcpy([mtlbufvertex contents], vertices, vertsize);
@ -1711,9 +1650,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
} }
if (view == NULL) { if (view == NULL) {
#if !__has_feature(objc_arc)
[mtldevice release];
#endif
SDL_free(renderer); SDL_free(renderer);
if (changed_window) { if (changed_window) {
SDL_RecreateWindow(window, window_flags); SDL_RecreateWindow(window, window_flags);
@ -1725,9 +1661,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
data = [[METAL_RenderData alloc] init]; data = [[METAL_RenderData alloc] init];
if (data == nil) { if (data == nil) {
#if !__has_feature(objc_arc)
[mtldevice release];
#endif
/* Release the metal view instead of destroying it, /* Release the metal view instead of destroying it,
in case we want to use it later (recreating the renderer) in case we want to use it later (recreating the renderer)
*/ */
@ -1746,7 +1679,7 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
data.mtlview = view; data.mtlview = view;
#ifdef __MACOSX__ #ifdef __MACOSX__
layer = (CAMetalLayer *)[(NSView *)view layer]; layer = (CAMetalLayer *)[(__bridge NSView *)view layer];
#else #else
layer = (CAMetalLayer *)[(__bridge UIView *)view layer]; layer = (CAMetalLayer *)[(__bridge UIView *)view layer];
#endif #endif
@ -1771,9 +1704,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
id<MTLLibrary> mtllibrary = [data.mtldevice newLibraryWithData:mtllibdata error:&err]; id<MTLLibrary> mtllibrary = [data.mtldevice newLibraryWithData:mtllibdata error:&err];
data.mtllibrary = mtllibrary; data.mtllibrary = mtllibrary;
SDL_assert(err == nil); SDL_assert(err == nil);
#if !__has_feature(objc_arc)
dispatch_release(mtllibdata);
#endif
data.mtllibrary.label = @"SDL Metal renderer shader library"; data.mtllibrary.label = @"SDL Metal renderer shader library";
/* Do some shader pipeline state loading up-front rather than on demand. */ /* Do some shader pipeline state loading up-front rather than on demand. */
@ -1831,9 +1761,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
}; };
id<MTLBuffer> mtlbufconstantstaging = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModeShared]; id<MTLBuffer> mtlbufconstantstaging = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModeShared];
#if !__has_feature(objc_arc)
[mtlbufconstantstaging autorelease];
#endif
char *constantdata = [mtlbufconstantstaging contents]; char *constantdata = [mtlbufconstantstaging contents];
SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform)); SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform));
@ -1845,9 +1772,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
int quadcount = UINT16_MAX / 4; int quadcount = UINT16_MAX / 4;
size_t indicessize = sizeof(UInt16) * quadcount * 6; size_t indicessize = sizeof(UInt16) * quadcount * 6;
id<MTLBuffer> mtlbufquadindicesstaging = [data.mtldevice newBufferWithLength:indicessize options:MTLResourceStorageModeShared]; id<MTLBuffer> mtlbufquadindicesstaging = [data.mtldevice newBufferWithLength:indicessize options:MTLResourceStorageModeShared];
#if !__has_feature(objc_arc)
[mtlbufquadindicesstaging autorelease];
#endif
/* Quads in the following vertex order (matches the FillRects vertices): /* Quads in the following vertex order (matches the FillRects vertices):
* 1---3 * 1---3
@ -1965,18 +1889,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->info.max_texture_width = maxtexsize; renderer->info.max_texture_width = maxtexsize;
renderer->info.max_texture_height = maxtexsize; renderer->info.max_texture_height = maxtexsize;
#if !__has_feature(objc_arc)
[mtlcmdqueue release];
[mtllibrary release];
[samplerdesc release];
[mtlsamplernearest release];
[mtlsamplerlinear release];
[mtlbufconstants release];
[mtlbufquadindices release];
[data release];
[mtldevice release];
#endif
return renderer; return renderer;
}} }}

View File

@ -24,12 +24,12 @@
#define SDL_cocoaclipboard_h_ #define SDL_cocoaclipboard_h_
/* Forward declaration */ /* Forward declaration */
struct SDL_VideoData; @class SDL_VideoData;
extern int Cocoa_SetClipboardText(_THIS, const char *text); extern int Cocoa_SetClipboardText(_THIS, const char *text);
extern char *Cocoa_GetClipboardText(_THIS); extern char *Cocoa_GetClipboardText(_THIS);
extern SDL_bool Cocoa_HasClipboardText(_THIS); extern SDL_bool Cocoa_HasClipboardText(_THIS);
extern void Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data); extern void Cocoa_CheckClipboardUpdate(SDL_VideoData * data);
#endif /* SDL_cocoaclipboard_h_ */ #endif /* SDL_cocoaclipboard_h_ */

View File

@ -29,7 +29,7 @@ int
Cocoa_SetClipboardText(_THIS, const char *text) Cocoa_SetClipboardText(_THIS, const char *text)
{ @autoreleasepool { @autoreleasepool
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
NSPasteboard *pasteboard; NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString; NSString *format = NSPasteboardTypeString;
NSString *nsstr = [NSString stringWithUTF8String:text]; NSString *nsstr = [NSString stringWithUTF8String:text];
@ -38,7 +38,7 @@ Cocoa_SetClipboardText(_THIS, const char *text)
} }
pasteboard = [NSPasteboard generalPasteboard]; pasteboard = [NSPasteboard generalPasteboard];
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; data.clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
[pasteboard setString:nsstr forType:format]; [pasteboard setString:nsstr forType:format];
return 0; return 0;
@ -86,7 +86,7 @@ Cocoa_HasClipboardText(_THIS)
} }
void void
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data) Cocoa_CheckClipboardUpdate(SDL_VideoData * data)
{ @autoreleasepool { @autoreleasepool
{ {
NSPasteboard *pasteboard; NSPasteboard *pasteboard;
@ -94,11 +94,11 @@ Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
pasteboard = [NSPasteboard generalPasteboard]; pasteboard = [NSPasteboard generalPasteboard];
count = [pasteboard changeCount]; count = [pasteboard changeCount];
if (count != data->clipboard_count) { if (count != data.clipboard_count) {
if (data->clipboard_count) { if (data.clipboard_count) {
SDL_SendClipboardUpdate(); SDL_SendClipboardUpdate();
} }
data->clipboard_count = count; data.clipboard_count = count;
} }
}} }}

View File

@ -45,7 +45,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->windows) { if (device && device->windows) {
for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) { for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = ((SDL_WindowData *) sdlwindow->driverdata)->nswindow; NSWindow *nswindow = ((__bridge SDL_WindowData *) sdlwindow->driverdata).nswindow;
if (win == nswindow) if (win == nswindow)
return sdlwindow; return sdlwindow;
} }
@ -121,7 +121,6 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
[NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState", [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
nil]; nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[appDefaults release];
} }
@end // SDLApplication @end // SDLApplication
@ -182,8 +181,6 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
removeEventHandlerForEventClass:kInternetEventClass removeEventHandlerForEventClass:kInternetEventClass
andEventID:kAEGetURL]; andEventID:kAEGetURL];
} }
[super dealloc];
} }
- (void)windowWillClose:(NSNotification *)notification; - (void)windowWillClose:(NSNotification *)notification;
@ -374,9 +371,6 @@ CreateApplicationMenus(void)
/* Create the main menu bar */ /* Create the main menu bar */
[NSApp setMainMenu:mainMenu]; [NSApp setMainMenu:mainMenu];
[mainMenu release]; /* we're done with it, let NSApp own it. */
mainMenu = nil;
/* Create the application menu */ /* Create the application menu */
appName = GetApplicationName(); appName = GetApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""]; appleMenu = [[NSMenu alloc] initWithTitle:@""];
@ -396,7 +390,6 @@ CreateApplicationMenus(void)
[menuItem setSubmenu:serviceMenu]; [menuItem setSubmenu:serviceMenu];
[NSApp setServicesMenu:serviceMenu]; [NSApp setServicesMenu:serviceMenu];
[serviceMenu release];
[appleMenu addItem:[NSMenuItem separatorItem]]; [appleMenu addItem:[NSMenuItem separatorItem]];
@ -417,12 +410,9 @@ CreateApplicationMenus(void)
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu]; [menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem]; [[NSApp mainMenu] addItem:menuItem];
[menuItem release];
/* Tell the application object that this is now the application menu */ /* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu]; [NSApp setAppleMenu:appleMenu];
[appleMenu release];
/* Create the window menu */ /* Create the window menu */
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
@ -442,18 +432,15 @@ CreateApplicationMenus(void)
menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"]; menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand]; [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
[windowMenu addItem:menuItem]; [windowMenu addItem:menuItem];
[menuItem release];
} }
/* Put menu into the menubar */ /* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[menuItem setSubmenu:windowMenu]; [menuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:menuItem]; [[NSApp mainMenu] addItem:menuItem];
[menuItem release];
/* Tell the application object that this is now the window menu */ /* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu]; [NSApp setWindowsMenu:windowMenu];
[windowMenu release];
} }
void void
@ -576,7 +563,7 @@ Cocoa_PumpEvents(_THIS)
void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window) void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
{ @autoreleasepool { @autoreleasepool
{ {
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
location: NSMakePoint(0,0) location: NSMakePoint(0,0)
@ -595,15 +582,15 @@ void
Cocoa_SuspendScreenSaver(_THIS) Cocoa_SuspendScreenSaver(_THIS)
{ @autoreleasepool { @autoreleasepool
{ {
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata;
if (!data->screensaver_use_iopm) { if (!data.screensaver_use_iopm) {
return; return;
} }
if (data->screensaver_assertion) { if (data.screensaver_assertion) {
IOPMAssertionRelease(data->screensaver_assertion); IOPMAssertionRelease(data.screensaver_assertion);
data->screensaver_assertion = 0; data.screensaver_assertion = kIOPMNullAssertionID;
} }
if (_this->suspend_screensaver) { if (_this->suspend_screensaver) {
@ -612,11 +599,13 @@ Cocoa_SuspendScreenSaver(_THIS)
* seen by OS X power users. there's an additional optional human-readable * seen by OS X power users. there's an additional optional human-readable
* (localized) reason parameter which we don't set. * (localized) reason parameter which we don't set.
*/ */
IOPMAssertionID assertion = kIOPMNullAssertionID;
NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"]; NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep, IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
(CFStringRef) name, (__bridge CFStringRef) name,
NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, 0, NULL,
&data->screensaver_assertion); &assertion);
data.screensaver_assertion = assertion;
} }
}} }}

View File

@ -104,8 +104,7 @@
} }
if (_markedText != aString) { if (_markedText != aString) {
[_markedText release]; _markedText = aString;
_markedText = [aString retain];
} }
_selectedRange = selectedRange; _selectedRange = selectedRange;
@ -120,7 +119,6 @@
- (void)unmarkText - (void)unmarkText
{ {
[_markedText release];
_markedText = nil; _markedText = nil;
SDL_SendEditingText("", 0, 0); SDL_SendEditingText("", 0, 0);
@ -381,14 +379,14 @@ DoSidedModifiers(unsigned short scancode,
static void static void
HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags) HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (modifierFlags == data->modifierFlags) { if (modifierFlags == data.modifierFlags) {
return; return;
} }
DoSidedModifiers(scancode, data->modifierFlags, modifierFlags); DoSidedModifiers(scancode, data.modifierFlags, modifierFlags);
data->modifierFlags = modifierFlags; data.modifierFlags = modifierFlags;
} }
static void static void
@ -402,10 +400,10 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
/* See if the keymap needs to be updated */ /* See if the keymap needs to be updated */
key_layout = TISCopyCurrentKeyboardLayoutInputSource(); key_layout = TISCopyCurrentKeyboardLayoutInputSource();
if (key_layout == data->key_layout) { if (key_layout == data.key_layout) {
return; return;
} }
data->key_layout = key_layout; data.key_layout = key_layout;
SDL_GetDefaultKeymap(keymap); SDL_GetDefaultKeymap(keymap);
@ -461,7 +459,7 @@ cleanup:
void void
Cocoa_InitKeyboard(_THIS) Cocoa_InitKeyboard(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
UpdateKeymap(data, SDL_FALSE); UpdateKeymap(data, SDL_FALSE);
@ -473,19 +471,19 @@ Cocoa_InitKeyboard(_THIS)
SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option"); SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command"); SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
data->modifierFlags = (unsigned int)[NSEvent modifierFlags]; data.modifierFlags = (unsigned int)[NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0); SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) != 0);
} }
void void
Cocoa_StartTextInput(_THIS) Cocoa_StartTextInput(_THIS)
{ @autoreleasepool { @autoreleasepool
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus(); SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow = nil; NSWindow *nswindow = nil;
if (window) { if (window) {
nswindow = ((SDL_WindowData*)window->driverdata)->nswindow; nswindow = ((__bridge SDL_WindowData*)window->driverdata).nswindow;
} }
NSView *parentView = [nswindow contentView]; NSView *parentView = [nswindow contentView];
@ -495,16 +493,16 @@ Cocoa_StartTextInput(_THIS)
* than one copy. When we switched to another window and requesting for * than one copy. When we switched to another window and requesting for
* text input, simply remove the field editor from its superview then add * text input, simply remove the field editor from its superview then add
* it to the front most window's content view */ * it to the front most window's content view */
if (!data->fieldEdit) { if (!data.fieldEdit) {
data->fieldEdit = data.fieldEdit =
[[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)]; [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
} }
if (![[data->fieldEdit superview] isEqual:parentView]) { if (![[data.fieldEdit superview] isEqual:parentView]) {
/* DEBUG_IME(@"add fieldEdit to window contentView"); */ /* DEBUG_IME(@"add fieldEdit to window contentView"); */
[data->fieldEdit removeFromSuperview]; [data.fieldEdit removeFromSuperview];
[parentView addSubview: data->fieldEdit]; [parentView addSubview: data.fieldEdit];
[nswindow makeFirstResponder: data->fieldEdit]; [nswindow makeFirstResponder: data.fieldEdit];
} }
}} }}
@ -512,32 +510,31 @@ void
Cocoa_StopTextInput(_THIS) Cocoa_StopTextInput(_THIS)
{ @autoreleasepool { @autoreleasepool
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (data && data->fieldEdit) { if (data && data.fieldEdit) {
[data->fieldEdit removeFromSuperview]; [data.fieldEdit removeFromSuperview];
[data->fieldEdit release]; data.fieldEdit = nil;
data->fieldEdit = nil;
} }
}} }}
void void
Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect) Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (!rect) { if (!rect) {
SDL_InvalidParamError("rect"); SDL_InvalidParamError("rect");
return; return;
} }
[data->fieldEdit setInputRect:rect]; [data.fieldEdit setInputRect:rect];
} }
void void
Cocoa_HandleKeyEvent(_THIS, NSEvent *event) Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{ {
SDL_VideoData *data = _this ? ((SDL_VideoData *) _this->driverdata) : NULL; SDL_VideoData *data = _this ? ((__bridge SDL_VideoData *) _this->driverdata) : nil;
if (!data) { if (!data) {
return; /* can happen when returning from fullscreen Space on shutdown */ return; /* can happen when returning from fullscreen Space on shutdown */
} }
@ -575,7 +572,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
#endif #endif
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
/* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */ /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
[data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]]; [data.fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
#if 0 #if 0
text = [[event characters] UTF8String]; text = [[event characters] UTF8String];
if(text && *text) { if(text && *text) {

View File

@ -45,9 +45,9 @@
/* Retain the NSWindow because we'll show the alert later on the main thread */ /* Retain the NSWindow because we'll show the alert later on the main thread */
if (window) { if (window) {
nswindow = [((SDL_WindowData *) window->driverdata)->nswindow retain]; nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
} else { } else {
nswindow = NULL; nswindow = nil;
} }
} }
@ -60,7 +60,7 @@
#ifdef MAC_OS_X_VERSION_10_9 #ifdef MAC_OS_X_VERSION_10_9
if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) { if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
[alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) { [alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
clicked = returnCode; self->clicked = returnCode;
}]; }];
} else } else
#endif #endif
@ -75,7 +75,7 @@
SDL_Delay(100); SDL_Delay(100);
} }
[nswindow release]; nswindow = nil;
} else { } else {
clicked = [alert runModal]; clicked = [alert runModal];
} }
@ -94,7 +94,7 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
{ {
Cocoa_RegisterApp(); Cocoa_RegisterApp();
NSAlert* alert = [[[NSAlert alloc] init] autorelease]; NSAlert* alert = [[NSAlert alloc] init];
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) { if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSAlertStyleCritical]; [alert setAlertStyle:NSAlertStyleCritical];
@ -129,7 +129,7 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
} }
} }
SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window] autorelease]; SDLMessageBoxPresenter* presenter = [[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window];
[presenter showAlert:alert]; [presenter showAlert:alert];

View File

@ -89,7 +89,7 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
/* Allow resize. */ /* Allow resize. */
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
SDL_AddEventWatch(SDL_MetalViewEventWatch, self); SDL_AddEventWatch(SDL_MetalViewEventWatch, (__bridge void *)(self));
[self updateDrawableSize]; [self updateDrawableSize];
} }
@ -99,8 +99,7 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
- (void)dealloc - (void)dealloc
{ {
SDL_DelEventWatch(SDL_MetalViewEventWatch, self); SDL_DelEventWatch(SDL_MetalViewEventWatch, (__bridge void *)(self));
[super dealloc];
} }
- (NSInteger)tag - (NSInteger)tag
@ -135,7 +134,7 @@ SDL_MetalView
Cocoa_Metal_CreateView(_THIS, SDL_Window * window) Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
{ @autoreleasepool { { @autoreleasepool {
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data->nswindow.contentView; NSView *view = data.nswindow.contentView;
BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
Uint32 windowID = SDL_GetWindowID(window); Uint32 windowID = SDL_GetWindowID(window);
SDL_cocoametalview *newview; SDL_cocoametalview *newview;
@ -151,7 +150,6 @@ Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
[view addSubview:newview]; [view addSubview:newview];
metalview = (SDL_MetalView)CFBridgingRetain(newview); metalview = (SDL_MetalView)CFBridgingRetain(newview);
[newview release];
return metalview; return metalview;
}} }}
@ -174,7 +172,7 @@ void
Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h) Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ @autoreleasepool { { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
NSView *contentView = data->sdlContentView; NSView *contentView = data.sdlContentView;
SDL_cocoametalview* metalview = [contentView viewWithTag:SDL_METALVIEW_TAG]; SDL_cocoametalview* metalview = [contentView viewWithTag:SDL_METALVIEW_TAG];
if (metalview) { if (metalview) {
CAMetalLayer *layer = (CAMetalLayer*)metalview.layer; CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;

View File

@ -306,7 +306,7 @@ Cocoa_GetDisplayName(CGDirectDisplayID displayID)
/* This API is deprecated in 10.9 with no good replacement (as of 10.15). */ /* This API is deprecated in 10.9 with no good replacement (as of 10.15). */
io_service_t servicePort = CGDisplayIOServicePort(displayID); io_service_t servicePort = CGDisplayIOServicePort(displayID);
CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName); CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
NSDictionary *localizedNames = [(NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]]; NSDictionary *localizedNames = [(__bridge NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
const char* displayName = NULL; const char* displayName = NULL;
if ([localizedNames count] > 0) { if ([localizedNames count] > 0) {

View File

@ -53,7 +53,7 @@
NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0] NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
length:sizeof(cursorBytes) length:sizeof(cursorBytes)
freeWhenDone:NO]; freeWhenDone:NO];
NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease]; NSImage *cursorImage = [[NSImage alloc] initWithData:cursorData];
invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage
hotSpot:NSZeroPoint]; hotSpot:NSZeroPoint];
} }
@ -75,8 +75,7 @@ Cocoa_CreateDefaultCursor()
if (nscursor) { if (nscursor) {
cursor = SDL_calloc(1, sizeof(*cursor)); cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) { if (cursor) {
cursor->driverdata = nscursor; cursor->driverdata = (void *)CFBridgingRetain(nscursor);
[nscursor retain];
} }
} }
@ -99,9 +98,7 @@ Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
if (nscursor) { if (nscursor) {
cursor = SDL_calloc(1, sizeof(*cursor)); cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) { if (cursor) {
cursor->driverdata = nscursor; cursor->driverdata = (void *)CFBridgingRetain(nscursor);
} else {
[nscursor release];
} }
} }
@ -159,8 +156,7 @@ Cocoa_CreateSystemCursor(SDL_SystemCursor id)
cursor = SDL_calloc(1, sizeof(*cursor)); cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) { if (cursor) {
/* We'll free it later, so retain it here */ /* We'll free it later, so retain it here */
[nscursor retain]; cursor->driverdata = (void *)CFBridgingRetain(nscursor);
cursor->driverdata = nscursor;
} }
} }
@ -171,9 +167,7 @@ static void
Cocoa_FreeCursor(SDL_Cursor * cursor) Cocoa_FreeCursor(SDL_Cursor * cursor)
{ @autoreleasepool { @autoreleasepool
{ {
NSCursor *nscursor = (NSCursor *)cursor->driverdata; CFBridgingRelease(cursor->driverdata);
[nscursor release];
SDL_free(cursor); SDL_free(cursor);
}} }}
@ -184,11 +178,11 @@ Cocoa_ShowCursor(SDL_Cursor * cursor)
SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_VideoDevice *device = SDL_GetVideoDevice();
SDL_Window *window = (device ? device->windows : NULL); SDL_Window *window = (device ? device->windows : NULL);
for (; window != NULL; window = window->next) { for (; window != NULL; window = window->next) {
SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata; SDL_WindowData *driverdata = (__bridge SDL_WindowData *)window->driverdata;
if (driverdata) { if (driverdata) {
[driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:) [driverdata.nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
withObject:[driverdata->nswindow contentView] withObject:[driverdata.nswindow contentView]
waitUntilDone:NO]; waitUntilDone:NO];
} }
} }
return 0; return 0;
@ -214,10 +208,10 @@ Cocoa_WarpMouseGlobal(int x, int y)
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->focus) { if (mouse->focus) {
SDL_WindowData *data = (SDL_WindowData *) mouse->focus->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) mouse->focus->driverdata;
if ([data->listener isMovingOrFocusClickPending]) { if ([data.listener isMovingOrFocusClickPending]) {
DLog("Postponing warp, window being moved or focused."); DLog("Postponing warp, window being moved or focused.");
[data->listener setPendingMoveX:x Y:y]; [data.listener setPendingMoveX:x Y:y];
return 0; return 0;
} }
} }
@ -282,8 +276,8 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
/* We will re-apply the non-relative mode when the window finishes being moved, /* We will re-apply the non-relative mode when the window finishes being moved,
* if it is being moved right now. * if it is being moved right now.
*/ */
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
if ([data->listener isMovingOrFocusClickPending]) { if ([data.listener isMovingOrFocusClickPending]) {
return 0; return 0;
} }
@ -360,18 +354,18 @@ Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
NSWindow *nswindow = [event window]; NSWindow *nswindow = [event window];
for (window = _this->windows; window; window = window->next) { for (window = _this->windows; window; window = window->next) {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
if (data && data->nswindow == nswindow) { if (data && data.nswindow == nswindow) {
switch ([event type]) { switch ([event type]) {
case NSEventTypeLeftMouseDown: case NSEventTypeLeftMouseDown:
case NSEventTypeRightMouseDown: case NSEventTypeRightMouseDown:
case NSEventTypeOtherMouseDown: case NSEventTypeOtherMouseDown:
[data->listener setFocusClickPending:[event buttonNumber]]; [data.listener setFocusClickPending:[event buttonNumber]];
break; break;
case NSEventTypeLeftMouseUp: case NSEventTypeLeftMouseUp:
case NSEventTypeRightMouseUp: case NSEventTypeRightMouseUp:
case NSEventTypeOtherMouseUp: case NSEventTypeOtherMouseUp:
[data->listener clearFocusClickPending:[event buttonNumber]]; [data.listener clearFocusClickPending:[event buttonNumber]];
break; break;
default: default:
break; break;

View File

@ -82,10 +82,10 @@
- (void)setWindow:(SDL_Window *)newWindow - (void)setWindow:(SDL_Window *)newWindow
{ {
if (self->window) { if (self->window) {
SDL_WindowData *oldwindowdata = (SDL_WindowData *)self->window->driverdata; SDL_WindowData *oldwindowdata = (__bridge SDL_WindowData *)self->window->driverdata;
/* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */ /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */
NSMutableArray *contexts = oldwindowdata->nscontexts; NSMutableArray *contexts = oldwindowdata.nscontexts;
@synchronized (contexts) { @synchronized (contexts) {
[contexts removeObject:self]; [contexts removeObject:self];
} }
@ -94,11 +94,11 @@
self->window = newWindow; self->window = newWindow;
if (newWindow) { if (newWindow) {
SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata; SDL_WindowData *windowdata = (__bridge SDL_WindowData *)newWindow->driverdata;
NSView *contentview = windowdata->sdlContentView; NSView *contentview = windowdata.sdlContentView;
/* Now sign up for scheduled updates for the new window. */ /* Now sign up for scheduled updates for the new window. */
NSMutableArray *contexts = windowdata->nscontexts; NSMutableArray *contexts = windowdata.nscontexts;
@synchronized (contexts) { @synchronized (contexts) {
[contexts addObject:self]; [contexts addObject:self];
} }
@ -184,6 +184,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt; NSOpenGLPixelFormat *fmt;
SDLOpenGLContext *context; SDLOpenGLContext *context;
SDL_GLContext sdlcontext;
NSOpenGLContext *share_context = nil; NSOpenGLContext *share_context = nil;
int i = 0; int i = 0;
const char *glversion; const char *glversion;
@ -288,20 +289,20 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
} }
if (_this->gl_config.share_with_current_context) { if (_this->gl_config.share_with_current_context) {
share_context = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); share_context = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
} }
context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context]; context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
[fmt release];
if (context == nil) { if (context == nil) {
SDL_SetError("Failed creating OpenGL context"); SDL_SetError("Failed creating OpenGL context");
return NULL; return NULL;
} }
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) { sdlcontext = (SDL_GLContext)CFBridgingRetain(context);
Cocoa_GL_DeleteContext(_this, context);
if ( Cocoa_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext)context) < 0 ) {
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError("Failed making OpenGL context current"); SDL_SetError("Failed making OpenGL context current");
return NULL; return NULL;
} }
@ -315,27 +316,27 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString"); glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
if (!glGetStringFunc) { if (!glGetStringFunc) {
Cocoa_GL_DeleteContext(_this, context); Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError ("Failed getting OpenGL glGetString entry point"); SDL_SetError ("Failed getting OpenGL glGetString entry point");
return NULL; return NULL;
} }
glversion = (const char *)glGetStringFunc(GL_VERSION); glversion = (const char *)glGetStringFunc(GL_VERSION);
if (glversion == NULL) { if (glversion == NULL) {
Cocoa_GL_DeleteContext(_this, context); Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError ("Failed getting OpenGL context version"); SDL_SetError ("Failed getting OpenGL context version");
return NULL; return NULL;
} }
if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) { if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
Cocoa_GL_DeleteContext(_this, context); Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError ("Failed parsing OpenGL context version"); SDL_SetError ("Failed parsing OpenGL context version");
return NULL; return NULL;
} }
if ((glversion_major < _this->gl_config.major_version) || if ((glversion_major < _this->gl_config.major_version) ||
((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) { ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
Cocoa_GL_DeleteContext(_this, context); Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError ("Failed creating OpenGL context at version requested"); SDL_SetError ("Failed creating OpenGL context at version requested");
return NULL; return NULL;
} }
@ -346,7 +347,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
/*_this->gl_config.major_version = glversion_major;*/ /*_this->gl_config.major_version = glversion_major;*/
/*_this->gl_config.minor_version = glversion_minor;*/ /*_this->gl_config.minor_version = glversion_minor;*/
} }
return context; return sdlcontext;
}} }}
int int
@ -354,7 +355,7 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool { @autoreleasepool
{ {
if (context) { if (context) {
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
if ([nscontext window] != window) { if ([nscontext window] != window) {
[nscontext setWindow:window]; [nscontext setWindow:window];
[nscontext updateIfNeeded]; [nscontext updateIfNeeded];
@ -369,9 +370,10 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
void void
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h) Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ @autoreleasepool
{ {
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSView *contentView = windata->sdlContentView; NSView *contentView = windata.sdlContentView;
NSRect viewport = [contentView bounds]; NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
@ -389,7 +391,7 @@ Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
if (h) { if (h) {
*h = viewport.size.height; *h = viewport.size.height;
} }
} }}
int int
Cocoa_GL_SetSwapInterval(_THIS, int interval) Cocoa_GL_SetSwapInterval(_THIS, int interval)
@ -403,7 +405,7 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval)
return SDL_SetError("Late swap tearing currently unsupported"); return SDL_SetError("Late swap tearing currently unsupported");
} }
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); nscontext = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) { if (nscontext != nil) {
value = interval; value = interval;
[nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval]; [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
@ -423,7 +425,7 @@ Cocoa_GL_GetSwapInterval(_THIS)
GLint value; GLint value;
int status = 0; int status = 0;
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); nscontext = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) { if (nscontext != nil) {
[nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval]; [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
status = (int)value; status = (int)value;
@ -436,15 +438,15 @@ int
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window) Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool { @autoreleasepool
{ {
SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext(); SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
/* on 10.14 ("Mojave") and later, this deadlocks if two contexts in two /* on 10.14 ("Mojave") and later, this deadlocks if two contexts in two
threads try to swap at the same time, so put a mutex around it. */ threads try to swap at the same time, so put a mutex around it. */
SDL_LockMutex(videodata->swaplock); SDL_LockMutex(videodata.swaplock);
[nscontext flushBuffer]; [nscontext flushBuffer];
[nscontext updateIfNeeded]; [nscontext updateIfNeeded];
SDL_UnlockMutex(videodata->swaplock); SDL_UnlockMutex(videodata.swaplock);
return 0; return 0;
}} }}
@ -452,10 +454,8 @@ void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context) Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool { @autoreleasepool
{ {
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; SDLOpenGLContext *nscontext = (SDLOpenGLContext *)CFBridgingRelease(context);
[nscontext setWindow:NULL]; [nscontext setWindow:NULL];
[nscontext release];
}} }}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */ /* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */

View File

@ -29,8 +29,8 @@
/* EGL implementation of SDL OpenGL support */ /* EGL implementation of SDL OpenGL support */
int int
Cocoa_GLES_LoadLibrary(_THIS, const char *path) { Cocoa_GLES_LoadLibrary(_THIS, const char *path)
{
/* If the profile requested is not GL ES, switch over to WIN_GL functions */ /* If the profile requested is not GL ES, switch over to WIN_GL functions */
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
#if SDL_VIDEO_OPENGL_CGL #if SDL_VIDEO_OPENGL_CGL
@ -59,9 +59,10 @@ Cocoa_GLES_LoadLibrary(_THIS, const char *path) {
SDL_GLContext SDL_GLContext
Cocoa_GLES_CreateContext(_THIS, SDL_Window * window) Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{ {
SDL_GLContext context; SDL_GLContext context;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
#if SDL_VIDEO_OPENGL_CGL #if SDL_VIDEO_OPENGL_CGL
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@ -85,25 +86,37 @@ Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
} }
#endif #endif
context = SDL_EGL_CreateContext(_this, data->egl_surface); context = SDL_EGL_CreateContext(_this, data.egl_surface);
return context; return context;
} }}
void void
Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context) Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{ {
SDL_EGL_DeleteContext(_this, context); SDL_EGL_DeleteContext(_this, context);
Cocoa_GLES_UnloadLibrary(_this); Cocoa_GLES_UnloadLibrary(_this);
} }}
SDL_EGL_SwapWindow_impl(Cocoa) int
SDL_EGL_MakeCurrent_impl(Cocoa) Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_WindowData *) window->driverdata).egl_surface);
}}
int
Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{
return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_WindowData *) window->driverdata).egl_surface : EGL_NO_SURFACE, context);
}}
int int
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window) Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
{ {
/* The current context is lost in here; save it and reset it. */ /* The current context is lost in here; save it and reset it. */
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; SDL_WindowData *windowdata = (__bridge SDL_WindowData *) window->driverdata;
SDL_Window *current_win = SDL_GL_GetCurrentWindow(); SDL_Window *current_win = SDL_GL_GetCurrentWindow();
SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
@ -121,10 +134,10 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
} }
/* Create the GLES window surface */ /* Create the GLES window surface */
NSView* v = windowdata->nswindow.contentView; NSView* v = windowdata.nswindow.contentView;
windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)[v layer]); windowdata.egl_surface = SDL_EGL_CreateSurface(_this, (__bridge NativeWindowType)[v layer]);
if (windowdata->egl_surface == EGL_NO_SURFACE) { if (windowdata.egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Could not create GLES window surface"); return SDL_SetError("Could not create GLES window surface");
} }

View File

@ -29,11 +29,12 @@
SDL_WindowShaper* SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window) Cocoa_CreateShaper(SDL_Window* window)
{ @autoreleasepool
{ {
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata; SDL_WindowData* windata = (__bridge SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO]; [windata.nswindow setOpaque:NO];
[windata->nswindow setStyleMask:NSWindowStyleMaskBorderless]; [windata.nswindow setStyleMask:NSWindowStyleMaskBorderless];
SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
result->window = window; result->window = window;
@ -44,14 +45,14 @@ Cocoa_CreateShaper(SDL_Window* window)
SDL_ShapeData* data = (SDL_ShapeData *)SDL_malloc(sizeof(SDL_ShapeData)); SDL_ShapeData* data = (SDL_ShapeData *)SDL_malloc(sizeof(SDL_ShapeData));
result->driverdata = data; result->driverdata = data;
data->context = [windata->nswindow graphicsContext]; data->context = [windata.nswindow graphicsContext];
data->saved = SDL_FALSE; data->saved = SDL_FALSE;
data->shape = NULL; data->shape = NULL;
int resized_properly = Cocoa_ResizeWindowShape(window); int resized_properly = Cocoa_ResizeWindowShape(window);
SDL_assert(resized_properly == 0); SDL_assert(resized_properly == 0);
return result; return result;
} }}
typedef struct { typedef struct {
NSView* view; NSView* view;
@ -74,7 +75,7 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowSha
{ @autoreleasepool { @autoreleasepool
{ {
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata; SDL_WindowData* windata = (__bridge SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure closure; SDL_CocoaClosure closure;
if(data->saved == SDL_TRUE) { if(data->saved == SDL_TRUE) {
[data->context restoreGraphicsState]; [data->context restoreGraphicsState];
@ -86,10 +87,10 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowSha
[NSGraphicsContext setCurrentContext:data->context]; [NSGraphicsContext setCurrentContext:data->context];
[[NSColor clearColor] set]; [[NSColor clearColor] set];
NSRectFill([windata->sdlContentView frame]); NSRectFill([windata.sdlContentView frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape); data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
closure.view = windata->sdlContentView; closure.view = windata.sdlContentView;
closure.path = [NSBezierPath bezierPath]; closure.path = [NSBezierPath bezierPath];
closure.window = shaper->window; closure.window = shaper->window;
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure); SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);

View File

@ -97,18 +97,17 @@ DECLARE_ALERT_STYLE(Critical);
@class SDLTranslatorResponder; @class SDLTranslatorResponder;
typedef struct SDL_VideoData @interface SDL_VideoData : NSObject
{ @property (nonatomic) int allow_spaces;
int allow_spaces; @property (nonatomic) unsigned int modifierFlags;
unsigned int modifierFlags; @property (nonatomic) void *key_layout;
void *key_layout; @property (nonatomic) SDLTranslatorResponder *fieldEdit;
SDLTranslatorResponder *fieldEdit; @property (nonatomic) NSInteger clipboard_count;
NSInteger clipboard_count; @property (nonatomic) Uint32 screensaver_activity;
Uint32 screensaver_activity; @property (nonatomic) BOOL screensaver_use_iopm;
BOOL screensaver_use_iopm; @property (nonatomic) IOPMAssertionID screensaver_assertion;
IOPMAssertionID screensaver_assertion; @property (nonatomic) SDL_mutex *swaplock;
SDL_mutex *swaplock; @end
} SDL_VideoData;
/* Utility functions */ /* Utility functions */
extern NSImage * Cocoa_CreateImage(SDL_Surface * surface); extern NSImage * Cocoa_CreateImage(SDL_Surface * surface);

View File

@ -22,6 +22,10 @@
#if SDL_VIDEO_DRIVER_COCOA #if SDL_VIDEO_DRIVER_COCOA
#if !__has_feature(objc_arc)
#error SDL must be built with Objective-C ARC (automatic reference counting) enabled
#endif
#include "SDL.h" #include "SDL.h"
#include "SDL_endian.h" #include "SDL_endian.h"
#include "SDL_cocoavideo.h" #include "SDL_cocoavideo.h"
@ -29,6 +33,10 @@
#include "SDL_cocoavulkan.h" #include "SDL_cocoavulkan.h"
#include "SDL_cocoametalview.h" #include "SDL_cocoametalview.h"
@implementation SDL_VideoData
@end
/* Initialization/Query functions */ /* Initialization/Query functions */
static int Cocoa_VideoInit(_THIS); static int Cocoa_VideoInit(_THIS);
static void Cocoa_VideoQuit(_THIS); static void Cocoa_VideoQuit(_THIS);
@ -37,16 +45,18 @@ static void Cocoa_VideoQuit(_THIS);
static void static void
Cocoa_DeleteDevice(SDL_VideoDevice * device) Cocoa_DeleteDevice(SDL_VideoDevice * device)
{ @autoreleasepool
{ {
if (device->wakeup_lock) { if (device->wakeup_lock) {
SDL_DestroyMutex(device->wakeup_lock); SDL_DestroyMutex(device->wakeup_lock);
} }
SDL_free(device->driverdata); CFBridgingRelease(device->driverdata);
SDL_free(device); SDL_free(device);
} }}
static SDL_VideoDevice * static SDL_VideoDevice *
Cocoa_CreateDevice(int devindex) Cocoa_CreateDevice(int devindex)
{ @autoreleasepool
{ {
SDL_VideoDevice *device; SDL_VideoDevice *device;
SDL_VideoData *data; SDL_VideoData *data;
@ -56,16 +66,16 @@ Cocoa_CreateDevice(int devindex)
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device) { if (device) {
data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); data = [[SDL_VideoData alloc] init];
} else { } else {
data = NULL; data = nil;
} }
if (!data) { if (!data) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_free(device); SDL_free(device);
return NULL; return NULL;
} }
device->driverdata = data; device->driverdata = (void *)CFBridgingRetain(data);
device->wakeup_lock = SDL_CreateMutex(); device->wakeup_lock = SDL_CreateMutex();
/* Set the function pointers */ /* Set the function pointers */
@ -166,7 +176,7 @@ Cocoa_CreateDevice(int devindex)
device->free = Cocoa_DeleteDevice; device->free = Cocoa_DeleteDevice;
return device; return device;
} }}
VideoBootStrap COCOA_bootstrap = { VideoBootStrap COCOA_bootstrap = {
"cocoa", "SDL Cocoa video driver", "cocoa", "SDL Cocoa video driver",
@ -176,8 +186,9 @@ VideoBootStrap COCOA_bootstrap = {
int int
Cocoa_VideoInit(_THIS) Cocoa_VideoInit(_THIS)
{ @autoreleasepool
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
Cocoa_InitModes(_this); Cocoa_InitModes(_this);
Cocoa_InitKeyboard(_this); Cocoa_InitKeyboard(_this);
@ -185,29 +196,30 @@ Cocoa_VideoInit(_THIS)
return -1; return -1;
} }
data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE)); data.allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
/* The IOPM assertion API can disable the screensaver as of 10.7. */ /* The IOPM assertion API can disable the screensaver as of 10.7. */
data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6; data.screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
data->swaplock = SDL_CreateMutex(); data.swaplock = SDL_CreateMutex();
if (!data->swaplock) { if (!data.swaplock) {
return -1; return -1;
} }
return 0; return 0;
} }}
void void
Cocoa_VideoQuit(_THIS) Cocoa_VideoQuit(_THIS)
{ @autoreleasepool
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
Cocoa_QuitModes(_this); Cocoa_QuitModes(_this);
Cocoa_QuitKeyboard(_this); Cocoa_QuitKeyboard(_this);
Cocoa_QuitMouse(_this); Cocoa_QuitMouse(_this);
SDL_DestroyMutex(data->swaplock); SDL_DestroyMutex(data.swaplock);
data->swaplock = NULL; data.swaplock = NULL;
} }}
/* This function assumes that it's called from within an autorelease pool */ /* This function assumes that it's called from within an autorelease pool */
NSImage * NSImage *
@ -224,7 +236,7 @@ Cocoa_CreateImage(SDL_Surface * surface)
return nil; return nil;
} }
imgrep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL imgrep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
pixelsWide: converted->w pixelsWide: converted->w
pixelsHigh: converted->h pixelsHigh: converted->h
bitsPerSample: 8 bitsPerSample: 8
@ -233,7 +245,7 @@ Cocoa_CreateImage(SDL_Surface * surface)
isPlanar: NO isPlanar: NO
colorSpaceName: NSDeviceRGBColorSpace colorSpaceName: NSDeviceRGBColorSpace
bytesPerRow: converted->pitch bytesPerRow: converted->pitch
bitsPerPixel: converted->format->BitsPerPixel] autorelease]; bitsPerPixel: converted->format->BitsPerPixel];
if (imgrep == nil) { if (imgrep == nil) {
SDL_FreeSurface(converted); SDL_FreeSurface(converted);
return nil; return nil;
@ -253,7 +265,7 @@ Cocoa_CreateImage(SDL_Surface * surface)
pixels += 4; pixels += 4;
} }
img = [[[NSImage alloc] initWithSize: NSMakeSize(surface->w, surface->h)] autorelease]; img = [[NSImage alloc] initWithSize: NSMakeSize(surface->w, surface->h)];
if (img != nil) { if (img != nil) {
[img addRepresentation: imgrep]; [img addRepresentation: imgrep];
} }

View File

@ -29,7 +29,7 @@
#include "../SDL_egl_c.h" #include "../SDL_egl_c.h"
#endif #endif
typedef struct SDL_WindowData SDL_WindowData; @class SDL_WindowData;
typedef enum typedef enum
{ {
@ -114,22 +114,22 @@ typedef enum
/* *INDENT-ON* */ /* *INDENT-ON* */
@class SDLOpenGLContext; @class SDLOpenGLContext;
@class SDL_VideoData;
struct SDL_WindowData @interface SDL_WindowData : NSObject
{ @property (nonatomic) SDL_Window *window;
SDL_Window *window; @property (nonatomic) NSWindow *nswindow;
NSWindow *nswindow; @property (nonatomic) NSView *sdlContentView;
NSView *sdlContentView; @property (nonatomic) NSMutableArray *nscontexts;
NSMutableArray *nscontexts; @property (nonatomic) SDL_bool created;
SDL_bool created; @property (nonatomic) SDL_bool inWindowFullscreenTransition;
SDL_bool inWindowFullscreenTransition; @property (nonatomic) NSInteger flash_request;
NSInteger flash_request; @property (nonatomic) Cocoa_WindowListener *listener;
Cocoa_WindowListener *listener; @property (nonatomic) SDL_VideoData *videodata;
struct SDL_VideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface; @property (nonatomic) EGLSurface egl_surface;
#endif #endif
}; @end
extern int Cocoa_CreateWindow(_THIS, SDL_Window * window); extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,

File diff suppressed because it is too large Load Diff