Skip to content

Commit

Permalink
Replaced all remaining uses of NSAutoreleasePool with @autoreleasepool
Browse files Browse the repository at this point in the history
…blocks (bugzilla #2680.)
  • Loading branch information
slime73 committed May 5, 2015
1 parent 6c20b68 commit 4fc4026
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 117 deletions.
49 changes: 12 additions & 37 deletions src/video/cocoa/SDL_cocoaopengl.m
Expand Up @@ -150,8 +150,8 @@ - (void)setWindow:(SDL_Window *)newWindow

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;
Expand All @@ -173,8 +173,6 @@ - (void)setWindow:(SDL_Window *)newWindow
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;
Expand Down Expand Up @@ -239,7 +237,6 @@ - (void)setWindow:(SDL_Window *)newWindow
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
if (fmt == nil) {
SDL_SetError("Failed creating OpenGL pixel format");
[pool release];
return NULL;
}

Expand All @@ -253,12 +250,9 @@ - (void)setWindow:(SDL_Window *)newWindow

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");
Expand Down Expand Up @@ -306,15 +300,12 @@ - (void)setWindow:(SDL_Window *)newWindow
/*_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];
Expand All @@ -324,9 +315,8 @@ - (void)setWindow:(SDL_Window *)newWindow
[NSOpenGLContext clearCurrentContext];
}

[pool release];
return 0;
}
}}

void
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
Expand All @@ -352,8 +342,8 @@ - (void)setWindow:(SDL_Window *)newWindow

int
Cocoa_GL_SetSwapInterval(_THIS, int interval)
{ @autoreleasepool
{
NSAutoreleasePool *pool;
NSOpenGLContext *nscontext;
GLint value;
int status;
Expand All @@ -362,8 +352,6 @@ - (void)setWindow:(SDL_Window *)newWindow
return SDL_SetError("Late swap tearing currently unsupported");
}

pool = [[NSAutoreleasePool alloc] init];

nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
value = interval;
Expand All @@ -373,57 +361,44 @@ - (void)setWindow:(SDL_Window *)newWindow
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 */

Expand Down
6 changes: 2 additions & 4 deletions src/video/cocoa/SDL_cocoashape.m
Expand Up @@ -75,11 +75,11 @@

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;
Expand All @@ -93,16 +93,14 @@
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)
Expand Down

0 comments on commit 4fc4026

Please sign in to comment.