src/video/cocoa/SDL_cocoawindow.m
changeset 9587 18979eac0a35
parent 9474 067b78126485
child 9619 b94b6d0bff0f
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue May 05 16:24:05 2015 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue May 05 19:01:55 2015 -0300
     1.3 @@ -1000,8 +1000,8 @@
     1.4  
     1.5  static int
     1.6  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
     1.7 +{ @autoreleasepool
     1.8  {
     1.9 -    NSAutoreleasePool *pool;
    1.10      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    1.11      SDL_WindowData *data;
    1.12  
    1.13 @@ -1016,8 +1016,6 @@
    1.14      data->videodata = videodata;
    1.15      data->nscontexts = [[NSMutableArray alloc] init];
    1.16  
    1.17 -    pool = [[NSAutoreleasePool alloc] init];
    1.18 -
    1.19      /* Create an event listener for the window */
    1.20      data->listener = [[Cocoa_WindowListener alloc] init];
    1.21  
    1.22 @@ -1079,16 +1077,15 @@
    1.23      [nswindow setOneShot:NO];
    1.24  
    1.25      /* All done! */
    1.26 -    [pool release];
    1.27      window->driverdata = data;
    1.28      return 0;
    1.29 -}
    1.30 +}}
    1.31  
    1.32  int
    1.33  Cocoa_CreateWindow(_THIS, SDL_Window * window)
    1.34 +{ @autoreleasepool
    1.35  {
    1.36      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    1.37 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.38      NSWindow *nswindow;
    1.39      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.40      NSRect rect;
    1.41 @@ -1123,9 +1120,7 @@
    1.42          nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
    1.43      }
    1.44      @catch (NSException *e) {
    1.45 -        SDL_SetError("%s", [[e reason] UTF8String]);
    1.46 -        [pool release];
    1.47 -        return -1;
    1.48 +        return SDL_SetError("%s", [[e reason] UTF8String]);
    1.49      }
    1.50      [nswindow setBackgroundColor:[NSColor blackColor]];
    1.51  
    1.52 @@ -1155,63 +1150,54 @@
    1.53      /* Allow files and folders to be dragged onto the window by users */
    1.54      [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
    1.55  
    1.56 -    [pool release];
    1.57 -
    1.58      if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
    1.59          [nswindow release];
    1.60          return -1;
    1.61      }
    1.62      return 0;
    1.63 -}
    1.64 +}}
    1.65  
    1.66  int
    1.67  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
    1.68 +{ @autoreleasepool
    1.69  {
    1.70 -    NSAutoreleasePool *pool;
    1.71      NSWindow *nswindow = (NSWindow *) data;
    1.72      NSString *title;
    1.73  
    1.74 -    pool = [[NSAutoreleasePool alloc] init];
    1.75 -
    1.76      /* Query the title from the existing window */
    1.77      title = [nswindow title];
    1.78      if (title) {
    1.79          window->title = SDL_strdup([title UTF8String]);
    1.80      }
    1.81  
    1.82 -    [pool release];
    1.83 -
    1.84      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
    1.85 -}
    1.86 +}}
    1.87  
    1.88  void
    1.89  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
    1.90 +{ @autoreleasepool
    1.91  {
    1.92 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.93      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
    1.94      NSString *string = [[NSString alloc] initWithUTF8String:window->title];
    1.95      [nswindow setTitle:string];
    1.96      [string release];
    1.97 -    [pool release];
    1.98 -}
    1.99 +}}
   1.100  
   1.101  void
   1.102  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
   1.103 +{ @autoreleasepool
   1.104  {
   1.105 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.106      NSImage *nsimage = Cocoa_CreateImage(icon);
   1.107  
   1.108      if (nsimage) {
   1.109          [NSApp setApplicationIconImage:nsimage];
   1.110      }
   1.111 -
   1.112 -    [pool release];
   1.113 -}
   1.114 +}}
   1.115  
   1.116  void
   1.117  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
   1.118 +{ @autoreleasepool
   1.119  {
   1.120 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.121      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.122      NSWindow *nswindow = windata->nswindow;
   1.123      NSRect rect;
   1.124 @@ -1229,14 +1215,12 @@
   1.125      s_moveHack = moveHack;
   1.126  
   1.127      ScheduleContextUpdates(windata);
   1.128 -
   1.129 -    [pool release];
   1.130 -}
   1.131 +}}
   1.132  
   1.133  void
   1.134  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
   1.135 +{ @autoreleasepool
   1.136  {
   1.137 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.138      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.139      NSWindow *nswindow = windata->nswindow;
   1.140      NSSize size;
   1.141 @@ -1246,14 +1230,12 @@
   1.142      [nswindow setContentSize:size];
   1.143  
   1.144      ScheduleContextUpdates(windata);
   1.145 -
   1.146 -    [pool release];
   1.147 -}
   1.148 +}}
   1.149  
   1.150  void
   1.151  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
   1.152 +{ @autoreleasepool
   1.153  {
   1.154 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.155      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.156  
   1.157      NSSize minSize;
   1.158 @@ -1261,14 +1243,12 @@
   1.159      minSize.height = window->min_h;
   1.160  
   1.161      [windata->nswindow setContentMinSize:minSize];
   1.162 -
   1.163 -    [pool release];
   1.164 -}
   1.165 +}}
   1.166  
   1.167  void
   1.168  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
   1.169 +{ @autoreleasepool
   1.170  {
   1.171 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.172      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.173  
   1.174      NSSize maxSize;
   1.175 @@ -1276,14 +1256,12 @@
   1.176      maxSize.height = window->max_h;
   1.177  
   1.178      [windata->nswindow setContentMaxSize:maxSize];
   1.179 -
   1.180 -    [pool release];
   1.181 -}
   1.182 +}}
   1.183  
   1.184  void
   1.185  Cocoa_ShowWindow(_THIS, SDL_Window * window)
   1.186 +{ @autoreleasepool
   1.187  {
   1.188 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.189      SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
   1.190      NSWindow *nswindow = windowData->nswindow;
   1.191  
   1.192 @@ -1292,23 +1270,21 @@
   1.193          [nswindow makeKeyAndOrderFront:nil];
   1.194          [windowData->listener resumeVisibleObservation];
   1.195      }
   1.196 -    [pool release];
   1.197 -}
   1.198 +}}
   1.199  
   1.200  void
   1.201  Cocoa_HideWindow(_THIS, SDL_Window * window)
   1.202 +{ @autoreleasepool
   1.203  {
   1.204 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.205      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.206  
   1.207      [nswindow orderOut:nil];
   1.208 -    [pool release];
   1.209 -}
   1.210 +}}
   1.211  
   1.212  void
   1.213  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   1.214 +{ @autoreleasepool
   1.215  {
   1.216 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.217      SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
   1.218      NSWindow *nswindow = windowData->nswindow;
   1.219  
   1.220 @@ -1321,28 +1297,24 @@
   1.221          [nswindow makeKeyAndOrderFront:nil];
   1.222      }
   1.223      [windowData->listener resumeVisibleObservation];
   1.224 -
   1.225 -    [pool release];
   1.226 -}
   1.227 +}}
   1.228  
   1.229  void
   1.230  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   1.231 +{ @autoreleasepool
   1.232  {
   1.233 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.234      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.235      NSWindow *nswindow = windata->nswindow;
   1.236  
   1.237      [nswindow zoom:nil];
   1.238  
   1.239      ScheduleContextUpdates(windata);
   1.240 -
   1.241 -    [pool release];
   1.242 -}
   1.243 +}}
   1.244  
   1.245  void
   1.246  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   1.247 +{ @autoreleasepool
   1.248  {
   1.249 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.250      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.251      NSWindow *nswindow = data->nswindow;
   1.252  
   1.253 @@ -1351,13 +1323,12 @@
   1.254      } else {
   1.255          [nswindow miniaturize:nil];
   1.256      }
   1.257 -    [pool release];
   1.258 -}
   1.259 +}}
   1.260  
   1.261  void
   1.262  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
   1.263 +{ @autoreleasepool
   1.264  {
   1.265 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.266      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.267  
   1.268      if ([nswindow isMiniaturized]) {
   1.269 @@ -1365,8 +1336,7 @@
   1.270      } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   1.271          [nswindow zoom:nil];
   1.272      }
   1.273 -    [pool release];
   1.274 -}
   1.275 +}}
   1.276  
   1.277  static NSWindow *
   1.278  Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
   1.279 @@ -1391,21 +1361,20 @@
   1.280  
   1.281  void
   1.282  Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
   1.283 +{ @autoreleasepool
   1.284  {
   1.285 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.286      if (SetWindowStyle(window, GetWindowStyle(window))) {
   1.287          if (bordered) {
   1.288              Cocoa_SetWindowTitle(_this, window);  /* this got blanked out. */
   1.289          }
   1.290      }
   1.291 -    [pool release];
   1.292 -}
   1.293 +}}
   1.294  
   1.295  
   1.296  void
   1.297  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   1.298 +{ @autoreleasepool
   1.299  {
   1.300 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.301      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.302      NSWindow *nswindow = data->nswindow;
   1.303      NSRect rect;
   1.304 @@ -1479,9 +1448,7 @@
   1.305      }
   1.306  
   1.307      ScheduleContextUpdates(data);
   1.308 -
   1.309 -    [pool release];
   1.310 -}
   1.311 +}}
   1.312  
   1.313  int
   1.314  Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
   1.315 @@ -1564,8 +1531,8 @@
   1.316  
   1.317  void
   1.318  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
   1.319 +{ @autoreleasepool
   1.320  {
   1.321 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.322      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.323  
   1.324      if (data) {
   1.325 @@ -1585,9 +1552,7 @@
   1.326          SDL_free(data);
   1.327      }
   1.328      window->driverdata = NULL;
   1.329 -
   1.330 -    [pool release];
   1.331 -}
   1.332 +}}
   1.333  
   1.334  SDL_bool
   1.335  Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   1.336 @@ -1619,9 +1584,9 @@
   1.337  
   1.338  SDL_bool
   1.339  Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
   1.340 +{ @autoreleasepool
   1.341  {
   1.342      SDL_bool succeeded = SDL_FALSE;
   1.343 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.344      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.345  
   1.346      if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
   1.347 @@ -1642,10 +1607,8 @@
   1.348          }
   1.349      }
   1.350  
   1.351 -    [pool release];
   1.352 -
   1.353      return succeeded;
   1.354 -}
   1.355 +}}
   1.356  
   1.357  int
   1.358  Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)