src/render/metal/SDL_render_metal.m
changeset 11743 3af68ade4d30
parent 11742 971cd689bd96
child 11744 4d97d8cdaa90
     1.1 --- a/src/render/metal/SDL_render_metal.m	Fri Dec 08 14:03:36 2017 -0500
     1.2 +++ b/src/render/metal/SDL_render_metal.m	Fri Dec 08 13:20:20 2017 -0800
     1.3 @@ -370,17 +370,17 @@
     1.4  
     1.5  static int
     1.6  METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
     1.7 -{
     1.8 +{ @autoreleasepool {
     1.9      METAL_ActivateRenderer(renderer);
    1.10      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    1.11      *w = (int) data.mtlbackbuffer.texture.width;
    1.12      *h = (int) data.mtlbackbuffer.texture.height;
    1.13      return 0;
    1.14 -}
    1.15 +}}
    1.16  
    1.17  static int
    1.18  METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    1.19 -{
    1.20 +{ @autoreleasepool {
    1.21      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    1.22      MTLPixelFormat mtlpixfmt;
    1.23  
    1.24 @@ -405,12 +405,12 @@
    1.25      texture->driverdata = (void*)CFBridgingRetain(mtltexture);
    1.26  
    1.27      return 0;
    1.28 -}
    1.29 +}}
    1.30  
    1.31  static int
    1.32  METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.33                   const SDL_Rect * rect, const void *pixels, int pitch)
    1.34 -{
    1.35 +{ @autoreleasepool {
    1.36      // !!! FIXME: this is a synchronous call; it doesn't return until data is uploaded in some form.
    1.37      // !!! FIXME:  Maybe move this off to a thread that marks the texture as uploaded and only stall the main thread if we try to
    1.38      // !!! FIXME:  use this texture before the marking is done? Is it worth it? Or will we basically always be uploading a bunch of
    1.39 @@ -418,7 +418,7 @@
    1.40      id<MTLTexture> mtltexture = (__bridge id<MTLTexture>) texture->driverdata;
    1.41      [mtltexture replaceRegion:MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h) mipmapLevel:0 withBytes:pixels bytesPerRow:pitch];
    1.42      return 0;
    1.43 -}
    1.44 +}}
    1.45  
    1.46  static int
    1.47  METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
    1.48 @@ -445,17 +445,17 @@
    1.49  
    1.50  static int
    1.51  METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
    1.52 -{
    1.53 +{ @autoreleasepool {
    1.54      METAL_ActivateRenderer(renderer);
    1.55      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    1.56      id<MTLTexture> mtltexture = texture ? (__bridge id<MTLTexture>) texture->driverdata : nil;
    1.57      data.mtlpassdesc.colorAttachments[0].texture = mtltexture;
    1.58      return 0;
    1.59 -}
    1.60 +}}
    1.61  
    1.62  static int
    1.63  METAL_UpdateViewport(SDL_Renderer * renderer)
    1.64 -{
    1.65 +{ @autoreleasepool {
    1.66      METAL_ActivateRenderer(renderer);
    1.67      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    1.68      MTLViewport viewport;
    1.69 @@ -467,15 +467,15 @@
    1.70      viewport.zfar = 1.0;
    1.71      [data.mtlcmdencoder setViewport:viewport];
    1.72      return 0;
    1.73 -}
    1.74 +}}
    1.75  
    1.76  static int
    1.77  METAL_UpdateClipRect(SDL_Renderer * renderer)
    1.78 -{
    1.79 -    // !!! FIXME: should this care about the viewport?
    1.80 +{ @autoreleasepool {
    1.81      METAL_ActivateRenderer(renderer);
    1.82      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    1.83      MTLScissorRect mtlrect;
    1.84 +    // !!! FIXME: should this care about the viewport?
    1.85      if (renderer->clipping_enabled) {
    1.86          const SDL_Rect *rect = &renderer->clip_rect;
    1.87          mtlrect.x = renderer->viewport.x + rect->x;
    1.88 @@ -492,11 +492,11 @@
    1.89          [data.mtlcmdencoder setScissorRect:mtlrect];
    1.90      }
    1.91      return 0;
    1.92 -}
    1.93 +}}
    1.94  
    1.95  static int
    1.96  METAL_RenderClear(SDL_Renderer * renderer)
    1.97 -{
    1.98 +{ @autoreleasepool {
    1.99      // We could dump the command buffer and force a clear on a new one, but this will respect the scissor state.
   1.100      METAL_ActivateRenderer(renderer);
   1.101      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
   1.102 @@ -528,7 +528,7 @@
   1.103      [data.mtlcmdencoder setViewport:viewport];
   1.104  
   1.105      return 0;
   1.106 -}
   1.107 +}}
   1.108  
   1.109  // normalize a value from 0.0f to len into -1.0f to 1.0f.
   1.110  static inline float
   1.111 @@ -556,7 +556,7 @@
   1.112  static int
   1.113  DrawVerts(SDL_Renderer * renderer, const SDL_FPoint * points, int count,
   1.114            const MTLPrimitiveType primtype)
   1.115 -{
   1.116 +{ @autoreleasepool {
   1.117      METAL_ActivateRenderer(renderer);
   1.118  
   1.119      const size_t vertlen = (sizeof (float) * 2) * count;
   1.120 @@ -588,7 +588,7 @@
   1.121  
   1.122      SDL_free(verts);
   1.123      return 0;
   1.124 -}
   1.125 +}}
   1.126  
   1.127  static int
   1.128  METAL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, int count)
   1.129 @@ -604,7 +604,7 @@
   1.130  
   1.131  static int
   1.132  METAL_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
   1.133 -{
   1.134 +{ @autoreleasepool {
   1.135      METAL_ActivateRenderer(renderer);
   1.136      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
   1.137  
   1.138 @@ -633,12 +633,12 @@
   1.139      }
   1.140  
   1.141      return 0;
   1.142 -}
   1.143 +}}
   1.144  
   1.145  static int
   1.146  METAL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.147                const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   1.148 -{
   1.149 +{ @autoreleasepool {
   1.150      METAL_ActivateRenderer(renderer);
   1.151      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
   1.152      id<MTLTexture> mtltexture = (__bridge id<MTLTexture>) texture->driverdata;
   1.153 @@ -679,7 +679,7 @@
   1.154      [data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:5];
   1.155  
   1.156      return 0;
   1.157 -}
   1.158 +}}
   1.159  
   1.160  static int
   1.161  METAL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
   1.162 @@ -692,7 +692,7 @@
   1.163  static int
   1.164  METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.165                      Uint32 pixel_format, void * pixels, int pitch)
   1.166 -{
   1.167 +{ @autoreleasepool {
   1.168      METAL_ActivateRenderer(renderer);
   1.169      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
   1.170      MTLRenderPassColorAttachmentDescriptor *colorAttachment = data.mtlpassdesc.colorAttachments[0];
   1.171 @@ -719,11 +719,11 @@
   1.172      const int status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch);
   1.173      SDL_free(temp_pixels);
   1.174      return status;
   1.175 -}
   1.176 +}}
   1.177  
   1.178  static void
   1.179  METAL_RenderPresent(SDL_Renderer * renderer)
   1.180 -{
   1.181 +{ @autoreleasepool {
   1.182      METAL_ActivateRenderer(renderer);
   1.183      METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
   1.184  
   1.185 @@ -739,21 +739,21 @@
   1.186      data.mtlcmdbuffer = nil;
   1.187      data.mtlbackbuffer = nil;
   1.188      data.beginScene = YES;
   1.189 -}
   1.190 +}}
   1.191  
   1.192  static void
   1.193  METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.194 -{
   1.195 +{ @autoreleasepool {
   1.196      id<MTLTexture> mtltexture = CFBridgingRelease(texture->driverdata);
   1.197  #if !__has_feature(objc_arc)
   1.198      [mtltexture release];
   1.199  #endif
   1.200      texture->driverdata = NULL;
   1.201 -}
   1.202 +}}
   1.203  
   1.204  static void
   1.205  METAL_DestroyRenderer(SDL_Renderer * renderer)
   1.206 -{
   1.207 +{ @autoreleasepool {
   1.208      if (renderer->driverdata) {
   1.209          METAL_RenderData *data = CFBridgingRelease(renderer->driverdata);
   1.210  
   1.211 @@ -784,7 +784,7 @@
   1.212  #endif
   1.213      }
   1.214      SDL_free(renderer);
   1.215 -}
   1.216 +}}
   1.217  
   1.218  #endif /* SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED */
   1.219