Replaced all remaining uses of NSAutoreleasePool with @autoreleasepool blocks (bugzilla #2680.)

This commit is contained in:
Alex Szpakowski 2015-05-05 19:01:55 -03:00
parent 6c20b68257
commit 4fc4026660
3 changed files with 53 additions and 117 deletions

View File

@ -150,8 +150,8 @@ Cocoa_GL_UnloadLibrary(_THIS)
SDL_GLContext
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
@ -173,8 +173,6 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
return NULL;
}
pool = [[NSAutoreleasePool alloc] init];
/* specify a profile if we're on Lion (10.7) or later. */
if (lion_or_later) {
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
@ -239,7 +237,6 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
if (fmt == nil) {
SDL_SetError("Failed creating OpenGL pixel format");
[pool release];
return NULL;
}
@ -253,12 +250,9 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
if (context == nil) {
SDL_SetError("Failed creating OpenGL context");
[pool release];
return NULL;
}
[pool release];
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError("Failed making OpenGL context current");
@ -306,15 +300,12 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
/*_this->gl_config.minor_version = glversion_minor;*/
}
return context;
}
}}
int
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
if (context) {
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
[nscontext setWindow:window];
@ -324,9 +315,8 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
[NSOpenGLContext clearCurrentContext];
}
[pool release];
return 0;
}
}}
void
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
@ -352,8 +342,8 @@ Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
int
Cocoa_GL_SetSwapInterval(_THIS, int interval)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
NSOpenGLContext *nscontext;
GLint value;
int status;
@ -362,8 +352,6 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval)
return SDL_SetError("Late swap tearing currently unsupported");
}
pool = [[NSAutoreleasePool alloc] init];
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
value = interval;
@ -373,57 +361,44 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval)
status = SDL_SetError("No current OpenGL context");
}
[pool release];
return status;
}
}}
int
Cocoa_GL_GetSwapInterval(_THIS)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
NSOpenGLContext *nscontext;
GLint value;
int status = 0;
pool = [[NSAutoreleasePool alloc] init];
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
[nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
status = (int)value;
}
[pool release];
return status;
}
}}
void
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
[nscontext flushBuffer];
[nscontext updateIfNeeded];
[pool release];
}
}}
void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
pool = [[NSAutoreleasePool alloc] init];
[nscontext setWindow:NULL];
[nscontext release];
[pool release];
}
}}
#endif /* SDL_VIDEO_OPENGL_CGL */

View File

@ -75,11 +75,11 @@ ConvertRects(SDL_ShapeTree* tree, void* closure)
int
Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{ @autoreleasepool
{
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;
@ -93,16 +93,14 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowSha
NSRectFill([[windata->nswindow contentView] frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
pool = [[NSAutoreleasePool alloc] init];
closure.view = [windata->nswindow contentView];
closure.path = [NSBezierPath bezierPath];
closure.window = shaper->window;
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
[closure.path addClip];
[pool release];
return 0;
}
}}
int
Cocoa_ResizeWindowShape(SDL_Window *window)

View File

@ -1000,8 +1000,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
static int
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *data;
@ -1016,8 +1016,6 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
data->videodata = videodata;
data->nscontexts = [[NSMutableArray alloc] init];
pool = [[NSAutoreleasePool alloc] init];
/* Create an event listener for the window */
data->listener = [[Cocoa_WindowListener alloc] init];
@ -1079,16 +1077,15 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
[nswindow setOneShot:NO];
/* All done! */
[pool release];
window->driverdata = data;
return 0;
}
}}
int
Cocoa_CreateWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
NSRect rect;
@ -1123,9 +1120,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
}
@catch (NSException *e) {
SDL_SetError("%s", [[e reason] UTF8String]);
[pool release];
return -1;
return SDL_SetError("%s", [[e reason] UTF8String]);
}
[nswindow setBackgroundColor:[NSColor blackColor]];
@ -1155,63 +1150,54 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
/* Allow files and folders to be dragged onto the window by users */
[nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
[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)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
NSWindow *nswindow = (NSWindow *) data;
NSString *title;
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
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
NSString *string = [[NSString alloc] initWithUTF8String:window->title];
[nswindow setTitle:string];
[string release];
[pool release];
}
}}
void
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSImage *nsimage = Cocoa_CreateImage(icon);
if (nsimage) {
[NSApp setApplicationIconImage:nsimage];
}
[pool release];
}
}}
void
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSWindow *nswindow = windata->nswindow;
NSRect rect;
@ -1229,14 +1215,12 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
s_moveHack = moveHack;
ScheduleContextUpdates(windata);
[pool release];
}
}}
void
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSWindow *nswindow = windata->nswindow;
NSSize size;
@ -1246,14 +1230,12 @@ Cocoa_SetWindowSize(_THIS, SDL_Window * window)
[nswindow setContentSize:size];
ScheduleContextUpdates(windata);
[pool release];
}
}}
void
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSSize minSize;
@ -1261,14 +1243,12 @@ Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
minSize.height = window->min_h;
[windata->nswindow setContentMinSize:minSize];
[pool release];
}
}}
void
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSSize maxSize;
@ -1276,14 +1256,12 @@ Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
maxSize.height = window->max_h;
[windata->nswindow setContentMaxSize:maxSize];
[pool release];
}
}}
void
Cocoa_ShowWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
NSWindow *nswindow = windowData->nswindow;
@ -1292,23 +1270,21 @@ Cocoa_ShowWindow(_THIS, SDL_Window * window)
[nswindow makeKeyAndOrderFront:nil];
[windowData->listener resumeVisibleObservation];
}
[pool release];
}
}}
void
Cocoa_HideWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
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
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
NSWindow *nswindow = windowData->nswindow;
@ -1321,28 +1297,24 @@ Cocoa_RaiseWindow(_THIS, SDL_Window * window)
[nswindow makeKeyAndOrderFront:nil];
}
[windowData->listener resumeVisibleObservation];
[pool release];
}
}}
void
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSWindow *nswindow = windata->nswindow;
[nswindow zoom:nil];
ScheduleContextUpdates(windata);
[pool release];
}
}}
void
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data->nswindow;
@ -1351,13 +1323,12 @@ Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
} else {
[nswindow miniaturize:nil];
}
[pool release];
}
}}
void
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
if ([nswindow isMiniaturized]) {
@ -1365,8 +1336,7 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
} else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
[nswindow zoom:nil];
}
[pool release];
}
}}
static NSWindow *
Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
@ -1391,21 +1361,20 @@ Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
void
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (SetWindowStyle(window, GetWindowStyle(window))) {
if (bordered) {
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
}
}
[pool release];
}
}}
void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data->nswindow;
NSRect rect;
@ -1479,9 +1448,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
}
ScheduleContextUpdates(data);
[pool release];
}
}}
int
Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
@ -1564,8 +1531,8 @@ Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
void
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (data) {
@ -1585,9 +1552,7 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
SDL_free(data);
}
window->driverdata = NULL;
[pool release];
}
}}
SDL_bool
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
@ -1619,9 +1584,9 @@ Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
SDL_bool
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
{ @autoreleasepool
{
SDL_bool succeeded = SDL_FALSE;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
@ -1642,10 +1607,8 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
}
}
[pool release];
return succeeded;
}
}}
int
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)