Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
--- a/src/file/cocoa/SDL_rwopsbundlesupport.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/file/cocoa/SDL_rwopsbundlesupport.m Mon Feb 11 17:39:52 2013 -0800
@@ -20,22 +20,25 @@
return fopen(file, mode);
}
- @autoreleasepool {
- NSFileManager* file_manager = [NSFileManager defaultManager];
- NSString* resource_path = [[NSBundle mainBundle] resourcePath];
+ NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+
- NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
+ NSFileManager* file_manager = [NSFileManager defaultManager];
+ NSString* resource_path = [[NSBundle mainBundle] resourcePath];
+
+ NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
- NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
- if([file_manager fileExistsAtPath:full_path_with_file_to_try])
- {
- fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
- }
- else
- {
- fp = fopen(file, mode);
- }
- }
+ NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
+ if([file_manager fileExistsAtPath:full_path_with_file_to_try])
+ {
+ fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
+ }
+ else
+ {
+ fp = fopen(file, mode);
+ }
+
+ [autorelease_pool drain];
return fp;
}
--- a/src/video/cocoa/SDL_cocoaclipboard.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoaclipboard.m Mon Feb 11 17:39:52 2013 -0800
@@ -45,46 +45,51 @@
Cocoa_SetClipboardText(_THIS, const char *text)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
-
+ NSAutoreleasePool *pool;
NSPasteboard *pasteboard;
NSString *format = GetTextFormat(_this);
- @autoreleasepool {
- pasteboard = [NSPasteboard generalPasteboard];
- data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
- [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
- }
-
+ pool = [[NSAutoreleasePool alloc] init];
+
+ pasteboard = [NSPasteboard generalPasteboard];
+ data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
+ [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
+
+ [pool release];
+
return 0;
}
char *
Cocoa_GetClipboardText(_THIS)
{
+ NSAutoreleasePool *pool;
NSPasteboard *pasteboard;
NSString *format = GetTextFormat(_this);
NSString *available;
char *text;
- @autoreleasepool {
- pasteboard = [NSPasteboard generalPasteboard];
- available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
- if ([available isEqualToString:format]) {
- NSString* string;
- const char *utf8;
+ pool = [[NSAutoreleasePool alloc] init];
+
+ pasteboard = [NSPasteboard generalPasteboard];
+ available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
+ if ([available isEqualToString:format]) {
+ NSString* string;
+ const char *utf8;
- string = [pasteboard stringForType:format];
- if (string == nil) {
- utf8 = "";
- } else {
- utf8 = [string UTF8String];
- }
- text = SDL_strdup(utf8);
+ string = [pasteboard stringForType:format];
+ if (string == nil) {
+ utf8 = "";
} else {
- text = SDL_strdup("");
+ utf8 = [string UTF8String];
}
+ text = SDL_strdup(utf8);
+ } else {
+ text = SDL_strdup("");
}
-
+
+ [pool release];
+
return text;
}
@@ -103,19 +108,22 @@
void
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
{
+ NSAutoreleasePool *pool;
NSPasteboard *pasteboard;
NSInteger count;
- @autoreleasepool {
- pasteboard = [NSPasteboard generalPasteboard];
- count = [pasteboard changeCount];
- if (count != data->clipboard_count) {
- if (data->clipboard_count) {
- SDL_SendClipboardUpdate();
- }
- data->clipboard_count = count;
+ pool = [[NSAutoreleasePool alloc] init];
+
+ pasteboard = [NSPasteboard generalPasteboard];
+ count = [pasteboard changeCount];
+ if (count != data->clipboard_count) {
+ if (data->clipboard_count) {
+ SDL_SendClipboardUpdate();
}
+ data->clipboard_count = count;
}
+
+ [pool release];
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
--- a/src/video/cocoa/SDL_cocoaevents.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoaevents.m Mon Feb 11 17:39:52 2013 -0800
@@ -159,30 +159,33 @@
{
/* This can get called more than once! Be careful what you initialize! */
ProcessSerialNumber psn;
+ NSAutoreleasePool *pool;
if (!GetCurrentProcess(&psn)) {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
SetFrontProcess(&psn);
}
- @autoreleasepool {
- if (NSApp == nil) {
- [NSApplication sharedApplication];
+ pool = [[NSAutoreleasePool alloc] init];
+ if (NSApp == nil) {
+ [NSApplication sharedApplication];
- if ([NSApp mainMenu] == nil) {
- CreateApplicationMenus();
- }
- [NSApp finishLaunching];
+ if ([NSApp mainMenu] == nil) {
+ CreateApplicationMenus();
}
- if ([NSApp delegate] == nil) {
- [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
- }
+ [NSApp finishLaunching];
}
+ if ([NSApp delegate] == nil) {
+ [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
+ }
+ [pool release];
}
void
Cocoa_PumpEvents(_THIS)
{
+ NSAutoreleasePool *pool;
+
/* Update activity every 30 seconds to prevent screensaver */
if (_this->suspend_screensaver) {
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
@@ -194,39 +197,39 @@
}
}
- @autoreleasepool {
- for ( ; ; ) {
- NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
- if ( event == nil ) {
- break;
- }
-
- switch ([event type]) {
- case NSLeftMouseDown:
- case NSOtherMouseDown:
- case NSRightMouseDown:
- case NSLeftMouseUp:
- case NSOtherMouseUp:
- case NSRightMouseUp:
- case NSLeftMouseDragged:
- case NSRightMouseDragged:
- case NSOtherMouseDragged: /* usually middle mouse dragged */
- case NSMouseMoved:
- case NSScrollWheel:
- Cocoa_HandleMouseEvent(_this, event);
- break;
- case NSKeyDown:
- case NSKeyUp:
- case NSFlagsChanged:
- Cocoa_HandleKeyEvent(_this, event);
- break;
- default:
- break;
- }
- /* Pass through to NSApp to make sure everything stays in sync */
- [NSApp sendEvent:event];
+ pool = [[NSAutoreleasePool alloc] init];
+ for ( ; ; ) {
+ NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
+ if ( event == nil ) {
+ break;
}
+
+ switch ([event type]) {
+ case NSLeftMouseDown:
+ case NSOtherMouseDown:
+ case NSRightMouseDown:
+ case NSLeftMouseUp:
+ case NSOtherMouseUp:
+ case NSRightMouseUp:
+ case NSLeftMouseDragged:
+ case NSRightMouseDragged:
+ case NSOtherMouseDragged: /* usually middle mouse dragged */
+ case NSMouseMoved:
+ case NSScrollWheel:
+ Cocoa_HandleMouseEvent(_this, event);
+ break;
+ case NSKeyDown:
+ case NSKeyUp:
+ case NSFlagsChanged:
+ Cocoa_HandleKeyEvent(_this, event);
+ break;
+ default:
+ break;
+ }
+ /* Pass through to NSApp to make sure everything stays in sync */
+ [NSApp sendEvent:event];
}
+ [pool release];
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
--- a/src/video/cocoa/SDL_cocoakeyboard.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoakeyboard.m Mon Feb 11 17:39:52 2013 -0800
@@ -625,27 +625,28 @@
Cocoa_StartTextInput(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
- @autoreleasepool {
- NSView *parentView = [[NSApp keyWindow] contentView];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSView *parentView = [[NSApp keyWindow] contentView];
- /* We only keep one field editor per process, since only the front most
- * window can receive text input events, so it make no sense to keep more
- * 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 =
- [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
- }
+ /* We only keep one field editor per process, since only the front most
+ * window can receive text input events, so it make no sense to keep more
+ * 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 =
+ [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
+ }
- if (![[data->fieldEdit superview] isEqual: parentView])
- {
- // DEBUG_IME(@"add fieldEdit to window contentView");
- [data->fieldEdit removeFromSuperview];
- [parentView addSubview: data->fieldEdit];
- [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
- }
+ if (![[data->fieldEdit superview] isEqual: parentView])
+ {
+ // DEBUG_IME(@"add fieldEdit to window contentView");
+ [data->fieldEdit removeFromSuperview];
+ [parentView addSubview: data->fieldEdit];
+ [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
}
+
+ [pool release];
}
void
@@ -654,11 +655,11 @@
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (data && data->fieldEdit) {
- @autoreleasepool {
- [data->fieldEdit removeFromSuperview];
- [data->fieldEdit release];
- data->fieldEdit = nil;
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ [data->fieldEdit removeFromSuperview];
+ [data->fieldEdit release];
+ data->fieldEdit = nil;
+ [pool release];
}
}
--- a/src/video/cocoa/SDL_cocoamessagebox.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoamessagebox.m Mon Feb 11 17:39:52 2013 -0800
@@ -39,38 +39,40 @@
{
Cocoa_RegisterApp();
- @autoreleasepool {
- NSAlert* alert = [[NSAlert alloc] init];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSAlert* alert = [[NSAlert alloc] init];
- if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
- [alert setAlertStyle:NSCriticalAlertStyle];
- } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
- [alert setAlertStyle:NSWarningAlertStyle];
- } else {
- [alert setAlertStyle:NSInformationalAlertStyle];
- }
+ if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
+ [alert setAlertStyle:NSWarningAlertStyle];
+ } else {
+ [alert setAlertStyle:NSInformationalAlertStyle];
+ }
- [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
- [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
+ [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
+ [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
- const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
- int i;
- for (i = 0; i < messageboxdata->numbuttons; ++i) {
- NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
- if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
- [button setKeyEquivalent:@"\r"];
- } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
- [button setKeyEquivalent:@"\033"];
- } else {
- [button setKeyEquivalent:@""];
- }
+ const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
+ int i;
+ for (i = 0; i < messageboxdata->numbuttons; ++i) {
+ NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
+ if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
+ [button setKeyEquivalent:@"\r"];
+ } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
+ [button setKeyEquivalent:@"\033"];
+ } else {
+ [button setKeyEquivalent:@""];
}
+ }
- NSInteger clicked = [alert runModal];
- clicked -= NSAlertFirstButtonReturn;
- *buttonid = buttons[clicked].buttonid;
- [alert release];
- }
+ NSInteger clicked = [alert runModal];
+ clicked -= NSAlertFirstButtonReturn;
+ *buttonid = buttons[clicked].buttonid;
+ [alert release];
+
+ [pool release];
return 0;
}
--- a/src/video/cocoa/SDL_cocoamouse.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.m Mon Feb 11 17:39:52 2013 -0800
@@ -32,134 +32,140 @@
static SDL_Cursor *
Cocoa_CreateDefaultCursor()
{
- @autoreleasepool {
- NSCursor *nscursor;
- SDL_Cursor *cursor = NULL;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSCursor *nscursor;
+ SDL_Cursor *cursor = NULL;
- nscursor = [NSCursor arrowCursor];
+ nscursor = [NSCursor arrowCursor];
- if (nscursor) {
- cursor = SDL_calloc(1, sizeof(*cursor));
- if (cursor) {
- cursor->driverdata = nscursor;
- [nscursor retain];
- }
+ if (nscursor) {
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = nscursor;
+ [nscursor retain];
}
-
- return cursor;
}
+
+ [pool release];
+
+ return cursor;
}
static SDL_Cursor *
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{
- @autoreleasepool {
- NSImage *nsimage;
- NSCursor *nscursor = NULL;
- SDL_Cursor *cursor = NULL;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSImage *nsimage;
+ NSCursor *nscursor = NULL;
+ SDL_Cursor *cursor = NULL;
- nsimage = Cocoa_CreateImage(surface);
- if (nsimage) {
- nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
- }
+ nsimage = Cocoa_CreateImage(surface);
+ if (nsimage) {
+ nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
+ }
- if (nscursor) {
- cursor = SDL_calloc(1, sizeof(*cursor));
- if (cursor) {
- cursor->driverdata = nscursor;
- }
+ if (nscursor) {
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = nscursor;
}
-
- return cursor;
}
+
+ [pool release];
+
+ return cursor;
}
static SDL_Cursor *
Cocoa_CreateSystemCursor(SDL_SystemCursor id)
{
- @autoreleasepool {
- NSCursor *nscursor = NULL;
- SDL_Cursor *cursor = NULL;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSCursor *nscursor = NULL;
+ SDL_Cursor *cursor = NULL;
- switch(id)
- {
- case SDL_SYSTEM_CURSOR_ARROW:
- nscursor = [NSCursor arrowCursor];
- break;
- case SDL_SYSTEM_CURSOR_IBEAM:
- nscursor = [NSCursor IBeamCursor];
- break;
- case SDL_SYSTEM_CURSOR_WAIT:
- nscursor = [NSCursor arrowCursor];
- break;
- case SDL_SYSTEM_CURSOR_CROSSHAIR:
- nscursor = [NSCursor crosshairCursor];
- break;
- case SDL_SYSTEM_CURSOR_WAITARROW:
- nscursor = [NSCursor arrowCursor];
- break;
- case SDL_SYSTEM_CURSOR_SIZENWSE:
- case SDL_SYSTEM_CURSOR_SIZENESW:
- nscursor = [NSCursor closedHandCursor];
- break;
- case SDL_SYSTEM_CURSOR_SIZEWE:
- nscursor = [NSCursor resizeLeftRightCursor];
- break;
- case SDL_SYSTEM_CURSOR_SIZENS:
- nscursor = [NSCursor resizeUpDownCursor];
- break;
- case SDL_SYSTEM_CURSOR_SIZEALL:
- nscursor = [NSCursor closedHandCursor];
- break;
- case SDL_SYSTEM_CURSOR_NO:
- nscursor = [NSCursor operationNotAllowedCursor];
- break;
- case SDL_SYSTEM_CURSOR_HAND:
- nscursor = [NSCursor pointingHandCursor];
- break;
- default:
- SDL_assert(!"Unknown system cursor");
- return NULL;
+ switch(id)
+ {
+ case SDL_SYSTEM_CURSOR_ARROW:
+ nscursor = [NSCursor arrowCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_IBEAM:
+ nscursor = [NSCursor IBeamCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_WAIT:
+ nscursor = [NSCursor arrowCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
+ nscursor = [NSCursor crosshairCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_WAITARROW:
+ nscursor = [NSCursor arrowCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
+ case SDL_SYSTEM_CURSOR_SIZENESW:
+ nscursor = [NSCursor closedHandCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEWE:
+ nscursor = [NSCursor resizeLeftRightCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENS:
+ nscursor = [NSCursor resizeUpDownCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEALL:
+ nscursor = [NSCursor closedHandCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_NO:
+ nscursor = [NSCursor operationNotAllowedCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_HAND:
+ nscursor = [NSCursor pointingHandCursor];
+ break;
+ default:
+ SDL_assert(!"Unknown system cursor");
+ return NULL;
+ }
+
+ if (nscursor) {
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ // We'll free it later, so retain it here
+ [nscursor retain];
+ cursor->driverdata = nscursor;
}
+ }
- if (nscursor) {
- cursor = SDL_calloc(1, sizeof(*cursor));
- if (cursor) {
- // We'll free it later, so retain it here
- [nscursor retain];
- cursor->driverdata = nscursor;
- }
- }
-
- return cursor;
- }
+ [pool release];
+
+ return cursor;
}
static void
Cocoa_FreeCursor(SDL_Cursor * cursor)
{
- @autoreleasepool {
- NSCursor *nscursor = (NSCursor *)cursor->driverdata;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSCursor *nscursor = (NSCursor *)cursor->driverdata;
- [nscursor release];
- SDL_free(cursor);
- }
+ [nscursor release];
+ SDL_free(cursor);
+
+ [pool release];
}
static int
Cocoa_ShowCursor(SDL_Cursor * cursor)
{
- @autoreleasepool {
- if (cursor) {
- NSCursor *nscursor = (NSCursor *)cursor->driverdata;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ if (cursor) {
+ NSCursor *nscursor = (NSCursor *)cursor->driverdata;
- [nscursor set];
- [NSCursor unhide];
- } else {
- [NSCursor hide];
- }
+ [nscursor set];
+ [NSCursor unhide];
+ } else {
+ [NSCursor hide];
}
+ [pool release];
+
return 0;
}
--- a/src/video/cocoa/SDL_cocoaopengl.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoaopengl.m Mon Feb 11 17:39:52 2013 -0800
@@ -80,6 +80,7 @@
const int wantver = (_this->gl_config.major_version << 8) |
(_this->gl_config.minor_version);
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ NSAutoreleasePool *pool;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
NSOpenGLPixelFormatAttribute attr[32];
@@ -99,115 +100,120 @@
return NULL;
}
- @autoreleasepool {
- /* specify a profile if we're on Lion (10.7) or later. */
- if (data->osversion >= 0x1070) {
- NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
- if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
- if (wantver == 0x0302) {
- profile = kCGLOGLPVersion_3_2_Core;
- }
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* specify a profile if we're on Lion (10.7) or later. */
+ if (data->osversion >= 0x1070) {
+ NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
+ if (wantver == 0x0302) {
+ profile = kCGLOGLPVersion_3_2_Core;
}
- attr[i++] = kCGLPFAOpenGLProfile;
- attr[i++] = profile;
}
+ attr[i++] = kCGLPFAOpenGLProfile;
+ attr[i++] = profile;
+ }
+
+#ifndef FULLSCREEN_TOGGLEABLE
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ attr[i++] = NSOpenGLPFAFullScreen;
+ }
+#endif
+
+ attr[i++] = NSOpenGLPFAColorSize;
+ attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
+
+ attr[i++] = NSOpenGLPFADepthSize;
+ attr[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.double_buffer) {
+ attr[i++] = NSOpenGLPFADoubleBuffer;
+ }
+
+ if (_this->gl_config.stereo) {
+ attr[i++] = NSOpenGLPFAStereo;
+ }
+
+ if (_this->gl_config.stencil_size) {
+ attr[i++] = NSOpenGLPFAStencilSize;
+ attr[i++] = _this->gl_config.stencil_size;
+ }
+
+ if ((_this->gl_config.accum_red_size +
+ _this->gl_config.accum_green_size +
+ _this->gl_config.accum_blue_size +
+ _this->gl_config.accum_alpha_size) > 0) {
+ attr[i++] = NSOpenGLPFAAccumSize;
+ attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ attr[i++] = NSOpenGLPFASampleBuffers;
+ attr[i++] = _this->gl_config.multisamplebuffers;
+ }
- #ifndef FULLSCREEN_TOGGLEABLE
- if (window->flags & SDL_WINDOW_FULLSCREEN) {
- attr[i++] = NSOpenGLPFAFullScreen;
+ if (_this->gl_config.multisamplesamples) {
+ attr[i++] = NSOpenGLPFASamples;
+ attr[i++] = _this->gl_config.multisamplesamples;
+ attr[i++] = NSOpenGLPFANoRecovery;
+ }
+
+ if (_this->gl_config.accelerated >= 0) {
+ if (_this->gl_config.accelerated) {
+ attr[i++] = NSOpenGLPFAAccelerated;
+ } else {
+ attr[i++] = NSOpenGLPFARendererID;
+ attr[i++] = kCGLRendererGenericFloatID;
}
+ }
+
+ attr[i++] = NSOpenGLPFAScreenMask;
+ attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
+ attr[i] = 0;
+
+ fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
+ if (fmt == nil) {
+ SDL_SetError ("Failed creating OpenGL pixel format");
+ [pool release];
+ return NULL;
+ }
+
+ context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
+
+ [fmt release];
+
+ if (context == nil) {
+ SDL_SetError ("Failed creating OpenGL context");
+ [pool release];
+ return NULL;
+ }
+
+ /*
+ * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
+ * "You are blowing a couple of the internal OpenGL function caches. This
+ * appears to be happening in the VAO case. You can tell OpenGL to up
+ * the cache size by issuing the following calls right after you create
+ * the OpenGL context. The default cache size is 16." --ryan.
+ */
+
+ #ifndef GLI_ARRAY_FUNC_CACHE_MAX
+ #define GLI_ARRAY_FUNC_CACHE_MAX 284
#endif
- attr[i++] = NSOpenGLPFAColorSize;
- attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
-
- attr[i++] = NSOpenGLPFADepthSize;
- attr[i++] = _this->gl_config.depth_size;
-
- if (_this->gl_config.double_buffer) {
- attr[i++] = NSOpenGLPFADoubleBuffer;
- }
-
- if (_this->gl_config.stereo) {
- attr[i++] = NSOpenGLPFAStereo;
- }
-
- if (_this->gl_config.stencil_size) {
- attr[i++] = NSOpenGLPFAStencilSize;
- attr[i++] = _this->gl_config.stencil_size;
- }
-
- if ((_this->gl_config.accum_red_size +
- _this->gl_config.accum_green_size +
- _this->gl_config.accum_blue_size +
- _this->gl_config.accum_alpha_size) > 0) {
- attr[i++] = NSOpenGLPFAAccumSize;
- attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
- }
-
- if (_this->gl_config.multisamplebuffers) {
- attr[i++] = NSOpenGLPFASampleBuffers;
- attr[i++] = _this->gl_config.multisamplebuffers;
- }
-
- if (_this->gl_config.multisamplesamples) {
- attr[i++] = NSOpenGLPFASamples;
- attr[i++] = _this->gl_config.multisamplesamples;
- attr[i++] = NSOpenGLPFANoRecovery;
- }
+ #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
+ #define GLI_SUBMIT_FUNC_CACHE_MAX 280
+ #endif
- if (_this->gl_config.accelerated >= 0) {
- if (_this->gl_config.accelerated) {
- attr[i++] = NSOpenGLPFAAccelerated;
- } else {
- attr[i++] = NSOpenGLPFARendererID;
- attr[i++] = kCGLRendererGenericFloatID;
- }
- }
-
- attr[i++] = NSOpenGLPFAScreenMask;
- attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
- attr[i] = 0;
-
- fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
- if (fmt == nil) {
- SDL_SetError ("Failed creating OpenGL pixel format");
- return NULL;
- }
-
- context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
-
- [fmt release];
+ {
+ GLint cache_max = 64;
+ CGLContextObj ctx = [context CGLContextObj];
+ CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
+ CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
+ }
- if (context == nil) {
- SDL_SetError ("Failed creating OpenGL context");
- return NULL;
- }
-
- /*
- * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
- * "You are blowing a couple of the internal OpenGL function caches. This
- * appears to be happening in the VAO case. You can tell OpenGL to up
- * the cache size by issuing the following calls right after you create
- * the OpenGL context. The default cache size is 16." --ryan.
- */
+ /* End Wisdom from Apple Engineer section. --ryan. */
- #ifndef GLI_ARRAY_FUNC_CACHE_MAX
- #define GLI_ARRAY_FUNC_CACHE_MAX 284
- #endif
-
- #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
- #define GLI_SUBMIT_FUNC_CACHE_MAX 280
- #endif
-
- {
- GLint cache_max = 64;
- CGLContextObj ctx = [context CGLContextObj];
- CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
- CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
- }
- }
- /* End Wisdom from Apple Engineer section. --ryan. */
+ [pool release];
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
Cocoa_GL_DeleteContext(_this, context);
@@ -220,94 +226,107 @@
int
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
- @autoreleasepool {
- if (context) {
- SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
- NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
+ NSAutoreleasePool *pool;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ if (context) {
+ SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
+ NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
- if (window->flags & SDL_WINDOW_SHOWN) {
- #ifndef FULLSCREEN_TOGGLEABLE
- if (window->flags & SDL_WINDOW_FULLSCREEN) {
- [nscontext setFullScreen];
- } else
- #endif
- {
- [nscontext setView:[windowdata->nswindow contentView]];
- [nscontext update];
- }
+ if (window->flags & SDL_WINDOW_SHOWN) {
+#ifndef FULLSCREEN_TOGGLEABLE
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ [nscontext setFullScreen];
+ } else
+#endif
+ {
+ [nscontext setView:[windowdata->nswindow contentView]];
+ [nscontext update];
}
- [nscontext makeCurrentContext];
- } else {
- [NSOpenGLContext clearCurrentContext];
}
+ [nscontext makeCurrentContext];
+ } else {
+ [NSOpenGLContext clearCurrentContext];
}
+ [pool release];
return 0;
}
int
Cocoa_GL_SetSwapInterval(_THIS, int interval)
{
+ NSAutoreleasePool *pool;
NSOpenGLContext *nscontext;
GLint value;
int status;
- @autoreleasepool {
- nscontext = [NSOpenGLContext currentContext];
- if (nscontext != nil) {
- value = interval;
- [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
- status = 0;
- } else {
- SDL_SetError("No current OpenGL context");
- status = -1;
- }
+ pool = [[NSAutoreleasePool alloc] init];
+
+ nscontext = [NSOpenGLContext currentContext];
+ if (nscontext != nil) {
+ value = interval;
+ [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
+ status = 0;
+ } else {
+ SDL_SetError("No current OpenGL context");
+ status = -1;
}
+ [pool release];
return status;
}
int
Cocoa_GL_GetSwapInterval(_THIS)
{
+ NSAutoreleasePool *pool;
NSOpenGLContext *nscontext;
GLint value;
int status = 0;
- @autoreleasepool {
- nscontext = [NSOpenGLContext currentContext];
- if (nscontext != nil) {
- [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
- status = (int)value;
- }
+ pool = [[NSAutoreleasePool alloc] init];
+
+ nscontext = [NSOpenGLContext currentContext];
+ if (nscontext != nil) {
+ [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
+ status = (int)value;
}
+ [pool release];
return status;
}
void
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{
+ NSAutoreleasePool *pool;
NSOpenGLContext *nscontext;
- @autoreleasepool {
- /* FIXME: Do we need to get the context for the window? */
- nscontext = [NSOpenGLContext currentContext];
- if (nscontext != nil) {
- [nscontext flushBuffer];
- }
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* FIXME: Do we need to get the context for the window? */
+ nscontext = [NSOpenGLContext currentContext];
+ if (nscontext != nil) {
+ [nscontext flushBuffer];
}
+
+ [pool release];
}
void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{
+ NSAutoreleasePool *pool;
NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
- @autoreleasepool {
- [nscontext clearDrawable];
- [nscontext release];
- }
+ pool = [[NSAutoreleasePool alloc] init];
+
+ [nscontext clearDrawable];
+ [nscontext release];
+
+ [pool release];
}
#endif /* SDL_VIDEO_OPENGL_CGL */
--- a/src/video/cocoa/SDL_cocoashape.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoashape.m Mon Feb 11 17:39:52 2013 -0800
@@ -74,7 +74,7 @@
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure closure;
-
+ NSAutoreleasePool *pool = NULL;
if(data->saved == SDL_TRUE) {
[data->context restoreGraphicsState];
data->saved = SDL_FALSE;
@@ -88,13 +88,12 @@
NSRectFill([[windata->nswindow contentView] frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
- @autoreleasepool {
- closure.view = [windata->nswindow contentView];
- closure.path = [[NSBezierPath bezierPath] autorelease];
- closure.window = shaper->window;
- SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
- [closure.path addClip];
- }
+ pool = [[NSAutoreleasePool alloc] init];
+ closure.view = [windata->nswindow contentView];
+ closure.path = [[NSBezierPath bezierPath] autorelease];
+ closure.window = shaper->window;
+ SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
+ [closure.path addClip];
return 0;
}
--- a/src/video/cocoa/SDL_cocoavideo.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoavideo.m Mon Feb 11 17:39:52 2013 -0800
@@ -250,37 +250,39 @@
}
}
- @autoreleasepool {
- NSString *msg = [NSString stringWithFormat:
- @"Assertion failure at %s (%s:%d), triggered %u time%s:\n '%s'",
- data->function, data->filename, data->linenum,
- data->trigger_count, (data->trigger_count == 1) ? "" : "s",
- data->condition];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSLog(@"%@", msg);
+ NSString *msg = [NSString stringWithFormat:
+ @"Assertion failure at %s (%s:%d), triggered %u time%s:\n '%s'",
+ data->function, data->filename, data->linenum,
+ data->trigger_count, (data->trigger_count == 1) ? "" : "s",
+ data->condition];
- /*
- * !!! FIXME: this code needs to deal with fullscreen modes:
- * !!! FIXME: reset to default desktop, runModal, reset to current?
- */
+ NSLog(@"%@", msg);
+
+ /*
+ * !!! FIXME: this code needs to deal with fullscreen modes:
+ * !!! FIXME: reset to default desktop, runModal, reset to current?
+ */
- NSAlert* alert = [[NSAlert alloc] init];
- [alert setAlertStyle:NSCriticalAlertStyle];
- [alert setMessageText:msg];
- [alert addButtonWithTitle:@"Retry"];
- [alert addButtonWithTitle:@"Break"];
- [alert addButtonWithTitle:@"Abort"];
- [alert addButtonWithTitle:@"Ignore"];
- [alert addButtonWithTitle:@"Always Ignore"];
- const NSInteger clicked = [alert runModal];
- [alert release];
+ NSAlert* alert = [[NSAlert alloc] init];
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert setMessageText:msg];
+ [alert addButtonWithTitle:@"Retry"];
+ [alert addButtonWithTitle:@"Break"];
+ [alert addButtonWithTitle:@"Abort"];
+ [alert addButtonWithTitle:@"Ignore"];
+ [alert addButtonWithTitle:@"Always Ignore"];
+ const NSInteger clicked = [alert runModal];
+ [alert release];
- if (!initialized) {
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
- }
+ [pool release];
- return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
+ if (!initialized) {
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
+
+ return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
--- a/src/video/cocoa/SDL_cocoawindow.m Mon Feb 11 17:25:58 2013 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m Mon Feb 11 17:39:52 2013 -0800
@@ -507,6 +507,7 @@
static int
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
{
+ NSAutoreleasePool *pool;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *data;
@@ -521,297 +522,313 @@
data->created = created;
data->videodata = videodata;
- @autoreleasepool {
- /* Create an event listener for the window */
- data->listener = [[Cocoa_WindowListener alloc] init];
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* Create an event listener for the window */
+ data->listener = [[Cocoa_WindowListener alloc] init];
- /* Fill in the SDL window with the window data */
- {
- NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
- ConvertNSRect(&rect);
- window->x = (int)rect.origin.x;
- window->y = (int)rect.origin.y;
- window->w = (int)rect.size.width;
- window->h = (int)rect.size.height;
- }
+ /* Fill in the SDL window with the window data */
+ {
+ NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
+ ConvertNSRect(&rect);
+ window->x = (int)rect.origin.x;
+ window->y = (int)rect.origin.y;
+ window->w = (int)rect.size.width;
+ window->h = (int)rect.size.height;
+ }
- /* Set up the listener after we create the view */
- [data->listener listen:data];
+ /* Set up the listener after we create the view */
+ [data->listener listen:data];
- if ([nswindow isVisible]) {
- window->flags |= SDL_WINDOW_SHOWN;
- } else {
- window->flags &= ~SDL_WINDOW_SHOWN;
- }
- {
- unsigned int style = [nswindow styleMask];
+ if ([nswindow isVisible]) {
+ window->flags |= SDL_WINDOW_SHOWN;
+ } else {
+ window->flags &= ~SDL_WINDOW_SHOWN;
+ }
+ {
+ unsigned int style = [nswindow styleMask];
- if (style == NSBorderlessWindowMask) {
- window->flags |= SDL_WINDOW_BORDERLESS;
- } else {
- window->flags &= ~SDL_WINDOW_BORDERLESS;
- }
- if (style & NSResizableWindowMask) {
- window->flags |= SDL_WINDOW_RESIZABLE;
- } else {
- window->flags &= ~SDL_WINDOW_RESIZABLE;
- }
+ if (style == NSBorderlessWindowMask) {
+ window->flags |= SDL_WINDOW_BORDERLESS;
+ } else {
+ window->flags &= ~SDL_WINDOW_BORDERLESS;
}
- /* isZoomed always returns true if the window is not resizable */
- if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
- window->flags |= SDL_WINDOW_MAXIMIZED;
+ if (style & NSResizableWindowMask) {
+ window->flags |= SDL_WINDOW_RESIZABLE;
} else {
- window->flags &= ~SDL_WINDOW_MAXIMIZED;
- }
- if ([nswindow isMiniaturized]) {
- window->flags |= SDL_WINDOW_MINIMIZED;
- } else {
- window->flags &= ~SDL_WINDOW_MINIMIZED;
+ window->flags &= ~SDL_WINDOW_RESIZABLE;
}
- if ([nswindow isKeyWindow]) {
- window->flags |= SDL_WINDOW_INPUT_FOCUS;
- SDL_SetKeyboardFocus(data->window);
- }
+ }
+ /* isZoomed always returns true if the window is not resizable */
+ if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
+ window->flags |= SDL_WINDOW_MAXIMIZED;
+ } else {
+ window->flags &= ~SDL_WINDOW_MAXIMIZED;
+ }
+ if ([nswindow isMiniaturized]) {
+ window->flags |= SDL_WINDOW_MINIMIZED;
+ } else {
+ window->flags &= ~SDL_WINDOW_MINIMIZED;
+ }
+ if ([nswindow isKeyWindow]) {
+ window->flags |= SDL_WINDOW_INPUT_FOCUS;
+ SDL_SetKeyboardFocus(data->window);
+ }
- /* All done! */
- window->driverdata = data;
- return 0;
- }
+ /* All done! */
+ [pool release];
+ window->driverdata = data;
+ return 0;
}
int
Cocoa_CreateWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow;
- SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
- NSRect rect;
- SDL_Rect bounds;
- unsigned int style;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow;
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ NSRect rect;
+ SDL_Rect bounds;
+ unsigned int style;
- Cocoa_GetDisplayBounds(_this, display, &bounds);
- rect.origin.x = window->x;
- rect.origin.y = window->y;
- rect.size.width = window->w;
- rect.size.height = window->h;
- ConvertNSRect(&rect);
+ Cocoa_GetDisplayBounds(_this, display, &bounds);
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ rect.size.width = window->w;
+ rect.size.height = window->h;
+ ConvertNSRect(&rect);
- style = GetWindowStyle(window);
+ style = GetWindowStyle(window);
- /* Figure out which screen to place this window */
- NSArray *screens = [NSScreen screens];
- NSScreen *screen = nil;
- NSScreen *candidate;
- int i, count = [screens count];
- for (i = 0; i < count; ++i) {
- candidate = [screens objectAtIndex:i];
- NSRect screenRect = [candidate frame];
- if (rect.origin.x >= screenRect.origin.x &&
- rect.origin.x < screenRect.origin.x + screenRect.size.width &&
- rect.origin.y >= screenRect.origin.y &&
- rect.origin.y < screenRect.origin.y + screenRect.size.height) {
- screen = candidate;
- rect.origin.x -= screenRect.origin.x;
- rect.origin.y -= screenRect.origin.y;
- }
+ /* Figure out which screen to place this window */
+ NSArray *screens = [NSScreen screens];
+ NSScreen *screen = nil;
+ NSScreen *candidate;
+ int i, count = [screens count];
+ for (i = 0; i < count; ++i) {
+ candidate = [screens objectAtIndex:i];
+ NSRect screenRect = [candidate frame];
+ if (rect.origin.x >= screenRect.origin.x &&
+ rect.origin.x < screenRect.origin.x + screenRect.size.width &&
+ rect.origin.y >= screenRect.origin.y &&
+ rect.origin.y < screenRect.origin.y + screenRect.size.height) {
+ screen = candidate;
+ rect.origin.x -= screenRect.origin.x;
+ rect.origin.y -= screenRect.origin.y;
}
- nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
+ }
+ nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
- // Create a default view for this window
- rect = [nswindow contentRectForFrameRect:[nswindow frame]];
- NSView *contentView = [[SDLView alloc] initWithFrame:rect];
- [nswindow setContentView: contentView];
- [contentView release];
+ // Create a default view for this window
+ rect = [nswindow contentRectForFrameRect:[nswindow frame]];
+ NSView *contentView = [[SDLView alloc] initWithFrame:rect];
+ [nswindow setContentView: contentView];
+ [contentView release];
- if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
- [nswindow release];
- return -1;
- }
- return 0;
+ [pool release];
+
+ if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
+ [nswindow release];
+ return -1;
}
+ return 0;
}
int
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
+ NSAutoreleasePool *pool;
NSWindow *nswindow = (NSWindow *) data;
NSString *title;
- @autoreleasepool {
- /* Query the title from the existing window */
- title = [nswindow title];
- if (title) {
- window->title = SDL_strdup([title UTF8String]);
- }
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* Query the title from the existing window */
+ title = [nswindow title];
+ if (title) {
+ window->title = SDL_strdup([title UTF8String]);
}
+ [pool release];
+
return SetupWindowData(_this, window, nswindow, SDL_FALSE);
}
void
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- NSString *string;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ NSString *string;
- if(window->title) {
- string = [[NSString alloc] initWithUTF8String:window->title];
- } else {
- string = [[NSString alloc] init];
- }
- [nswindow setTitle:string];
- [string release];
+ if(window->title) {
+ string = [[NSString alloc] initWithUTF8String:window->title];
+ } else {
+ string = [[NSString alloc] init];
}
+ [nswindow setTitle:string];
+ [string release];
+
+ [pool release];
}
void
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
- @autoreleasepool {
- NSImage *nsimage = Cocoa_CreateImage(icon);
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSImage *nsimage = Cocoa_CreateImage(icon);
- if (nsimage) {
- [NSApp setApplicationIconImage:nsimage];
- }
+ if (nsimage) {
+ [NSApp setApplicationIconImage:nsimage];
}
+
+ [pool release];
}
void
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- NSRect rect;
- Uint32 moveHack;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ NSRect rect;
+ Uint32 moveHack;
+
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ rect.size.width = window->w;
+ rect.size.height = window->h;
+ ConvertNSRect(&rect);
- rect.origin.x = window->x;
- rect.origin.y = window->y;
- rect.size.width = window->w;
- rect.size.height = window->h;
- ConvertNSRect(&rect);
+ moveHack = s_moveHack;
+ s_moveHack = 0;
+ [nswindow setFrameOrigin:rect.origin];
+ s_moveHack = moveHack;
- moveHack = s_moveHack;
- s_moveHack = 0;
- [nswindow setFrameOrigin:rect.origin];
- s_moveHack = moveHack;
+ if (window == _this->current_glwin) {
+ [((NSOpenGLContext *) _this->current_glctx) update];
+ }
- if (window == _this->current_glwin) {
- [((NSOpenGLContext *) _this->current_glctx) update];
- }
- }
+ [pool release];
}
void
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
- NSWindow *nswindow = windata->nswindow;
- NSSize size;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = windata->nswindow;
+ NSSize size;
- size.width = window->w;
- size.height = window->h;
- [nswindow setContentSize:size];
+ size.width = window->w;
+ size.height = window->h;
+ [nswindow setContentSize:size];
- if (window == _this->current_glwin) {
- [((NSOpenGLContext *) _this->current_glctx) update];
- }
+ if (window == _this->current_glwin) {
+ [((NSOpenGLContext *) _this->current_glctx) update];
}
+
+ [pool release];
}
void
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
-
- NSSize minSize;
- minSize.width = window->min_w;
- minSize.height = window->min_h;
-
- [windata->nswindow setContentMinSize:minSize];
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+
+ NSSize minSize;
+ minSize.width = window->min_w;
+ minSize.height = window->min_h;
+
+ [windata->nswindow setContentMinSize:minSize];
+
+ [pool release];
}
void
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
-
- NSSize maxSize;
- maxSize.width = window->max_w;
- maxSize.height = window->max_h;
-
- [windata->nswindow setContentMaxSize:maxSize];
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+
+ NSSize maxSize;
+ maxSize.width = window->max_w;
+ maxSize.height = window->max_h;
+
+ [windata->nswindow setContentMaxSize:maxSize];
+
+ [pool release];
}
void
Cocoa_ShowWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- if (![nswindow isMiniaturized]) {
- [nswindow makeKeyAndOrderFront:nil];
- }
+ if (![nswindow isMiniaturized]) {
+ [nswindow makeKeyAndOrderFront:nil];
}
+ [pool release];
}
void
Cocoa_HideWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- [nswindow orderOut:nil];
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ [nswindow orderOut:nil];
+ [pool release];
}
void
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- [nswindow makeKeyAndOrderFront:nil];
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ [nswindow makeKeyAndOrderFront:nil];
+ [pool release];
}
void
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- [nswindow zoom:nil];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ [nswindow zoom:nil];
- if (window == _this->current_glwin) {
- [((NSOpenGLContext *) _this->current_glctx) update];
- }
+ if (window == _this->current_glwin) {
+ [((NSOpenGLContext *) _this->current_glctx) update];
}
+
+ [pool release];
}
void
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- [nswindow miniaturize:nil];
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ [nswindow miniaturize:nil];
+ [pool release];
}
void
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- if ([nswindow isMiniaturized]) {
- [nswindow deminiaturize:nil];
- } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
- [nswindow zoom:nil];
- }
+ if ([nswindow isMiniaturized]) {
+ [nswindow deminiaturize:nil];
+ } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
+ [nswindow zoom:nil];
}
+ [pool release];
}
static NSWindow *
@@ -837,95 +854,96 @@
{
/* this message arrived in 10.6. You're out of luck on older OSes. */
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
- @autoreleasepool {
- NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
- if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
- [nswindow setStyleMask:GetWindowStyle(window)];
- if (bordered) {
- Cocoa_SetWindowTitle(_this, window); // this got blanked out.
- }
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
+ [nswindow setStyleMask:GetWindowStyle(window)];
+ if (bordered) {
+ Cocoa_SetWindowTitle(_this, window); // this got blanked out.
}
}
+ [pool release];
#endif
}
void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{
- @autoreleasepool {
- SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- NSWindow *nswindow = data->nswindow;
- NSRect rect;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = data->nswindow;
+ NSRect rect;
+
+ /* The view responder chain gets messed with during setStyleMask */
+ if ([[nswindow contentView] nextResponder] == data->listener) {
+ [[nswindow contentView] setNextResponder:nil];
+ }
- /* The view responder chain gets messed with during setStyleMask */
- if ([[nswindow contentView] nextResponder] == data->listener) {
- [[nswindow contentView] setNextResponder:nil];
+ if (fullscreen) {
+ SDL_Rect bounds;
+
+ Cocoa_GetDisplayBounds(_this, display, &bounds);
+ rect.origin.x = bounds.x;
+ rect.origin.y = bounds.y;
+ rect.size.width = bounds.w;
+ rect.size.height = bounds.h;
+ ConvertNSRect(&rect);
+
+ /* Hack to fix origin on Mac OS X 10.4 */
+ NSRect screenRect = [[nswindow screen] frame];
+ if (screenRect.size.height >= 1.0f) {
+ rect.origin.y += (screenRect.size.height - rect.size.height);
}
- if (fullscreen) {
- SDL_Rect bounds;
-
- Cocoa_GetDisplayBounds(_this, display, &bounds);
- rect.origin.x = bounds.x;
- rect.origin.y = bounds.y;
- rect.size.width = bounds.w;
- rect.size.height = bounds.h;
- ConvertNSRect(&rect);
-
- /* Hack to fix origin on Mac OS X 10.4 */
- NSRect screenRect = [[nswindow screen] frame];
- if (screenRect.size.height >= 1.0f) {
- rect.origin.y += (screenRect.size.height - rect.size.height);
- }
-
- if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
- [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
- } else {
- nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
- }
+ if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
+ [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
} else {
- rect.origin.x = window->windowed.x;
- rect.origin.y = window->windowed.y;
- rect.size.width = window->windowed.w;
- rect.size.height = window->windowed.h;
- ConvertNSRect(&rect);
+ nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
+ }
+ } else {
+ rect.origin.x = window->windowed.x;
+ rect.origin.y = window->windowed.y;
+ rect.size.width = window->windowed.w;
+ rect.size.height = window->windowed.h;
+ ConvertNSRect(&rect);
- if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
- [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
- } else {
- nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
- }
- }
-
- /* The view responder chain gets messed with during setStyleMask */
- if ([[nswindow contentView] nextResponder] != data->listener) {
- [[nswindow contentView] setNextResponder:data->listener];
- }
-
- s_moveHack = 0;
- [nswindow setFrameOrigin:rect.origin];
- [nswindow setContentSize:rect.size];
- s_moveHack = SDL_GetTicks();
-
- /* When the window style changes the title is cleared */
- if (!fullscreen) {
- Cocoa_SetWindowTitle(_this, window);
- }
-
- #ifdef FULLSCREEN_TOGGLEABLE
- if (SDL_ShouldAllowTopmost() && fullscreen) {
- /* OpenGL is rendering to the window, so make it visible! */
- [nswindow setLevel:CGShieldingWindowLevel()];
+ if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
+ [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
} else {
- [nswindow setLevel:kCGNormalWindowLevel];
- }
- #endif
- [nswindow makeKeyAndOrderFront:nil];
-
- if (window == _this->current_glwin) {
- [((NSOpenGLContext *) _this->current_glctx) update];
+ nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
}
}
+
+ /* The view responder chain gets messed with during setStyleMask */
+ if ([[nswindow contentView] nextResponder] != data->listener) {
+ [[nswindow contentView] setNextResponder:data->listener];
+ }
+
+ s_moveHack = 0;
+ [nswindow setFrameOrigin:rect.origin];
+ [nswindow setContentSize:rect.size];
+ s_moveHack = SDL_GetTicks();
+
+ /* When the window style changes the title is cleared */
+ if (!fullscreen) {
+ Cocoa_SetWindowTitle(_this, window);
+ }
+
+#ifdef FULLSCREEN_TOGGLEABLE
+ if (SDL_ShouldAllowTopmost() && fullscreen) {
+ /* OpenGL is rendering to the window, so make it visible! */
+ [nswindow setLevel:CGShieldingWindowLevel()];
+ } else {
+ [nswindow setLevel:kCGNormalWindowLevel];
+ }
+#endif
+ [nswindow makeKeyAndOrderFront:nil];
+
+ if (window == _this->current_glwin) {
+ [((NSOpenGLContext *) _this->current_glctx) update];
+ }
+
+ [pool release];
}
int
@@ -1009,18 +1027,18 @@
void
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
{
- @autoreleasepool {
- SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- if (data) {
- [data->listener close];
- [data->listener release];
- if (data->created) {
- [data->nswindow close];
- }
- SDL_free(data);
+ if (data) {
+ [data->listener close];
+ [data->listener release];
+ if (data->created) {
+ [data->nswindow close];
}
+ SDL_free(data);
}
+ [pool release];
}
SDL_bool
--- a/test/automated/rwops/TestSupportRWops_Cocoa.m Mon Feb 11 17:25:58 2013 -0800
+++ b/test/automated/rwops/TestSupportRWops_Cocoa.m Mon Feb 11 17:39:52 2013 -0800
@@ -21,23 +21,30 @@
FILE* fp = NULL;
// If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only.
- if (strcmp("r", mode) && strcmp("rb", mode)) {
+ if(strcmp("r", mode) && strcmp("rb", mode))
+ {
return fopen(file, mode);
}
- @autoreleasepool {
- NSFileManager* file_manager = [NSFileManager defaultManager];
- NSString* resource_path = [[NSBundle mainBundle] resourcePath];
+ NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+
- NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
+ NSFileManager* file_manager = [NSFileManager defaultManager];
+ NSString* resource_path = [[NSBundle mainBundle] resourcePath];
+
+ NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
- NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
- if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
- fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
- } else {
- fp = fopen(file, mode);
- }
- }
+ NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
+ if([file_manager fileExistsAtPath:full_path_with_file_to_try])
+ {
+ fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
+ }
+ else
+ {
+ fp = fopen(file, mode);
+ }
+
+ [autorelease_pool drain];
return fp;
}
@@ -46,14 +53,16 @@
{
FILE* fp = NULL;
- @autoreleasepool {
- NSFileManager* file_manager = [NSFileManager defaultManager];
- NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
- NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
+ NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+
+ NSFileManager* file_manager = [NSFileManager defaultManager];
+ NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
+ NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
- fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
- }
-
+ fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
+
+ [autorelease_pool drain];
+
return fp;
}
@@ -66,14 +75,15 @@
{
SDL_RWops* rw = NULL;
- @autoreleasepool {
- NSFileManager* file_manager = [NSFileManager defaultManager];
- NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
- NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
-
- rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
- }
-
+ NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+
+ NSFileManager* file_manager = [NSFileManager defaultManager];
+ NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
+ NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
+
+ rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
+
+ [autorelease_pool drain];
return rw;
}