metal: Cleaned up some reference count politics.

This commit is contained in:
Ryan C. Gordon 2017-12-08 18:26:26 -05:00
parent 7cb8b50ad8
commit 686fc0937e
1 changed files with 6 additions and 18 deletions

View File

@ -394,14 +394,10 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
default: return SDL_SetError("Texture format %s not supported by Metal", SDL_GetPixelFormatName(texture->format)); default: return SDL_SetError("Texture format %s not supported by Metal", SDL_GetPixelFormatName(texture->format));
} }
// !!! FIXME: autorelease or nah?
MTLTextureDescriptor *mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mtlpixfmt MTLTextureDescriptor *mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mtlpixfmt
width:(NSUInteger)texture->w height:(NSUInteger)texture->h mipmapped:NO]; width:(NSUInteger)texture->w height:(NSUInteger)texture->h mipmapped:NO];
id<MTLTexture> mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc]; id<MTLTexture> mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
#if !__has_feature(objc_arc)
[mtltexdesc release];
#endif
if (mtltexture == nil) { if (mtltexture == nil) {
return SDL_SetError("Texture allocation failed"); return SDL_SetError("Texture allocation failed");
} }
@ -734,11 +730,6 @@ METAL_RenderPresent(SDL_Renderer * renderer)
[data.mtlcmdencoder endEncoding]; [data.mtlcmdencoder endEncoding];
[data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer]; [data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer];
[data.mtlcmdbuffer commit]; [data.mtlcmdbuffer commit];
#if !__has_feature(objc_arc)
[data.mtlcmdencoder release];
[data.mtlcmdbuffer release];
[data.mtlbackbuffer release];
#endif
data.mtlcmdencoder = nil; data.mtlcmdencoder = nil;
data.mtlcmdbuffer = nil; data.mtlcmdbuffer = nil;
data.mtlbackbuffer = nil; data.mtlbackbuffer = nil;
@ -761,17 +752,14 @@ METAL_DestroyRenderer(SDL_Renderer * renderer)
if (renderer->driverdata) { if (renderer->driverdata) {
METAL_RenderData *data = CFBridgingRelease(renderer->driverdata); METAL_RenderData *data = CFBridgingRelease(renderer->driverdata);
#if !__has_feature(objc_arc)
if (data.mtlbackbuffer != nil) {
[data.mtlbackbuffer release];
}
if (data.mtlcmdencoder != nil) { if (data.mtlcmdencoder != nil) {
[data.mtlcmdencoder endEncoding]; [data.mtlcmdencoder endEncoding];
}
#if !__has_feature(objc_arc)
[data.mtlbackbuffer release];
[data.mtlcmdencoder release]; [data.mtlcmdencoder release];
}
if (data.mtlcmdbuffer != nil) {
[data.mtlcmdbuffer release]; [data.mtlcmdbuffer release];
}
[data.mtlcmdqueue release]; [data.mtlcmdqueue release];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
[data.mtlpipelineprims[i] release]; [data.mtlpipelineprims[i] release];
@ -784,9 +772,9 @@ METAL_DestroyRenderer(SDL_Renderer * renderer)
[data.mtldevice release]; [data.mtldevice release];
[data.mtlpassdesc release]; [data.mtlpassdesc release];
[data.mtllayer release]; [data.mtllayer release];
[data release];
#endif #endif
} }
SDL_free(renderer); SDL_free(renderer);
}} }}