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")
endif()
if(IOS OR TVOS)
if(APPLE)
target_compile_options(sdl-build-options INTERFACE "-fobjc-arc")
endif()

View File

@ -3469,13 +3469,13 @@
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 */; };
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 */; };
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 */; };
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 */; };
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 */; };
@ -9188,6 +9188,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
@ -9273,6 +9274,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;

View File

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

View File

@ -142,24 +142,6 @@ typedef struct METAL_ShaderPipelines
@end
@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
@interface METAL_TextureData : NSObject
@ -178,16 +160,6 @@ typedef struct METAL_ShaderPipelines
@end
@implementation METAL_TextureData
#if !__has_feature(objc_arc)
- (void)dealloc
{
[_mtltexture release];
[_mtltexture_uv release];
[_mtlsampler release];
[_lockedbuffer release];
[super dealloc];
}
#endif
@end
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));
#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) {
states[cache->count++] = pipeline;
cache->states = states;
@ -632,9 +597,6 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (yuv || nv12) {
mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
if (mtltexture_uv == nil) {
#if !__has_feature(objc_arc)
[mtltexture release];
#endif
return SDL_SetError("Texture allocation failed");
}
}
@ -677,12 +639,6 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
#endif
texture->driverdata = (void*)CFBridgingRetain(texturedata);
#if !__has_feature(objc_arc)
[texturedata release];
[mtltexture release];
[mtltexture_uv release];
#endif
return 0;
}}
@ -742,10 +698,6 @@ METAL_UpdateTextureInternal(SDL_Renderer * renderer, METAL_TextureData *textured
return SDL_OutOfMemory();
}
#if !__has_feature(objc_arc)
[stagingtex autorelease];
#endif
METAL_UploadTextureData(stagingtex, stagingrect, 0, pixels, pitch);
if (data.mtlcmdencoder != nil) {
@ -917,11 +869,6 @@ METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
texturedata.lockedbuffer = lockedbuffer;
*pixels = [lockedbuffer contents];
/* METAL_TextureData.lockedbuffer retains. */
#if !__has_feature(objc_arc)
[lockedbuffer release];
#endif
return 0;
}}
@ -1209,13 +1156,8 @@ METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
typedef struct
{
#if __has_feature(objc_arc)
__unsafe_unretained id<MTLRenderPipelineState> pipeline;
__unsafe_unretained id<MTLBuffer> vertex_buffer;
#else
id<MTLRenderPipelineState> pipeline;
id<MTLBuffer> vertex_buffer;
#endif
size_t constants_offset;
SDL_Texture *texture;
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
* good for those, or should we have a managed buffer for them? */
mtlbufvertex = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModeShared];
#if !__has_feature(objc_arc)
[mtlbufvertex autorelease];
#endif
mtlbufvertex.label = @"SDL vertex data";
SDL_memcpy([mtlbufvertex contents], vertices, vertsize);
@ -1711,9 +1650,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
}
if (view == NULL) {
#if !__has_feature(objc_arc)
[mtldevice release];
#endif
SDL_free(renderer);
if (changed_window) {
SDL_RecreateWindow(window, window_flags);
@ -1725,9 +1661,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
data = [[METAL_RenderData alloc] init];
if (data == nil) {
#if !__has_feature(objc_arc)
[mtldevice release];
#endif
/* Release the metal view instead of destroying it,
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;
#ifdef __MACOSX__
layer = (CAMetalLayer *)[(NSView *)view layer];
layer = (CAMetalLayer *)[(__bridge NSView *)view layer];
#else
layer = (CAMetalLayer *)[(__bridge UIView *)view layer];
#endif
@ -1771,9 +1704,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
id<MTLLibrary> mtllibrary = [data.mtldevice newLibraryWithData:mtllibdata error:&err];
data.mtllibrary = mtllibrary;
SDL_assert(err == nil);
#if !__has_feature(objc_arc)
dispatch_release(mtllibdata);
#endif
data.mtllibrary.label = @"SDL Metal renderer shader library";
/* 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];
#if !__has_feature(objc_arc)
[mtlbufconstantstaging autorelease];
#endif
char *constantdata = [mtlbufconstantstaging contents];
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;
size_t indicessize = sizeof(UInt16) * quadcount * 6;
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):
* 1---3
@ -1965,18 +1889,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->info.max_texture_width = 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;
}}

View File

@ -24,12 +24,12 @@
#define SDL_cocoaclipboard_h_
/* Forward declaration */
struct SDL_VideoData;
@class SDL_VideoData;
extern int Cocoa_SetClipboardText(_THIS, const char *text);
extern char *Cocoa_GetClipboardText(_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_ */

View File

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

View File

@ -104,8 +104,7 @@
}
if (_markedText != aString) {
[_markedText release];
_markedText = [aString retain];
_markedText = aString;
}
_selectedRange = selectedRange;
@ -120,7 +119,6 @@
- (void)unmarkText
{
[_markedText release];
_markedText = nil;
SDL_SendEditingText("", 0, 0);
@ -381,14 +379,14 @@ DoSidedModifiers(unsigned short scancode,
static void
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;
}
DoSidedModifiers(scancode, data->modifierFlags, modifierFlags);
data->modifierFlags = modifierFlags;
DoSidedModifiers(scancode, data.modifierFlags, modifierFlags);
data.modifierFlags = modifierFlags;
}
static void
@ -402,10 +400,10 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
/* See if the keymap needs to be updated */
key_layout = TISCopyCurrentKeyboardLayoutInputSource();
if (key_layout == data->key_layout) {
if (key_layout == data.key_layout) {
return;
}
data->key_layout = key_layout;
data.key_layout = key_layout;
SDL_GetDefaultKeymap(keymap);
@ -461,7 +459,7 @@ cleanup:
void
Cocoa_InitKeyboard(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
UpdateKeymap(data, SDL_FALSE);
@ -473,19 +471,19 @@ Cocoa_InitKeyboard(_THIS)
SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
data->modifierFlags = (unsigned int)[NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);
data.modifierFlags = (unsigned int)[NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) != 0);
}
void
Cocoa_StartTextInput(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow = nil;
if (window) {
nswindow = ((SDL_WindowData*)window->driverdata)->nswindow;
nswindow = ((__bridge SDL_WindowData*)window->driverdata).nswindow;
}
NSView *parentView = [nswindow contentView];
@ -495,16 +493,16 @@ Cocoa_StartTextInput(_THIS)
* than one copy. When we switched to another window and requesting for
* text input, simply remove the field editor from its superview then add
* it to the front most window's content view */
if (!data->fieldEdit) {
data->fieldEdit =
if (!data.fieldEdit) {
data.fieldEdit =
[[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"); */
[data->fieldEdit removeFromSuperview];
[parentView addSubview: data->fieldEdit];
[nswindow makeFirstResponder: data->fieldEdit];
[data.fieldEdit removeFromSuperview];
[parentView addSubview: data.fieldEdit];
[nswindow makeFirstResponder: data.fieldEdit];
}
}}
@ -512,32 +510,31 @@ void
Cocoa_StopTextInput(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (data && data->fieldEdit) {
[data->fieldEdit removeFromSuperview];
[data->fieldEdit release];
data->fieldEdit = nil;
if (data && data.fieldEdit) {
[data.fieldEdit removeFromSuperview];
data.fieldEdit = nil;
}
}}
void
Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (!rect) {
SDL_InvalidParamError("rect");
return;
}
[data->fieldEdit setInputRect:rect];
[data.fieldEdit setInputRect:rect];
}
void
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) {
return; /* can happen when returning from fullscreen Space on shutdown */
}
@ -575,7 +572,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
#endif
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. */
[data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
[data.fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
#if 0
text = [[event characters] UTF8String];
if(text && *text) {

View File

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

View File

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

View File

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

View File

@ -82,10 +82,10 @@
- (void)setWindow:(SDL_Window *)newWindow
{
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. */
NSMutableArray *contexts = oldwindowdata->nscontexts;
NSMutableArray *contexts = oldwindowdata.nscontexts;
@synchronized (contexts) {
[contexts removeObject:self];
}
@ -94,11 +94,11 @@
self->window = newWindow;
if (newWindow) {
SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
NSView *contentview = windowdata->sdlContentView;
SDL_WindowData *windowdata = (__bridge SDL_WindowData *)newWindow->driverdata;
NSView *contentview = windowdata.sdlContentView;
/* Now sign up for scheduled updates for the new window. */
NSMutableArray *contexts = windowdata->nscontexts;
NSMutableArray *contexts = windowdata.nscontexts;
@synchronized (contexts) {
[contexts addObject:self];
}
@ -184,6 +184,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt;
SDLOpenGLContext *context;
SDL_GLContext sdlcontext;
NSOpenGLContext *share_context = nil;
int i = 0;
const char *glversion;
@ -288,20 +289,20 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
}
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];
[fmt release];
if (context == nil) {
SDL_SetError("Failed creating OpenGL context");
return NULL;
}
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
Cocoa_GL_DeleteContext(_this, context);
sdlcontext = (SDL_GLContext)CFBridgingRetain(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");
return NULL;
}
@ -315,27 +316,27 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
if (!glGetStringFunc) {
Cocoa_GL_DeleteContext(_this, context);
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError ("Failed getting OpenGL glGetString entry point");
return NULL;
}
glversion = (const char *)glGetStringFunc(GL_VERSION);
if (glversion == NULL) {
Cocoa_GL_DeleteContext(_this, context);
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_SetError ("Failed getting OpenGL context version");
return NULL;
}
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");
return NULL;
}
if ((glversion_major < _this->gl_config.major_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");
return NULL;
}
@ -346,7 +347,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
/*_this->gl_config.major_version = glversion_major;*/
/*_this->gl_config.minor_version = glversion_minor;*/
}
return context;
return sdlcontext;
}}
int
@ -354,7 +355,7 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{
if (context) {
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
if ([nscontext window] != window) {
[nscontext setWindow:window];
[nscontext updateIfNeeded];
@ -369,9 +370,10 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
void
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ @autoreleasepool
{
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSView *contentView = windata->sdlContentView;
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSView *contentView = windata.sdlContentView;
NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
@ -389,7 +391,7 @@ Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
if (h) {
*h = viewport.size.height;
}
}
}}
int
Cocoa_GL_SetSwapInterval(_THIS, int interval)
@ -403,7 +405,7 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval)
return SDL_SetError("Late swap tearing currently unsupported");
}
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
nscontext = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
value = interval;
[nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
@ -423,7 +425,7 @@ Cocoa_GL_GetSwapInterval(_THIS)
GLint value;
int status = 0;
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
nscontext = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
[nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
status = (int)value;
@ -436,15 +438,15 @@ int
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
/* 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. */
SDL_LockMutex(videodata->swaplock);
SDL_LockMutex(videodata.swaplock);
[nscontext flushBuffer];
[nscontext updateIfNeeded];
SDL_UnlockMutex(videodata->swaplock);
SDL_UnlockMutex(videodata.swaplock);
return 0;
}}
@ -452,10 +454,8 @@ void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)CFBridgingRelease(context);
[nscontext setWindow:NULL];
[nscontext release];
}}
/* 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 */
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 (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
#if SDL_VIDEO_OPENGL_CGL
@ -59,9 +59,10 @@ Cocoa_GLES_LoadLibrary(_THIS, const char *path) {
SDL_GLContext
Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_GLContext context;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
#if SDL_VIDEO_OPENGL_CGL
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@ -85,25 +86,37 @@ Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
}
#endif
context = SDL_EGL_CreateContext(_this, data->egl_surface);
context = SDL_EGL_CreateContext(_this, data.egl_surface);
return context;
}
}}
void
Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
SDL_EGL_DeleteContext(_this, context);
Cocoa_GLES_UnloadLibrary(_this);
}
}}
SDL_EGL_SwapWindow_impl(Cocoa)
SDL_EGL_MakeCurrent_impl(Cocoa)
int
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
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
{
/* 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_GLContext current_ctx = SDL_GL_GetCurrentContext();
@ -121,10 +134,10 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
}
/* Create the GLES window surface */
NSView* v = windowdata->nswindow.contentView;
windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)[v layer]);
NSView* v = windowdata.nswindow.contentView;
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");
}

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff