From 7b1000013e385400e1a93d3017d86237c4bd8049 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 30 Nov 2022 15:51:17 -0800
Subject: [PATCH] Reverted code formatting for Apple platforms
We didn't get the merge right, and rather than tease out exactly what happened, I'm just reverting for now.
---
src/render/metal/SDL_render_metal.m | 1785 ++++++++++-----------
src/video/cocoa/SDL_cocoaclipboard.h | 2 +-
src/video/cocoa/SDL_cocoaclipboard.m | 101 +-
src/video/cocoa/SDL_cocoaevents.h | 2 +-
src/video/cocoa/SDL_cocoaevents.m | 267 +--
src/video/cocoa/SDL_cocoakeyboard.h | 4 +-
src/video/cocoa/SDL_cocoakeyboard.m | 189 +--
src/video/cocoa/SDL_cocoamessagebox.m | 59 +-
src/video/cocoa/SDL_cocoametalview.h | 12 +-
src/video/cocoa/SDL_cocoametalview.m | 115 +-
src/video/cocoa/SDL_cocoamodes.h | 10 +-
src/video/cocoa/SDL_cocoamodes.m | 387 ++---
src/video/cocoa/SDL_cocoamouse.h | 7 +-
src/video/cocoa/SDL_cocoamouse.m | 322 ++--
src/video/cocoa/SDL_cocoaopengl.h | 25 +-
src/video/cocoa/SDL_cocoaopengl.m | 472 +++---
src/video/cocoa/SDL_cocoaopengles.m | 51 +-
src/video/cocoa/SDL_cocoashape.h | 10 +-
src/video/cocoa/SDL_cocoashape.m | 153 +-
src/video/cocoa/SDL_cocoavideo.h | 18 +-
src/video/cocoa/SDL_cocoavideo.m | 240 ++-
src/video/cocoa/SDL_cocoavulkan.h | 12 +-
src/video/cocoa/SDL_cocoavulkan.m | 31 +-
src/video/cocoa/SDL_cocoawindow.h | 133 +-
src/video/cocoa/SDL_cocoawindow.m | 1355 ++++++++--------
src/video/uikit/SDL_uikitappdelegate.h | 4 +-
src/video/uikit/SDL_uikitappdelegate.m | 48 +-
src/video/uikit/SDL_uikitclipboard.m | 23 +-
src/video/uikit/SDL_uikitevents.m | 85 +-
src/video/uikit/SDL_uikitmessagebox.m | 54 +-
src/video/uikit/SDL_uikitmetalview.h | 11 +-
src/video/uikit/SDL_uikitmetalview.m | 88 +-
src/video/uikit/SDL_uikitmodes.h | 16 +-
src/video/uikit/SDL_uikitmodes.m | 290 ++--
src/video/uikit/SDL_uikitopengles.h | 10 +-
src/video/uikit/SDL_uikitopengles.m | 39 +-
src/video/uikit/SDL_uikitopenglview.h | 12 +-
src/video/uikit/SDL_uikitopenglview.m | 13 +-
src/video/uikit/SDL_uikitvideo.h | 2 +-
src/video/uikit/SDL_uikitvideo.m | 43 +-
src/video/uikit/SDL_uikitview.h | 2 +-
src/video/uikit/SDL_uikitview.m | 69 +-
src/video/uikit/SDL_uikitviewcontroller.h | 16 +-
src/video/uikit/SDL_uikitviewcontroller.m | 88 +-
src/video/uikit/SDL_uikitvulkan.h | 12 +-
src/video/uikit/SDL_uikitvulkan.m | 54 +-
src/video/uikit/SDL_uikitwindow.h | 8 +-
src/video/uikit/SDL_uikitwindow.m | 102 +-
48 files changed, 3449 insertions(+), 3402 deletions(-)
diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index 51899f582a1b..80fd96f07542 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -120,46 +120,47 @@
} METAL_ShaderPipelines;
@interface METAL_RenderData : NSObject
-@property(nonatomic, retain) id<MTLDevice> mtldevice;
-@property(nonatomic, retain) id<MTLCommandQueue> mtlcmdqueue;
-@property(nonatomic, retain) id<MTLCommandBuffer> mtlcmdbuffer;
-@property(nonatomic, retain) id<MTLRenderCommandEncoder> mtlcmdencoder;
-@property(nonatomic, retain) id<MTLLibrary> mtllibrary;
-@property(nonatomic, retain) id<CAMetalDrawable> mtlbackbuffer;
-@property(nonatomic, retain) id<MTLSamplerState> mtlsamplernearest;
-@property(nonatomic, retain) id<MTLSamplerState> mtlsamplerlinear;
-@property(nonatomic, retain) id<MTLBuffer> mtlbufconstants;
-@property(nonatomic, retain) id<MTLBuffer> mtlbufquadindices;
-@property(nonatomic, assign) SDL_MetalView mtlview;
-@property(nonatomic, retain) CAMetalLayer *mtllayer;
-@property(nonatomic, retain) MTLRenderPassDescriptor *mtlpassdesc;
-@property(nonatomic, assign) METAL_ShaderPipelines *activepipelines;
-@property(nonatomic, assign) METAL_ShaderPipelines *allpipelines;
-@property(nonatomic, assign) int pipelinescount;
+ @property (nonatomic, retain) id<MTLDevice> mtldevice;
+ @property (nonatomic, retain) id<MTLCommandQueue> mtlcmdqueue;
+ @property (nonatomic, retain) id<MTLCommandBuffer> mtlcmdbuffer;
+ @property (nonatomic, retain) id<MTLRenderCommandEncoder> mtlcmdencoder;
+ @property (nonatomic, retain) id<MTLLibrary> mtllibrary;
+ @property (nonatomic, retain) id<CAMetalDrawable> mtlbackbuffer;
+ @property (nonatomic, retain) id<MTLSamplerState> mtlsamplernearest;
+ @property (nonatomic, retain) id<MTLSamplerState> mtlsamplerlinear;
+ @property (nonatomic, retain) id<MTLBuffer> mtlbufconstants;
+ @property (nonatomic, retain) id<MTLBuffer> mtlbufquadindices;
+ @property (nonatomic, assign) SDL_MetalView mtlview;
+ @property (nonatomic, retain) CAMetalLayer *mtllayer;
+ @property (nonatomic, retain) MTLRenderPassDescriptor *mtlpassdesc;
+ @property (nonatomic, assign) METAL_ShaderPipelines *activepipelines;
+ @property (nonatomic, assign) METAL_ShaderPipelines *allpipelines;
+ @property (nonatomic, assign) int pipelinescount;
@end
@implementation METAL_RenderData
@end
@interface METAL_TextureData : NSObject
-@property(nonatomic, retain) id<MTLTexture> mtltexture;
-@property(nonatomic, retain) id<MTLTexture> mtltexture_uv;
-@property(nonatomic, retain) id<MTLSamplerState> mtlsampler;
-@property(nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction;
+ @property (nonatomic, retain) id<MTLTexture> mtltexture;
+ @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;
+ @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;
+ @property (nonatomic, assign) BOOL hasdata;
+ @property (nonatomic, retain) id<MTLBuffer> lockedbuffer;
+ @property (nonatomic, assign) SDL_Rect lockedrect;
@end
@implementation METAL_TextureData
@end
-static int IsMetalAvailable(const SDL_SysWMinfo *syswm)
+static int
+IsMetalAvailable(const SDL_SysWMinfo *syswm)
{
if (syswm->subsystem != SDL_SYSWM_COCOA && syswm->subsystem != SDL_SYSWM_UIKIT) {
return SDL_SetError("Metal render target only supports Cocoa and UIKit video targets at the moment.");
@@ -178,84 +179,63 @@ static int IsMetalAvailable(const SDL_SysWMinfo *syswm)
static const MTLBlendOperation invalidBlendOperation = (MTLBlendOperation)0xFFFFFFFF;
static const MTLBlendFactor invalidBlendFactor = (MTLBlendFactor)0xFFFFFFFF;
-static MTLBlendOperation GetBlendOperation(SDL_BlendOperation operation)
+static MTLBlendOperation
+GetBlendOperation(SDL_BlendOperation operation)
{
switch (operation) {
- case SDL_BLENDOPERATION_ADD:
- return MTLBlendOperationAdd;
- case SDL_BLENDOPERATION_SUBTRACT:
- return MTLBlendOperationSubtract;
- case SDL_BLENDOPERATION_REV_SUBTRACT:
- return MTLBlendOperationReverseSubtract;
- case SDL_BLENDOPERATION_MINIMUM:
- return MTLBlendOperationMin;
- case SDL_BLENDOPERATION_MAXIMUM:
- return MTLBlendOperationMax;
- default:
- return invalidBlendOperation;
+ case SDL_BLENDOPERATION_ADD: return MTLBlendOperationAdd;
+ case SDL_BLENDOPERATION_SUBTRACT: return MTLBlendOperationSubtract;
+ case SDL_BLENDOPERATION_REV_SUBTRACT: return MTLBlendOperationReverseSubtract;
+ case SDL_BLENDOPERATION_MINIMUM: return MTLBlendOperationMin;
+ case SDL_BLENDOPERATION_MAXIMUM: return MTLBlendOperationMax;
+ default: return invalidBlendOperation;
}
}
-static MTLBlendFactor GetBlendFactor(SDL_BlendFactor factor)
+static MTLBlendFactor
+GetBlendFactor(SDL_BlendFactor factor)
{
switch (factor) {
- case SDL_BLENDFACTOR_ZERO:
- return MTLBlendFactorZero;
- case SDL_BLENDFACTOR_ONE:
- return MTLBlendFactorOne;
- case SDL_BLENDFACTOR_SRC_COLOR:
- return MTLBlendFactorSourceColor;
- case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
- return MTLBlendFactorOneMinusSourceColor;
- case SDL_BLENDFACTOR_SRC_ALPHA:
- return MTLBlendFactorSourceAlpha;
- case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
- return MTLBlendFactorOneMinusSourceAlpha;
- case SDL_BLENDFACTOR_DST_COLOR:
- return MTLBlendFactorDestinationColor;
- case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
- return MTLBlendFactorOneMinusDestinationColor;
- case SDL_BLENDFACTOR_DST_ALPHA:
- return MTLBlendFactorDestinationAlpha;
- case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
- return MTLBlendFactorOneMinusDestinationAlpha;
- default:
- return invalidBlendFactor;
+ case SDL_BLENDFACTOR_ZERO: return MTLBlendFactorZero;
+ case SDL_BLENDFACTOR_ONE: return MTLBlendFactorOne;
+ case SDL_BLENDFACTOR_SRC_COLOR: return MTLBlendFactorSourceColor;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return MTLBlendFactorOneMinusSourceColor;
+ case SDL_BLENDFACTOR_SRC_ALPHA: return MTLBlendFactorSourceAlpha;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return MTLBlendFactorOneMinusSourceAlpha;
+ case SDL_BLENDFACTOR_DST_COLOR: return MTLBlendFactorDestinationColor;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR: return MTLBlendFactorOneMinusDestinationColor;
+ case SDL_BLENDFACTOR_DST_ALPHA: return MTLBlendFactorDestinationAlpha;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return MTLBlendFactorOneMinusDestinationAlpha;
+ default: return invalidBlendFactor;
}
}
-static NSString *GetVertexFunctionName(SDL_MetalVertexFunction function)
+static NSString *
+GetVertexFunctionName(SDL_MetalVertexFunction function)
{
switch (function) {
- case SDL_METAL_VERTEX_SOLID:
- return @"SDL_Solid_vertex";
- case SDL_METAL_VERTEX_COPY:
- return @"SDL_Copy_vertex";
- default:
- return nil;
+ case SDL_METAL_VERTEX_SOLID: return @"SDL_Solid_vertex";
+ case SDL_METAL_VERTEX_COPY: return @"SDL_Copy_vertex";
+ default: return nil;
}
}
-static NSString *GetFragmentFunctionName(SDL_MetalFragmentFunction function)
+static NSString *
+GetFragmentFunctionName(SDL_MetalFragmentFunction function)
{
switch (function) {
- case SDL_METAL_FRAGMENT_SOLID:
- return @"SDL_Solid_fragment";
- case SDL_METAL_FRAGMENT_COPY:
- return @"SDL_Copy_fragment";
- case SDL_METAL_FRAGMENT_YUV:
- return @"SDL_YUV_fragment";
- case SDL_METAL_FRAGMENT_NV12:
- return @"SDL_NV12_fragment";
- case SDL_METAL_FRAGMENT_NV21:
- return @"SDL_NV21_fragment";
- default:
- return nil;
+ case SDL_METAL_FRAGMENT_SOLID: return @"SDL_Solid_fragment";
+ case SDL_METAL_FRAGMENT_COPY: return @"SDL_Copy_fragment";
+ case SDL_METAL_FRAGMENT_YUV: return @"SDL_YUV_fragment";
+ case SDL_METAL_FRAGMENT_NV12: return @"SDL_NV12_fragment";
+ case SDL_METAL_FRAGMENT_NV21: return @"SDL_NV21_fragment";
+ default: return nil;
}
}
-static id<MTLRenderPipelineState> MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
- NSString *blendlabel, SDL_BlendMode blendmode)
+static id<MTLRenderPipelineState>
+MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
+ NSString *blendlabel, SDL_BlendMode blendmode)
{
MTLRenderPipelineDescriptor *mtlpipedesc;
MTLVertexDescriptor *vertdesc;
@@ -277,37 +257,37 @@ static MTLBlendFactor GetBlendFactor(SDL_BlendFactor factor)
vertdesc = [MTLVertexDescriptor vertexDescriptor];
switch (cache->vertexFunction) {
- case SDL_METAL_VERTEX_SOLID:
- /* position (float2), color (uchar4normalized) */
- vertdesc.layouts[0].stride = sizeof(float) * 2 + sizeof(int);
- vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
+ case SDL_METAL_VERTEX_SOLID:
+ /* position (float2), color (uchar4normalized) */
+ vertdesc.layouts[0].stride = sizeof(float) * 2 + sizeof (int);
+ vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
- vertdesc.attributes[0].format = MTLVertexFormatFloat2;
- vertdesc.attributes[0].offset = 0;
- vertdesc.attributes[0].bufferIndex = 0;
+ vertdesc.attributes[0].format = MTLVertexFormatFloat2;
+ vertdesc.attributes[0].offset = 0;
+ vertdesc.attributes[0].bufferIndex = 0;
- vertdesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
- vertdesc.attributes[1].offset = sizeof(float) * 2;
- vertdesc.attributes[1].bufferIndex = 0;
+ vertdesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
+ vertdesc.attributes[1].offset = sizeof (float) * 2;
+ vertdesc.attributes[1].bufferIndex = 0;
- break;
- case SDL_METAL_VERTEX_COPY:
- /* position (float2), color (uchar4normalized), texcoord (float2) */
- vertdesc.layouts[0].stride = sizeof(float) * 2 + sizeof(int) + sizeof(float) * 2;
- vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
-
- vertdesc.attributes[0].format = MTLVertexFormatFloat2;
- vertdesc.attributes[0].offset = 0;
- vertdesc.attributes[0].bufferIndex = 0;
-
- vertdesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
- vertdesc.attributes[1].offset = sizeof(float) * 2;
- vertdesc.attributes[1].bufferIndex = 0;
-
- vertdesc.attributes[2].format = MTLVertexFormatFloat2;
- vertdesc.attributes[2].offset = sizeof(float) * 2 + sizeof(int);
- vertdesc.attributes[2].bufferIndex = 0;
- break;
+ break;
+ case SDL_METAL_VERTEX_COPY:
+ /* position (float2), color (uchar4normalized), texcoord (float2) */
+ vertdesc.layouts[0].stride = sizeof(float) * 2 + sizeof (int) + sizeof (float) * 2;
+ vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
+
+ vertdesc.attributes[0].format = MTLVertexFormatFloat2;
+ vertdesc.attributes[0].offset = 0;
+ vertdesc.attributes[0].bufferIndex = 0;
+
+ vertdesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
+ vertdesc.attributes[1].offset = sizeof (float) * 2;
+ vertdesc.attributes[1].bufferIndex = 0;
+
+ vertdesc.attributes[2].format = MTLVertexFormatFloat2;
+ vertdesc.attributes[2].offset = sizeof(float) * 2 + sizeof (int);
+ vertdesc.attributes[2].bufferIndex = 0;
+ break;
}
mtlpipedesc.vertexDescriptor = vertdesc;
@@ -348,8 +328,9 @@ static MTLBlendFactor GetBlendFactor(SDL_BlendFactor factor)
}
}
-static void MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char *label,
- MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn)
+static void
+MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char *label,
+ MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn)
{
SDL_zerop(cache);
@@ -367,7 +348,8 @@ static void MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache
MakePipelineState(data, cache, @" (blend=mul)", SDL_BLENDMODE_MUL);
}
-static void DestroyPipelineCache(METAL_PipelineCache *cache)
+static void
+DestroyPipelineCache(METAL_PipelineCache *cache)
{
if (cache != NULL) {
for (int i = 0; i < cache->count; i++) {
@@ -378,7 +360,8 @@ static void DestroyPipelineCache(METAL_PipelineCache *cache)
}
}
-void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat)
+void
+MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat)
{
SDL_zerop(pipelines);
@@ -391,7 +374,8 @@ void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipeline
MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_NV21], "SDL NV21 pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_NV21);
}
-static METAL_ShaderPipelines *ChooseShaderPipelines(METAL_RenderData *data, MTLPixelFormat rtformat)
+static METAL_ShaderPipelines *
+ChooseShaderPipelines(METAL_RenderData *data, MTLPixelFormat rtformat)
{
METAL_ShaderPipelines *allpipelines = data.allpipelines;
int count = data.pipelinescount;
@@ -417,7 +401,8 @@ void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipeline
return &data.allpipelines[count];
}
-static void DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
+static void
+DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
{
if (allpipelines != NULL) {
for (int i = 0; i < count; i++) {
@@ -430,7 +415,8 @@ static void DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
}
}
-static inline id<MTLRenderPipelineState> ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SDL_MetalFragmentFunction fragfn, SDL_BlendMode blendmode)
+static inline id<MTLRenderPipelineState>
+ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SDL_MetalFragmentFunction fragfn, SDL_BlendMode blendmode)
{
METAL_PipelineCache *cache = &pipelines->caches[fragfn];
@@ -443,9 +429,10 @@ static void DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
return MakePipelineState(data, cache, [NSString stringWithFormat:@" (blend=custom 0x%x)", blendmode], blendmode);
}
-static SDL_bool METAL_ActivateRenderCommandEncoder(SDL_Renderer *renderer, MTLLoadAction load, MTLClearColor *clear_color, id<MTLBuffer> vertex_buffer)
+static SDL_bool
+METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load, MTLClearColor *clear_color, id<MTLBuffer> vertex_buffer)
{
- METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata;
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
/* Our SetRenderTarget just signals that the next render operation should
* set up a new render pass. This is where that work happens. */
@@ -510,25 +497,26 @@ static SDL_bool METAL_ActivateRenderCommandEncoder(SDL_Renderer *renderer, MTLLo
return SDL_TRUE;
}
-static void METAL_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
+static void
+METAL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
}
-static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
-{
- @autoreleasepool {
- METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata;
- if (w) {
- *w = (int)data.mtllayer.drawableSize.width;
- }
- if (h) {
- *h = (int)data.mtllayer.drawableSize.height;
- }
- return 0;
+static int
+METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ if (w) {
+ *w = (int)data.mtllayer.drawableSize.width;
}
-}
+ if (h) {
+ *h = (int)data.mtllayer.drawableSize.height;
+ }
+ return 0;
+}}
-static SDL_bool METAL_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
+static SDL_bool
+METAL_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
{
SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
@@ -548,17 +536,17 @@ static SDL_bool METAL_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode bl
return SDL_TRUE;
}
-static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
-{
- @autoreleasepool {
- METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata;
- MTLPixelFormat pixfmt;
- MTLTextureDescriptor *mtltexdesc;
- id<MTLTexture> mtltexture, mtltexture_uv;
- BOOL yuv, nv12;
- METAL_TextureData *texturedata;
-
- switch (texture->format) {
+static int
+METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ MTLPixelFormat pixfmt;
+ MTLTextureDescriptor *mtltexdesc;
+ id<MTLTexture> mtltexture, mtltexture_uv;
+ BOOL yuv, nv12;
+ METAL_TextureData *texturedata;
+
+ switch (texture->format) {
case SDL_PIXELFORMAT_ABGR8888:
pixfmt = MTLPixelFormatRGBA8Unorm;
break;
@@ -573,103 +561,93 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
break;
default:
return SDL_SetError("Texture format %s not supported by Metal", SDL_GetPixelFormatName(texture->format));
- }
+ }
- mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixfmt
- width:(NSUInteger)texture->w
- height:(NSUInteger)texture->h
- mipmapped:NO];
-
- /* Not available in iOS 8. */
- if ([mtltexdesc respondsToSelector:@selector(usage)]) {
- if (texture->access == SDL_TEXTUREACCESS_TARGET) {
- mtltexdesc.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget;
- } else {
- mtltexdesc.usage = MTLTextureUsageShaderRead;
- }
- }
+ mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixfmt
+ width:(NSUInteger)texture->w height:(NSUInteger)texture->h mipmapped:NO];
- mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
- if (mtltexture == nil) {
- return SDL_SetError("Texture allocation failed");
+ /* Not available in iOS 8. */
+ if ([mtltexdesc respondsToSelector:@selector(usage)]) {
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ mtltexdesc.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget;
+ } else {
+ mtltexdesc.usage = MTLTextureUsageShaderRead;
}
+ }
+
+ mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+ if (mtltexture == nil) {
+ return SDL_SetError("Texture allocation failed");
+ }
- mtltexture_uv = nil;
+ mtltexture_uv = nil;
#if SDL_HAVE_YUV
- yuv = (texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12);
- nv12 = (texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21);
-
- if (yuv) {
- mtltexdesc.pixelFormat = MTLPixelFormatR8Unorm;
- mtltexdesc.width = (texture->w + 1) / 2;
- mtltexdesc.height = (texture->h + 1) / 2;
- mtltexdesc.textureType = MTLTextureType2DArray;
- mtltexdesc.arrayLength = 2;
- } else if (nv12) {
- mtltexdesc.pixelFormat = MTLPixelFormatRG8Unorm;
- mtltexdesc.width = (texture->w + 1) / 2;
- mtltexdesc.height = (texture->h + 1) / 2;
- }
+ yuv = (texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12);
+ nv12 = (texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21);
+
+ if (yuv) {
+ mtltexdesc.pixelFormat = MTLPixelFormatR8Unorm;
+ mtltexdesc.width = (texture->w + 1) / 2;
+ mtltexdesc.height = (texture->h + 1) / 2;
+ mtltexdesc.textureType = MTLTextureType2DArray;
+ mtltexdesc.arrayLength = 2;
+ } else if (nv12) {
+ mtltexdesc.pixelFormat = MTLPixelFormatRG8Unorm;
+ mtltexdesc.width = (texture->w + 1) / 2;
+ mtltexdesc.height = (texture->h + 1) / 2;
+ }
- if (yuv || nv12) {
- mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
- if (mtltexture_uv == nil) {
- return SDL_SetError("Texture allocation failed");
- }
+ if (yuv || nv12) {
+ mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+ if (mtltexture_uv == nil) {
+ return SDL_SetError("Texture allocation failed");
}
+ }
#endif /* SDL_HAVE_YUV */
- texturedata = [[METAL_TextureData alloc] init];
- if (texture->scaleMode == SDL_ScaleModeNearest) {
- texturedata.mtlsampler = data.mtlsamplernearest;
- } else {
- texturedata.mtlsampler = data.mtlsamplerlinear;
- }
- texturedata.mtltexture = mtltexture;
- texturedata.mtltexture_uv = mtltexture_uv;
+ texturedata = [[METAL_TextureData alloc] init];
+ if (texture->scaleMode == SDL_ScaleModeNearest) {
+ texturedata.mtlsampler = data.mtlsamplernearest;
+ } else {
+ texturedata.mtlsampler = data.mtlsamplerlinear;
+ }
+ texturedata.mtltexture = mtltexture;
+ texturedata.mtltexture_uv = mtltexture_uv;
#if SDL_HAVE_YUV
- texturedata.yuv = yuv;
- texturedata.nv12 = nv12;
-
- if (yuv) {
- texturedata.fragmentFunction = SDL_METAL_FRAGMENT_YUV;
- } else if (texture->format == SDL_PIXELFORMAT_NV12) {
- texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV12;
- } else if (texture->format == SDL_PIXELFORMAT_NV21) {
- texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV21;
- } else
+ texturedata.yuv = yuv;
+ texturedata.nv12 = nv12;
+
+ if (yuv) {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_YUV;
+ } else if (texture->format == SDL_PIXELFORMAT_NV12) {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV12;
+ } else if (texture->format == SDL_PIXELFORMAT_NV21) {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV21;
+ } else
#endif
- {
- texturedata.fragmentFunction = SDL_METAL_FRAGMENT_COPY;
- }
+ {
+ 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);
- switch (mode) {
- case SDL_YUV_CONVERSION_JPEG:
- offset = CONSTANTS_OFFSET_DECODE_JPEG;
- break;
- case SDL_YUV_CONVERSION_BT601:
- offset = CONSTANTS_OFFSET_DECODE_BT601;
- break;
- case SDL_YUV_CONVERSION_BT709:
- offset = CONSTANTS_OFFSET_DECODE_BT709;
- break;
- default:
- offset = 0;
- break;
- }
- texturedata.conversionBufferOffset = offset;
- }
+ if (yuv || nv12) {
+ size_t offset = 0;
+ SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h);
+ switch (mode) {
+ case SDL_YUV_CONVERSION_JPEG: offset = CONSTANTS_OFFSET_DECODE_JPEG; break;
+ case SDL_YUV_CONVERSION_BT601: offset = CONSTANTS_OFFSET_DECODE_BT601; break;
+ case SDL_YUV_CONVERSION_BT709: offset = CONSTANTS_OFFSET_DECODE_BT709; break;
+ default: offset = 0; break;
+ }
+ texturedata.conversionBufferOffset = offset;
+ }
#endif
- texture->driverdata = (void *)CFBridgingRetain(texturedata);
+ texture->driverdata = (void*)CFBridgingRetain(texturedata);
- return 0;
- }
-}
+ return 0;
+}}
-static void METAL_UploadTextureData(id<MTLTexture> texture, SDL_Rect rect, int slice,
- const void *pixels, int pitch)
+static void
+METAL_UploadTextureData(id<MTLTexture> texture, SDL_Rect rect, int slice,
+ const void * pixels, int pitch)
{
[texture replaceRegion:MTLRegionMake2D(rect.x, rect.y, rect.w, rect.h)
mipmapLevel:0
@@ -679,7 +657,8 @@ static void METAL_UploadTextureData(id<MTLTexture> texture, SDL_Rect rect, int s
bytesPerImage:0];
}
-static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource)
+static MTLStorageMode
+METAL_GetStorageMode(id<MTLResource> resource)
{
/* iOS 8 does not have this method. */
if ([resource respondsToSelector:@selector(storageMode)]) {
@@ -688,12 +667,13 @@ static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource)
return MTLStorageModeShared;
}
-static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, METAL_TextureData *texturedata,
- id<MTLTexture> texture, SDL_Rect rect, int slice,
- const void *pixels, int pitch)
+static int
+METAL_UpdateTextureInternal(SDL_Renderer * renderer, METAL_TextureData *texturedata,
+ id<MTLTexture> texture, SDL_Rect rect, int slice,
+ const void * pixels, int pitch)
{
- METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata;
- SDL_Rect stagingrect = { 0, 0, rect.w, rect.h };
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ SDL_Rect stagingrect = {0, 0, rect.w, rect.h};
MTLTextureDescriptor *desc;
id<MTLTexture> stagingtex;
id<MTLBlitCommandEncoder> blitcmd;
@@ -756,279 +736,274 @@ static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, METAL_TextureData
return 0;
}
-static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
- const SDL_Rect *rect, const void *pixels, int pitch)
-{
- @autoreleasepool {
- METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
+static int
+METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{ @autoreleasepool {
+ METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
- if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch) < 0) {
+ 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;
+ int UVpitch = (pitch + 1) / 2;
+ SDL_Rect UVrect = {rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2};
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ if (METAL
(Patch may be truncated, please check the link at the top of this post.)