mirror of
https://github.com/encounter/SDL.git
synced 2025-12-20 18:29:22 +00:00
extend the code hidden by SDL_HAVE_YUV
This commit is contained in:
@@ -167,11 +167,12 @@ typedef struct METAL_ShaderPipelines
|
||||
@property (nonatomic, retain) id<MTLTexture> mtltexture_uv;
|
||||
@property (nonatomic, retain) id<MTLSamplerState> mtlsampler;
|
||||
@property (nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction;
|
||||
#if SDL_HAVE_YUV
|
||||
@property (nonatomic, assign) BOOL yuv;
|
||||
@property (nonatomic, assign) BOOL nv12;
|
||||
@property (nonatomic, assign) size_t conversionBufferOffset;
|
||||
#endif
|
||||
@property (nonatomic, assign) BOOL hasdata;
|
||||
|
||||
@property (nonatomic, retain) id<MTLBuffer> lockedbuffer;
|
||||
@property (nonatomic, assign) SDL_Rect lockedrect;
|
||||
@end
|
||||
@@ -612,7 +613,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
}
|
||||
|
||||
id<MTLTexture> mtltexture_uv = nil;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
BOOL yuv = (texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12);
|
||||
BOOL nv12 = (texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21);
|
||||
|
||||
@@ -637,7 +638,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
return SDL_SetError("Texture allocation failed");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
METAL_TextureData *texturedata = [[METAL_TextureData alloc] init];
|
||||
if (texture->scaleMode == SDL_ScaleModeNearest) {
|
||||
texturedata.mtlsampler = data.mtlsamplernearest;
|
||||
@@ -646,7 +647,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
}
|
||||
texturedata.mtltexture = mtltexture;
|
||||
texturedata.mtltexture_uv = mtltexture_uv;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
texturedata.yuv = yuv;
|
||||
texturedata.nv12 = nv12;
|
||||
|
||||
@@ -657,9 +658,12 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
} else if (texture->format == SDL_PIXELFORMAT_NV21) {
|
||||
texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV21;
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
#endif /* SDL_HAVE_YUV*/
|
||||
texturedata.fragmentFunction = SDL_METAL_FRAGMENT_COPY;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (yuv || nv12) {
|
||||
size_t offset = 0;
|
||||
SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h);
|
||||
@@ -671,7 +675,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
}
|
||||
texturedata.conversionBufferOffset = offset;
|
||||
}
|
||||
|
||||
#endif
|
||||
texture->driverdata = (void*)CFBridgingRetain(texturedata);
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
@@ -785,7 +789,7 @@ METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv) {
|
||||
int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0;
|
||||
int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1;
|
||||
@@ -815,7 +819,7 @@ METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
texturedata.hasdata = YES;
|
||||
|
||||
return 0;
|
||||
@@ -896,10 +900,13 @@ METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
}
|
||||
|
||||
*pitch = SDL_BYTESPERPIXEL(texture->format) * rect->w;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv || texturedata.nv12) {
|
||||
buffersize = ((*pitch) * rect->h) + (2 * (*pitch + 1) / 2) * ((rect->h + 1) / 2);
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
#endif
|
||||
buffersize = (*pitch) * rect->h;
|
||||
}
|
||||
|
||||
@@ -953,7 +960,7 @@ METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
destinationSlice:0
|
||||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(rect.x, rect.y, 0)];
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv) {
|
||||
int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0;
|
||||
int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1;
|
||||
@@ -993,7 +1000,7 @@ METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(UVrect.x, UVrect.y, 0)];
|
||||
}
|
||||
|
||||
#endif
|
||||
[blitcmd endEncoding];
|
||||
|
||||
[data.mtlcmdbuffer commit];
|
||||
@@ -1313,10 +1320,12 @@ SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t
|
||||
}
|
||||
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture atIndex:0];
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv || texturedata.nv12) {
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture_uv atIndex:1];
|
||||
[data.mtlcmdencoder setFragmentBuffer:data.mtlbufconstants offset:texturedata.conversionBufferOffset atIndex:1];
|
||||
}
|
||||
#endif
|
||||
statecache->texture = texture;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
|
||||
Reference in New Issue
Block a user