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.
This commit is contained in:
Sam Lantinga 2022-11-30 15:51:17 -08:00
parent 9e997cc787
commit 7b1000013e
48 changed files with 3489 additions and 3442 deletions

View file

@ -159,7 +159,8 @@ typedef struct METAL_ShaderPipelines
@implementation METAL_TextureData @implementation METAL_TextureData
@end @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) { 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."); return SDL_SetError("Metal render target only supports Cocoa and UIKit video targets at the moment.");
@ -178,83 +179,62 @@ static int IsMetalAvailable(const SDL_SysWMinfo *syswm)
static const MTLBlendOperation invalidBlendOperation = (MTLBlendOperation)0xFFFFFFFF; static const MTLBlendOperation invalidBlendOperation = (MTLBlendOperation)0xFFFFFFFF;
static const MTLBlendFactor invalidBlendFactor = (MTLBlendFactor)0xFFFFFFFF; static const MTLBlendFactor invalidBlendFactor = (MTLBlendFactor)0xFFFFFFFF;
static MTLBlendOperation GetBlendOperation(SDL_BlendOperation operation) static MTLBlendOperation
GetBlendOperation(SDL_BlendOperation operation)
{ {
switch (operation) { switch (operation) {
case SDL_BLENDOPERATION_ADD: case SDL_BLENDOPERATION_ADD: return MTLBlendOperationAdd;
return MTLBlendOperationAdd; case SDL_BLENDOPERATION_SUBTRACT: return MTLBlendOperationSubtract;
case SDL_BLENDOPERATION_SUBTRACT: case SDL_BLENDOPERATION_REV_SUBTRACT: return MTLBlendOperationReverseSubtract;
return MTLBlendOperationSubtract; case SDL_BLENDOPERATION_MINIMUM: return MTLBlendOperationMin;
case SDL_BLENDOPERATION_REV_SUBTRACT: case SDL_BLENDOPERATION_MAXIMUM: return MTLBlendOperationMax;
return MTLBlendOperationReverseSubtract; default: return invalidBlendOperation;
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) { switch (factor) {
case SDL_BLENDFACTOR_ZERO: case SDL_BLENDFACTOR_ZERO: return MTLBlendFactorZero;
return MTLBlendFactorZero; case SDL_BLENDFACTOR_ONE: return MTLBlendFactorOne;
case SDL_BLENDFACTOR_ONE: case SDL_BLENDFACTOR_SRC_COLOR: return MTLBlendFactorSourceColor;
return MTLBlendFactorOne; case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return MTLBlendFactorOneMinusSourceColor;
case SDL_BLENDFACTOR_SRC_COLOR: case SDL_BLENDFACTOR_SRC_ALPHA: return MTLBlendFactorSourceAlpha;
return MTLBlendFactorSourceColor; case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return MTLBlendFactorOneMinusSourceAlpha;
case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: case SDL_BLENDFACTOR_DST_COLOR: return MTLBlendFactorDestinationColor;
return MTLBlendFactorOneMinusSourceColor; case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR: return MTLBlendFactorOneMinusDestinationColor;
case SDL_BLENDFACTOR_SRC_ALPHA: case SDL_BLENDFACTOR_DST_ALPHA: return MTLBlendFactorDestinationAlpha;
return MTLBlendFactorSourceAlpha; case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return MTLBlendFactorOneMinusDestinationAlpha;
case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: default: return invalidBlendFactor;
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) { switch (function) {
case SDL_METAL_VERTEX_SOLID: case SDL_METAL_VERTEX_SOLID: return @"SDL_Solid_vertex";
return @"SDL_Solid_vertex"; case SDL_METAL_VERTEX_COPY: return @"SDL_Copy_vertex";
case SDL_METAL_VERTEX_COPY: default: return nil;
return @"SDL_Copy_vertex";
default:
return nil;
} }
} }
static NSString *GetFragmentFunctionName(SDL_MetalFragmentFunction function) static NSString *
GetFragmentFunctionName(SDL_MetalFragmentFunction function)
{ {
switch (function) { switch (function) {
case SDL_METAL_FRAGMENT_SOLID: case SDL_METAL_FRAGMENT_SOLID: return @"SDL_Solid_fragment";
return @"SDL_Solid_fragment"; case SDL_METAL_FRAGMENT_COPY: return @"SDL_Copy_fragment";
case SDL_METAL_FRAGMENT_COPY: case SDL_METAL_FRAGMENT_YUV: return @"SDL_YUV_fragment";
return @"SDL_Copy_fragment"; case SDL_METAL_FRAGMENT_NV12: return @"SDL_NV12_fragment";
case SDL_METAL_FRAGMENT_YUV: case SDL_METAL_FRAGMENT_NV21: return @"SDL_NV21_fragment";
return @"SDL_YUV_fragment"; default: return nil;
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, static id<MTLRenderPipelineState>
MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
NSString *blendlabel, SDL_BlendMode blendmode) NSString *blendlabel, SDL_BlendMode blendmode)
{ {
MTLRenderPipelineDescriptor *mtlpipedesc; MTLRenderPipelineDescriptor *mtlpipedesc;
@ -348,7 +328,8 @@ static id<MTLRenderPipelineState> MakePipelineState(METAL_RenderData *data, META
} }
} }
static void MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char *label, static void
MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char *label,
MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn) MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn)
{ {
SDL_zerop(cache); SDL_zerop(cache);
@ -367,7 +348,8 @@ static void MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache
MakePipelineState(data, cache, @" (blend=mul)", SDL_BLENDMODE_MUL); MakePipelineState(data, cache, @" (blend=mul)", SDL_BLENDMODE_MUL);
} }
static void DestroyPipelineCache(METAL_PipelineCache *cache) static void
DestroyPipelineCache(METAL_PipelineCache *cache)
{ {
if (cache != NULL) { if (cache != NULL) {
for (int i = 0; i < cache->count; i++) { 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); 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); 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; METAL_ShaderPipelines *allpipelines = data.allpipelines;
int count = data.pipelinescount; int count = data.pipelinescount;
@ -417,7 +401,8 @@ static METAL_ShaderPipelines *ChooseShaderPipelines(METAL_RenderData *data, MTLP
return &data.allpipelines[count]; return &data.allpipelines[count];
} }
static void DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count) static void
DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
{ {
if (allpipelines != NULL) { if (allpipelines != NULL) {
for (int i = 0; i < count; i++) { 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]; METAL_PipelineCache *cache = &pipelines->caches[fragfn];
@ -443,7 +429,8 @@ static inline id<MTLRenderPipelineState> ChoosePipelineState(METAL_RenderData *d
return MakePipelineState(data, cache, [NSString stringWithFormat:@" (blend=custom 0x%x)", blendmode], blendmode); 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;
@ -510,13 +497,14 @@ static SDL_bool METAL_ActivateRenderCommandEncoder(SDL_Renderer *renderer, MTLLo
return SDL_TRUE; 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) static int
{ METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
if (w) { if (w) {
*w = (int)data.mtllayer.drawableSize.width; *w = (int)data.mtllayer.drawableSize.width;
@ -525,10 +513,10 @@ static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
*h = (int)data.mtllayer.drawableSize.height; *h = (int)data.mtllayer.drawableSize.height;
} }
return 0; 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 srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode); SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
@ -548,9 +536,9 @@ static SDL_bool METAL_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode bl
return SDL_TRUE; return SDL_TRUE;
} }
static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) static int
{ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
MTLPixelFormat pixfmt; MTLPixelFormat pixfmt;
MTLTextureDescriptor *mtltexdesc; MTLTextureDescriptor *mtltexdesc;
@ -576,9 +564,7 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
} }
mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixfmt mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixfmt
width:(NSUInteger)texture->w width:(NSUInteger)texture->w height:(NSUInteger)texture->h mipmapped:NO];
height:(NSUInteger)texture->h
mipmapped:NO];
/* Not available in iOS 8. */ /* Not available in iOS 8. */
if ([mtltexdesc respondsToSelector:@selector(usage)]) { if ([mtltexdesc respondsToSelector:@selector(usage)]) {
@ -646,18 +632,10 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
size_t offset = 0; size_t offset = 0;
SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h); SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h);
switch (mode) { switch (mode) {
case SDL_YUV_CONVERSION_JPEG: case SDL_YUV_CONVERSION_JPEG: offset = CONSTANTS_OFFSET_DECODE_JPEG; break;
offset = CONSTANTS_OFFSET_DECODE_JPEG; case SDL_YUV_CONVERSION_BT601: offset = CONSTANTS_OFFSET_DECODE_BT601; break;
break; case SDL_YUV_CONVERSION_BT709: offset = CONSTANTS_OFFSET_DECODE_BT709; break;
case SDL_YUV_CONVERSION_BT601: default: offset = 0; break;
offset = CONSTANTS_OFFSET_DECODE_BT601;
break;
case SDL_YUV_CONVERSION_BT709:
offset = CONSTANTS_OFFSET_DECODE_BT709;
break;
default:
offset = 0;
break;
} }
texturedata.conversionBufferOffset = offset; texturedata.conversionBufferOffset = offset;
} }
@ -665,10 +643,10 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
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, static void
METAL_UploadTextureData(id<MTLTexture> texture, SDL_Rect rect, int slice,
const void * pixels, int pitch) const void * pixels, int pitch)
{ {
[texture replaceRegion:MTLRegionMake2D(rect.x, rect.y, rect.w, rect.h) [texture replaceRegion:MTLRegionMake2D(rect.x, rect.y, rect.w, rect.h)
@ -679,7 +657,8 @@ static void METAL_UploadTextureData(id<MTLTexture> texture, SDL_Rect rect, int s
bytesPerImage:0]; bytesPerImage:0];
} }
static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource) static MTLStorageMode
METAL_GetStorageMode(id<MTLResource> resource)
{ {
/* iOS 8 does not have this method. */ /* iOS 8 does not have this method. */
if ([resource respondsToSelector:@selector(storageMode)]) { if ([resource respondsToSelector:@selector(storageMode)]) {
@ -688,7 +667,8 @@ static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource)
return MTLStorageModeShared; return MTLStorageModeShared;
} }
static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, METAL_TextureData *texturedata, static int
METAL_UpdateTextureInternal(SDL_Renderer * renderer, METAL_TextureData *texturedata,
id<MTLTexture> texture, SDL_Rect rect, int slice, id<MTLTexture> texture, SDL_Rect rect, int slice,
const void * pixels, int pitch) const void * pixels, int pitch)
{ {
@ -756,10 +736,10 @@ static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, METAL_TextureData
return 0; return 0;
} }
static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, static int
METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch) const SDL_Rect * rect, const void *pixels, int pitch)
{ { @autoreleasepool {
@autoreleasepool {
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; 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) {
@ -799,17 +779,16 @@ static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
texturedata.hasdata = YES; texturedata.hasdata = YES;
return 0; return 0;
} }}
}
#if SDL_HAVE_YUV #if SDL_HAVE_YUV
static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, static int
METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch, const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch, const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch) const Uint8 *Vplane, int Vpitch)
{ { @autoreleasepool {
@autoreleasepool {
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
const int Uslice = 0; const int Uslice = 0;
const int Vslice = 1; const int Vslice = 1;
@ -833,15 +812,14 @@ static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
texturedata.hasdata = YES; texturedata.hasdata = YES;
return 0; return 0;
} }}
}
static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, static int
METAL_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch, const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch) const Uint8 *UVplane, int UVpitch)
{ { @autoreleasepool {
@autoreleasepool {
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
SDL_Rect UVrect = {rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2}; SDL_Rect UVrect = {rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2};
@ -861,14 +839,13 @@ static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
texturedata.hasdata = YES; texturedata.hasdata = YES;
return 0; return 0;
} }}
}
#endif #endif
static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, static int
METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch) const SDL_Rect * rect, void **pixels, int *pitch)
{ { @autoreleasepool {
@autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
int buffersize = 0; int buffersize = 0;
@ -898,12 +875,11 @@ static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
*pixels = [lockedbuffer contents]; *pixels = [lockedbuffer contents];
return 0; return 0;
} }}
}
static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) static void
{ METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
id<MTLBlitCommandEncoder> blitcmd; id<MTLBlitCommandEncoder> blitcmd;
@ -983,12 +959,11 @@ static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
texturedata.lockedbuffer = nil; /* Retained property, so it calls release. */ texturedata.lockedbuffer = nil; /* Retained property, so it calls release. */
texturedata.hasdata = YES; texturedata.hasdata = YES;
} }}
}
static void METAL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode) static void
{ METAL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
@ -997,12 +972,11 @@ static void METAL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu
} else { } else {
texturedata.mtlsampler = data.mtlsamplerlinear; texturedata.mtlsampler = data.mtlsamplerlinear;
} }
} }}
}
static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) static int
{ METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
if (data.mtlcmdencoder) { if (data.mtlcmdencoder) {
@ -1019,10 +993,11 @@ static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
* draw or clear happens. That way we can use hardware clears when possible, * draw or clear happens. That way we can use hardware clears when possible,
* which are only available when beginning a new render pass. */ * which are only available when beginning a new render pass. */
return 0; return 0;
} }}
}
static int METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
static int
METAL_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
{ {
float projection[4][4]; /* Prepare an orthographic projection */ float projection[4][4]; /* Prepare an orthographic projection */
const int w = cmd->data.viewport.rect.w; const int w = cmd->data.viewport.rect.w;
@ -1046,7 +1021,8 @@ static int METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd
return 0; return 0;
} }
static int METAL_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd) static int
METAL_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{ {
const size_t vertlen = sizeof (float) * 4; const size_t vertlen = sizeof (float) * 4;
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(16), &cmd->data.color.first); float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(16), &cmd->data.color.first);
@ -1064,7 +1040,8 @@ static int METAL_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cm
return 0; return 0;
} }
static int METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) static int
METAL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{ {
const SDL_Color color = { const SDL_Color color = {
cmd->data.draw.r, cmd->data.draw.r,
@ -1088,7 +1065,8 @@ static int METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
return 0; return 0;
} }
static int METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) static int
METAL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{ {
const SDL_Color color = { const SDL_Color color = {
cmd->data.draw.r, cmd->data.draw.r,
@ -1141,7 +1119,8 @@ static int METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
return 0; return 0;
} }
static int METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, static int
METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride, const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices, int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y) float scale_x, float scale_y)
@ -1202,7 +1181,8 @@ typedef struct
size_t color_offset; size_t color_offset;
} METAL_DrawStateCache; } METAL_DrawStateCache;
static SDL_bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_MetalFragmentFunction shader, static SDL_bool
SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_MetalFragmentFunction shader,
const size_t constants_offset, id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache) const size_t constants_offset, id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache)
{ {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
@ -1282,7 +1262,8 @@ static SDL_bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cm
return SDL_TRUE; return SDL_TRUE;
} }
static SDL_bool SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t constants_offset, static SDL_bool
SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t constants_offset,
id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache) id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache)
{ {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
@ -1314,9 +1295,9 @@ static SDL_bool SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cm
return SDL_TRUE; return SDL_TRUE;
} }
static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) static int
{ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
id<MTLBuffer> mtlbufvertex = nil; id<MTLBuffer> mtlbufvertex = nil;
METAL_DrawStateCache statecache; METAL_DrawStateCache statecache;
@ -1356,8 +1337,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
while (cmd) { while (cmd) {
switch (cmd->command) { switch (cmd->command) {
case SDL_RENDERCMD_SETVIEWPORT: case SDL_RENDERCMD_SETVIEWPORT: {
{
SDL_memcpy(&statecache.viewport, &cmd->data.viewport.rect, sizeof (statecache.viewport)); SDL_memcpy(&statecache.viewport, &cmd->data.viewport.rect, sizeof (statecache.viewport));
statecache.projection_offset = cmd->data.viewport.first; statecache.projection_offset = cmd->data.viewport.first;
statecache.viewport_dirty = SDL_TRUE; statecache.viewport_dirty = SDL_TRUE;
@ -1365,23 +1345,20 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
break; break;
} }
case SDL_RENDERCMD_SETCLIPRECT: case SDL_RENDERCMD_SETCLIPRECT: {
{
SDL_memcpy(&statecache.cliprect, &cmd->data.cliprect.rect, sizeof (statecache.cliprect)); SDL_memcpy(&statecache.cliprect, &cmd->data.cliprect.rect, sizeof (statecache.cliprect));
statecache.cliprect_enabled = cmd->data.cliprect.enabled; statecache.cliprect_enabled = cmd->data.cliprect.enabled;
statecache.cliprect_dirty = SDL_TRUE; statecache.cliprect_dirty = SDL_TRUE;
break; break;
} }
case SDL_RENDERCMD_SETDRAWCOLOR: case SDL_RENDERCMD_SETDRAWCOLOR: {
{
statecache.color_offset = cmd->data.color.first; statecache.color_offset = cmd->data.color.first;
statecache.color_dirty = SDL_TRUE; statecache.color_dirty = SDL_TRUE;
break; break;
} }
case SDL_RENDERCMD_CLEAR: case SDL_RENDERCMD_CLEAR: {
{
/* If we're already encoding a command buffer, dump it without committing it. We'd just /* If we're already encoding a command buffer, dump it without committing it. We'd just
clear all its work anyhow, and starting a new encoder will let us use a hardware clear clear all its work anyhow, and starting a new encoder will let us use a hardware clear
operation via MTLLoadActionClear. */ operation via MTLLoadActionClear. */
@ -1417,8 +1394,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
} }
case SDL_RENDERCMD_DRAW_POINTS: case SDL_RENDERCMD_DRAW_POINTS:
case SDL_RENDERCMD_DRAW_LINES: case SDL_RENDERCMD_DRAW_LINES: {
{
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const MTLPrimitiveType primtype = (cmd->command == SDL_RENDERCMD_DRAW_POINTS) ? MTLPrimitiveTypePoint : MTLPrimitiveTypeLineStrip; const MTLPrimitiveType primtype = (cmd->command == SDL_RENDERCMD_DRAW_POINTS) ? MTLPrimitiveTypePoint : MTLPrimitiveTypeLineStrip;
if (SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, mtlbufvertex, &statecache)) { if (SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, mtlbufvertex, &statecache)) {
@ -1436,8 +1412,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
case SDL_RENDERCMD_COPY_EX: /* unused */ case SDL_RENDERCMD_COPY_EX: /* unused */
break; break;
case SDL_RENDERCMD_GEOMETRY: case SDL_RENDERCMD_GEOMETRY: {
{
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
SDL_Texture *texture = cmd->data.draw.texture; SDL_Texture *texture = cmd->data.draw.texture;
@ -1460,13 +1435,12 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
} }
return 0; return 0;
} }}
}
static int METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, static int
METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch) Uint32 pixel_format, void * pixels, int pitch)
{ { @autoreleasepool {
@autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
id<MTLTexture> mtltexture; id<MTLTexture> mtltexture;
MTLRegion mtlregion; MTLRegion mtlregion;
@ -1514,12 +1488,11 @@ static int METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch); status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch);
SDL_free(temp_pixels); SDL_free(temp_pixels);
return status; return status;
} }}
}
static int METAL_RenderPresent(SDL_Renderer *renderer) static int
{ METAL_RenderPresent(SDL_Renderer * renderer)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
SDL_bool ready = SDL_TRUE; SDL_bool ready = SDL_TRUE;
@ -1553,20 +1526,18 @@ static int METAL_RenderPresent(SDL_Renderer *renderer)
return -1; return -1;
} }
return 0; return 0;
} }}
}
static void METAL_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) static void
{ METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
@autoreleasepool { { @autoreleasepool {
CFBridgingRelease(texture->driverdata); CFBridgingRelease(texture->driverdata);
texture->driverdata = NULL; texture->driverdata = NULL;
} }}
}
static void METAL_DestroyRenderer(SDL_Renderer *renderer) static void
{ METAL_DestroyRenderer(SDL_Renderer * renderer)
@autoreleasepool { { @autoreleasepool {
if (renderer->driverdata) { if (renderer->driverdata) {
METAL_RenderData *data = CFBridgingRelease(renderer->driverdata); METAL_RenderData *data = CFBridgingRelease(renderer->driverdata);
@ -1584,20 +1555,18 @@ static void METAL_DestroyRenderer(SDL_Renderer *renderer)
} }
SDL_free(renderer); SDL_free(renderer);
} }}
}
static void *METAL_GetMetalLayer(SDL_Renderer *renderer) static void *
{ METAL_GetMetalLayer(SDL_Renderer * renderer)
@autoreleasepool { { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
return (__bridge void*)data.mtllayer; return (__bridge void*)data.mtllayer;
} }}
}
static void *METAL_GetMetalCommandEncoder(SDL_Renderer *renderer) static void *
{ METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
@autoreleasepool { { @autoreleasepool {
// note that data.mtlcmdencoder can be nil if METAL_ActivateRenderCommandEncoder fails. // note that data.mtlcmdencoder can be nil if METAL_ActivateRenderCommandEncoder fails.
// Before SDL 2.0.18, it might have returned a non-nil encoding that might not have been // Before SDL 2.0.18, it might have returned a non-nil encoding that might not have been
// usable for presentation. Check your return values! // usable for presentation. Check your return values!
@ -1605,10 +1574,10 @@ static void *METAL_GetMetalCommandEncoder(SDL_Renderer *renderer)
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil); METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
data = (__bridge METAL_RenderData *) renderer->driverdata; data = (__bridge METAL_RenderData *) renderer->driverdata;
return (__bridge void*)data.mtlcmdencoder; return (__bridge void*)data.mtlcmdencoder;
} }}
}
static int METAL_SetVSync(SDL_Renderer *renderer, const int vsync) static int
METAL_SetVSync(SDL_Renderer * renderer, const int vsync)
{ {
#if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST #if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST
if (@available(macOS 10.13, *)) { if (@available(macOS 10.13, *)) {
@ -1654,9 +1623,9 @@ static SDL_MetalView GetWindowView(SDL_Window *window)
return nil; return nil;
} }
static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags) static SDL_Renderer *
{ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
@autoreleasepool { { @autoreleasepool {
SDL_Renderer *renderer = NULL; SDL_Renderer *renderer = NULL;
METAL_RenderData *data = NULL; METAL_RenderData *data = NULL;
id<MTLDevice> mtldevice = nil; id<MTLDevice> mtldevice = nil;
@ -1679,41 +1648,17 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
/* Note: matrices are column major. */ /* Note: matrices are column major. */
float identitytransform[16] = { float identitytransform[16] = {
1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}; };
float halfpixeltransform[16] = { float halfpixeltransform[16] = {
1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.5f, 0.5f, 0.0f, 1.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
0.0f,
0.5f,
0.5f,
0.0f,
1.0f,
}; };
/* Metal pads float3s to 16 bytes. */ /* Metal pads float3s to 16 bytes. */
@ -1810,8 +1755,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
// The compiled .metallib is embedded in a static array in a header file // The compiled .metallib is embedded in a static array in a header file
// but the original shader source code is in SDL_shaders_metal.metal. // but the original shader source code is in SDL_shaders_metal.metal.
mtllibdata = dispatch_data_create(sdl_metallib, sdl_metallib_len, dispatch_get_global_queue(0, 0), ^{ mtllibdata = dispatch_data_create(sdl_metallib, sdl_metallib_len, dispatch_get_global_queue(0, 0), ^{});
});
mtllibrary = [data.mtldevice newLibraryWithData:mtllibdata error:&err]; mtllibrary = [data.mtldevice newLibraryWithData:mtllibdata error:&err];
data.mtllibrary = mtllibrary; data.mtllibrary = mtllibrary;
SDL_assert(err == nil); SDL_assert(err == nil);
@ -1918,6 +1862,11 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
if (data.mtllayer.displaySyncEnabled) { if (data.mtllayer.displaySyncEnabled) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
} }
} else
#endif
{
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
}
/* https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf */ /* https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf */
maxtexsize = 4096; maxtexsize = 4096;
@ -1957,8 +1906,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->info.max_texture_height = maxtexsize; renderer->info.max_texture_height = maxtexsize;
return renderer; return renderer;
} }}
}
SDL_RenderDriver METAL_RenderDriver = { SDL_RenderDriver METAL_RenderDriver = {
METAL_CreateRenderer, METAL_CreateRenderer,
@ -1966,14 +1914,15 @@ SDL_RenderDriver METAL_RenderDriver = {
"metal", "metal",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
6, 6,
{ SDL_PIXELFORMAT_ARGB8888, {
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_IYUV,
SDL_PIXELFORMAT_NV12, SDL_PIXELFORMAT_NV12,
SDL_PIXELFORMAT_NV21 }, SDL_PIXELFORMAT_NV21
0, },
0, 0, 0,
} }
}; };

View file

@ -25,9 +25,10 @@
#include "SDL_cocoavideo.h" #include "SDL_cocoavideo.h"
#include "../../events/SDL_clipboardevents_c.h" #include "../../events/SDL_clipboardevents_c.h"
int Cocoa_SetClipboardText(_THIS, const char *text) int
Cocoa_SetClipboardText(_THIS, const char *text)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
NSPasteboard *pasteboard; NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString; NSString *format = NSPasteboardTypeString;
@ -41,13 +42,12 @@ int Cocoa_SetClipboardText(_THIS, const char *text)
[pasteboard setString:nsstr forType:format]; [pasteboard setString:nsstr forType:format];
return 0; return 0;
} }}
}
char * char *
Cocoa_GetClipboardText(_THIS) Cocoa_GetClipboardText(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
NSPasteboard *pasteboard; NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString; NSString *format = NSPasteboardTypeString;
NSString *available; NSString *available;
@ -71,8 +71,7 @@ Cocoa_GetClipboardText(_THIS)
} }
return text; return text;
} }}
}
SDL_bool SDL_bool
Cocoa_HasClipboardText(_THIS) Cocoa_HasClipboardText(_THIS)
@ -86,9 +85,10 @@ Cocoa_HasClipboardText(_THIS)
return result; return result;
} }
void Cocoa_CheckClipboardUpdate(SDL_VideoData *data) void
Cocoa_CheckClipboardUpdate(SDL_VideoData * data)
{ @autoreleasepool
{ {
@autoreleasepool {
NSPasteboard *pasteboard; NSPasteboard *pasteboard;
NSInteger count; NSInteger count;
@ -100,8 +100,7 @@ void Cocoa_CheckClipboardUpdate(SDL_VideoData *data)
} }
data.clipboard_count = count; data.clipboard_count = count;
} }
} }}
}
#endif /* SDL_VIDEO_DRIVER_COCOA */ #endif /* SDL_VIDEO_DRIVER_COCOA */

View file

@ -130,8 +130,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
- (void)setAppleMenu:(NSMenu *)menu; - (void)setAppleMenu:(NSMenu *)menu;
@end @end
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> @interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
{
@public @public
BOOL seenFirstActivate; BOOL seenFirstActivate;
} }
@ -313,7 +312,8 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
static SDLAppDelegate *appDelegate = nil; static SDLAppDelegate *appDelegate = nil;
static NSString *GetApplicationName(void) static NSString *
GetApplicationName(void)
{ {
NSString *appName; NSString *appName;
@ -330,7 +330,8 @@ static NSString *GetApplicationName(void)
return appName; return appName;
} }
static bool LoadMainMenuNibIfAvailable(void) static bool
LoadMainMenuNibIfAvailable(void)
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
NSDictionary *infoDict; NSDictionary *infoDict;
@ -355,7 +356,8 @@ static bool LoadMainMenuNibIfAvailable(void)
#endif #endif
} }
static void CreateApplicationMenus(void) static void
CreateApplicationMenus(void)
{ {
NSString *appName; NSString *appName;
NSString *title; NSString *title;
@ -444,9 +446,10 @@ static void CreateApplicationMenus(void)
[NSApp setWindowsMenu:windowMenu]; [NSApp setWindowsMenu:windowMenu];
} }
void Cocoa_RegisterApp(void) void
Cocoa_RegisterApp(void)
{ @autoreleasepool
{ {
@autoreleasepool {
/* This can get called more than once! Be careful what you initialize! */ /* This can get called more than once! Be careful what you initialize! */
if (NSApp == nil) { if (NSApp == nil) {
@ -500,10 +503,10 @@ void Cocoa_RegisterApp(void)
appDelegate->seenFirstActivate = YES; appDelegate->seenFirstActivate = YES;
} }
} }
} }}
}
int Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate) int
Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
{ {
for ( ; ; ) { for ( ; ; ) {
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES ]; NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES ];
@ -524,9 +527,10 @@ int Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
return 1; return 1;
} }
int Cocoa_WaitEventTimeout(_THIS, int timeout) int
Cocoa_WaitEventTimeout(_THIS, int timeout)
{ @autoreleasepool
{ {
@autoreleasepool {
if (timeout > 0) { if (timeout > 0) {
NSDate *limitDate = [NSDate dateWithTimeIntervalSinceNow: (double) timeout / 1000.0]; NSDate *limitDate = [NSDate dateWithTimeIntervalSinceNow: (double) timeout / 1000.0];
return Cocoa_PumpEventsUntilDate(_this, limitDate, false); return Cocoa_PumpEventsUntilDate(_this, limitDate, false);
@ -537,19 +541,18 @@ int Cocoa_WaitEventTimeout(_THIS, int timeout)
} }
} }
return 1; return 1;
} }}
}
void Cocoa_PumpEvents(_THIS) void
Cocoa_PumpEvents(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
Cocoa_PumpEventsUntilDate(_this, [NSDate distantPast], true); Cocoa_PumpEventsUntilDate(_this, [NSDate distantPast], true);
} }}
}
void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window) void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
{ @autoreleasepool
{ {
@autoreleasepool {
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
location: NSMakePoint(0,0) location: NSMakePoint(0,0)
modifierFlags: 0 modifierFlags: 0
@ -561,12 +564,12 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
data2: 0]; data2: 0];
[NSApp postEvent: event atStart: YES]; [NSApp postEvent: event atStart: YES];
} }}
}
void Cocoa_SuspendScreenSaver(_THIS) void
Cocoa_SuspendScreenSaver(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata;
if (data.screensaver_assertion) { if (data.screensaver_assertion) {
@ -588,7 +591,7 @@ void Cocoa_SuspendScreenSaver(_THIS)
&assertion); &assertion);
data.screensaver_assertion = assertion; data.screensaver_assertion = assertion;
} }
} }}
#endif /* SDL_VIDEO_DRIVER_COCOA */ #endif /* SDL_VIDEO_DRIVER_COCOA */

View file

@ -33,8 +33,7 @@
/*#define DEBUG_IME NSLog */ /*#define DEBUG_IME NSLog */
#define DEBUG_IME(...) #define DEBUG_IME(...)
@interface SDLTranslatorResponder : NSView <NSTextInputClient> @interface SDLTranslatorResponder : NSView <NSTextInputClient> {
{
NSString *_markedText; NSString *_markedText;
NSRange _markedRange; NSRange _markedRange;
NSRange _selectedRange; NSRange _selectedRange;
@ -183,7 +182,8 @@
@end @end
static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags) static void
HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
{ {
SDL_Scancode code = darwin_scancode_table[scancode]; SDL_Scancode code = darwin_scancode_table[scancode];
@ -199,8 +199,7 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
SDL_SCANCODE_LSHIFT, SDL_SCANCODE_LSHIFT,
SDL_SCANCODE_LCTRL, SDL_SCANCODE_LCTRL,
SDL_SCANCODE_LALT, SDL_SCANCODE_LALT,
SDL_SCANCODE_LGUI, SDL_SCANCODE_LGUI, };
};
const unsigned int modifiers[] = { const unsigned int modifiers[] = {
NX_DEVICELSHIFTKEYMASK, NX_DEVICELSHIFTKEYMASK,
@ -214,11 +213,12 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
NX_SHIFTMASK, NX_SHIFTMASK,
NX_CONTROLMASK, NX_CONTROLMASK,
NX_ALTERNATEMASK, NX_ALTERNATEMASK,
NX_COMMANDMASK NX_COMMANDMASK };
};
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++)
if (code == codes[i]) { {
if (code == codes[i])
{
if (modifierFlags & modifiers[i]) if (modifierFlags & modifiers[i])
SDL_SendKeyboardKey(SDL_PRESSED, code); SDL_SendKeyboardKey(SDL_PRESSED, code);
else else
@ -227,7 +227,8 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
} }
} }
static void UpdateKeymap(SDL_VideoData *data, SDL_bool send_event) static void
UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
{ {
TISInputSourceRef key_layout; TISInputSourceRef key_layout;
const void *chr_data; const void *chr_data;
@ -291,7 +292,8 @@ cleanup:
CFRelease(key_layout); CFRelease(key_layout);
} }
void Cocoa_InitKeyboard(_THIS) void
Cocoa_InitKeyboard(_THIS)
{ {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -309,9 +311,10 @@ void Cocoa_InitKeyboard(_THIS)
SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) != 0); SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) != 0);
} }
void Cocoa_StartTextInput(_THIS) void
Cocoa_StartTextInput(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
NSView *parentView; NSView *parentView;
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus(); SDL_Window *window = SDL_GetKeyboardFocus();
@ -338,22 +341,22 @@ void Cocoa_StartTextInput(_THIS)
[parentView addSubview: data.fieldEdit]; [parentView addSubview: data.fieldEdit];
[nswindow makeFirstResponder: data.fieldEdit]; [nswindow makeFirstResponder: data.fieldEdit];
} }
} }}
}
void Cocoa_StopTextInput(_THIS) void
Cocoa_StopTextInput(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (data && data.fieldEdit) { if (data && data.fieldEdit) {
[data.fieldEdit removeFromSuperview]; [data.fieldEdit removeFromSuperview];
data.fieldEdit = nil; data.fieldEdit = nil;
} }
} }}
}
void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect) void
Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect)
{ {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -365,7 +368,8 @@ void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect)
[data.fieldEdit setInputRect:rect]; [data.fieldEdit setInputRect:rect];
} }
void Cocoa_HandleKeyEvent(_THIS, NSEvent *event) void
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{ {
unsigned short scancode; unsigned short scancode;
SDL_Scancode code; SDL_Scancode code;
@ -427,13 +431,13 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
} }
} }
void Cocoa_QuitKeyboard(_THIS) void
Cocoa_QuitKeyboard(_THIS)
{ {
} }
typedef int CGSConnection; typedef int CGSConnection;
typedef enum typedef enum {
{
CGSGlobalHotKeyEnable = 0, CGSGlobalHotKeyEnable = 0,
CGSGlobalHotKeyDisable = 1, CGSGlobalHotKeyDisable = 1,
} CGSGlobalHotKeyOperatingMode; } CGSGlobalHotKeyOperatingMode;
@ -441,7 +445,8 @@ typedef enum
extern CGSConnection _CGSDefaultConnection(void); extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection, CGSGlobalHotKeyOperatingMode mode); extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection, CGSGlobalHotKeyOperatingMode mode);
void Cocoa_SetWindowKeyboardGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void
Cocoa_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{ {
#if SDL_MAC_NO_SANDBOX #if SDL_MAC_NO_SANDBOX
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), grabbed ? CGSGlobalHotKeyDisable : CGSGlobalHotKeyEnable); CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), grabbed ? CGSGlobalHotKeyDisable : CGSGlobalHotKeyEnable);

View file

@ -27,8 +27,7 @@
#include "SDL_messagebox.h" #include "SDL_messagebox.h"
#include "SDL_cocoavideo.h" #include "SDL_cocoavideo.h"
@interface SDLMessageBoxPresenter : NSObject @interface SDLMessageBoxPresenter : NSObject {
{
@public @public
NSInteger clicked; NSInteger clicked;
NSWindow *nswindow; NSWindow *nswindow;
@ -60,18 +59,14 @@
if (nswindow) { if (nswindow) {
#ifdef MAC_OS_X_VERSION_10_9 #ifdef MAC_OS_X_VERSION_10_9
if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) { if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
[alert beginSheetModalForWindow:nswindow [alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
completionHandler:^(NSModalResponse returnCode) {
self->clicked = returnCode; self->clicked = returnCode;
}]; }];
} else } else
#endif #endif
{ {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
[alert beginSheetModalForWindow:nswindow [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
#endif #endif
} }
@ -93,7 +88,9 @@
@end @end
static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue)
static void
Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue)
{ {
NSAlert* alert; NSAlert* alert;
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
@ -153,21 +150,19 @@ static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, i
} }
/* Display a Cocoa message box */ /* Display a Cocoa message box */
int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) int
Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{ @autoreleasepool
{ {
@autoreleasepool {
__block int returnValue = 0; __block int returnValue = 0;
if ([NSThread isMainThread]) { if ([NSThread isMainThread]) {
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue); Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
} else { } else {
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue); });
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
});
} }
return returnValue; return returnValue;
} }}
}
#endif /* SDL_VIDEO_DRIVER_COCOA */ #endif /* SDL_VIDEO_DRIVER_COCOA */

View file

@ -39,6 +39,7 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
@interface SDL_cocoametalview : NSView @interface SDL_cocoametalview : NSView
- (instancetype)initWithFrame:(NSRect)frame - (instancetype)initWithFrame:(NSRect)frame
@ -66,3 +67,4 @@ void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h);
#endif /* SDL_cocoametalview_h_ */ #endif /* SDL_cocoametalview_h_ */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View file

@ -33,7 +33,9 @@
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_syswm.h" #include "SDL_syswm.h"
static int SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
static int SDLCALL
SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
{ {
/* Update the drawable size when SDL receives a size changed event for /* Update the drawable size when SDL receives a size changed event for
* the window that contains the metal view. It would be nice to use * the window that contains the metal view. It would be nice to use
@ -122,8 +124,7 @@ static int SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
metalLayer.drawableSize = NSSizeToCGSize(backingSize); metalLayer.drawableSize = NSSizeToCGSize(backingSize);
} }
- (NSView *)hitTest:(NSPoint)point - (NSView *)hitTest:(NSPoint)point {
{
return nil; return nil;
} }
@ -131,8 +132,7 @@ static int SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
SDL_MetalView SDL_MetalView
Cocoa_Metal_CreateView(_THIS, SDL_Window * window) Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
{ { @autoreleasepool {
@autoreleasepool {
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data.nswindow.contentView; NSView *view = data.nswindow.contentView;
BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
@ -153,29 +153,25 @@ Cocoa_Metal_CreateView(_THIS, SDL_Window *window)
metalview = (SDL_MetalView)CFBridgingRetain(newview); metalview = (SDL_MetalView)CFBridgingRetain(newview);
return metalview; return metalview;
} }}
}
void Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view) void
{ Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
@autoreleasepool { { @autoreleasepool {
SDL_cocoametalview *metalview = CFBridgingRelease(view); SDL_cocoametalview *metalview = CFBridgingRelease(view);
[metalview removeFromSuperview]; [metalview removeFromSuperview];
} }}
}
void * void *
Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view) Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view)
{ { @autoreleasepool {
@autoreleasepool {
SDL_cocoametalview *cocoaview = (__bridge SDL_cocoametalview *)view; SDL_cocoametalview *cocoaview = (__bridge SDL_cocoametalview *)view;
return (__bridge void *)cocoaview.layer; return (__bridge void *)cocoaview.layer;
} }}
}
void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h) void
{ Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
@autoreleasepool { { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
NSView *contentView = data.sdlContentView; NSView *contentView = data.sdlContentView;
SDL_cocoametalview* metalview = [contentView viewWithTag:SDL_METALVIEW_TAG]; SDL_cocoametalview* metalview = [contentView viewWithTag:SDL_METALVIEW_TAG];
@ -192,8 +188,7 @@ void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
/* Fall back to the viewport size. */ /* Fall back to the viewport size. */
SDL_GetWindowSizeInPixels(window, w, h); SDL_GetWindowSizeInPixels(window, w, h);
} }
} }}
}
#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */ #endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */

View file

@ -41,7 +41,9 @@
#define kDisplayModeNativeFlag 0x02000000 #define kDisplayModeNativeFlag 0x02000000
#endif #endif
static int CG_SetError(const char *prefix, CGDisplayErr result)
static int
CG_SetError(const char *prefix, CGDisplayErr result)
{ {
const char *error; const char *error;
@ -83,7 +85,8 @@ static int CG_SetError(const char *prefix, CGDisplayErr result)
return SDL_SetError("%s: %s", prefix, error); return SDL_SetError("%s: %s", prefix, error);
} }
static int GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link) static int
GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link)
{ {
int refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5); int refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5);
@ -98,7 +101,8 @@ static int GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef
return refreshRate; return refreshRate;
} }
static SDL_bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode) static SDL_bool
HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
{ {
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode); uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
@ -115,7 +119,8 @@ static SDL_bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
return SDL_TRUE; return SDL_TRUE;
} }
static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode) static Uint32
GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
{ {
/* This API is deprecated in 10.11 with no good replacement (as of 10.15). */ /* This API is deprecated in 10.11 with no good replacement (as of 10.15). */
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode); CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
@ -139,7 +144,8 @@ static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
return pixelformat; return pixelformat;
} }
static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode) static SDL_bool
GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
{ {
SDL_DisplayModeData *data; SDL_DisplayModeData *data;
bool usableForGUI = CGDisplayModeIsUsableForDesktopGUI(vidmode); bool usableForGUI = CGDisplayModeIsUsableForDesktopGUI(vidmode);
@ -204,7 +210,10 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
/* Ignore this mode if it's low-dpi (@1x) and we have a high-dpi /* Ignore this mode if it's low-dpi (@1x) and we have a high-dpi
* mode in the list with the same size in points. * mode in the list with the same size in points.
*/ */
if (width == pixelW && height == pixelH && width == otherW && height == otherH && refreshrate == otherrefresh && format == otherformat && (otherpixelW != otherW || otherpixelH != otherH)) { if (width == pixelW && height == pixelH
&& width == otherW && height == otherH
&& refreshrate == otherrefresh && format == otherformat
&& (otherpixelW != otherW || otherpixelH != otherH)) {
CFRelease(modes); CFRelease(modes);
return SDL_FALSE; return SDL_FALSE;
} }
@ -212,7 +221,10 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
/* Ignore this mode if it's interlaced and there's a non-interlaced /* Ignore this mode if it's interlaced and there's a non-interlaced
* mode in the list with the same properties. * mode in the list with the same properties.
*/ */
if (interlaced && ((otherioflags & kDisplayModeInterlacedFlag) == 0) && width == otherW && height == otherH && pixelW == otherpixelW && pixelH == otherpixelH && refreshrate == otherrefresh && format == otherformat && usableForGUI == otherGUI) { if (interlaced && ((otherioflags & kDisplayModeInterlacedFlag) == 0)
&& width == otherW && height == otherH && pixelW == otherpixelW
&& pixelH == otherpixelH && refreshrate == otherrefresh
&& format == otherformat && usableForGUI == otherGUI) {
CFRelease(modes); CFRelease(modes);
return SDL_FALSE; return SDL_FALSE;
} }
@ -220,7 +232,9 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
/* Ignore this mode if it's not usable for desktop UI and its /* Ignore this mode if it's not usable for desktop UI and its
* properties are equal to another GUI-capable mode in the list. * properties are equal to another GUI-capable mode in the list.
*/ */
if (width == otherW && height == otherH && pixelW == otherpixelW && pixelH == otherpixelH && !usableForGUI && otherGUI && refreshrate == otherrefresh && format == otherformat) { if (width == otherW && height == otherH && pixelW == otherpixelW
&& pixelH == otherpixelH && !usableForGUI && otherGUI
&& refreshrate == otherrefresh && format == otherformat) {
CFRelease(modes); CFRelease(modes);
return SDL_FALSE; return SDL_FALSE;
} }
@ -246,7 +260,9 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
* correct but it being filtered out by SDL_AddDisplayMode as being * correct but it being filtered out by SDL_AddDisplayMode as being
* a duplicate. * a duplicate.
*/ */
if (width == otherW && height == otherH && pixelW == otherpixelW && pixelH == otherpixelH && usableForGUI == otherGUI && refreshrate == otherrefresh && format == otherformat) { if (width == otherW && height == otherH && pixelW == otherpixelW
&& pixelH == otherpixelH && usableForGUI == otherGUI
&& refreshrate == otherrefresh && format == otherformat) {
CFArrayAppendValue(modes, othermode); CFArrayAppendValue(modes, othermode);
} }
} }
@ -267,7 +283,8 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
return SDL_TRUE; return SDL_TRUE;
} }
static const char *Cocoa_GetDisplayName(CGDirectDisplayID displayID) static const char *
Cocoa_GetDisplayName(CGDirectDisplayID displayID)
{ {
/* This API is deprecated in 10.9 with no good replacement (as of 10.15). */ /* This API is deprecated in 10.9 with no good replacement (as of 10.15). */
io_service_t servicePort = CGDisplayIOServicePort(displayID); io_service_t servicePort = CGDisplayIOServicePort(displayID);
@ -282,9 +299,10 @@ static const char *Cocoa_GetDisplayName(CGDirectDisplayID displayID)
return displayName; return displayName;
} }
void Cocoa_InitModes(_THIS) void
Cocoa_InitModes(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
CGDisplayErr result; CGDisplayErr result;
CGDirectDisplayID *displays; CGDirectDisplayID *displays;
CGDisplayCount numDisplays; CGDisplayCount numDisplays;
@ -364,10 +382,10 @@ void Cocoa_InitModes(_THIS)
} }
} }
SDL_small_free(displays, isstack); SDL_small_free(displays, isstack);
} }}
}
int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int
Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{ {
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
CGRect cgrect; CGRect cgrect;
@ -380,7 +398,8 @@ int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
return 0; return 0;
} }
int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int
Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{ {
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
const CGDirectDisplayID cgdisplay = displaydata->display; const CGDirectDisplayID cgdisplay = displaydata->display;
@ -412,9 +431,10 @@ int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
return 0; return 0;
} }
int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi) int
Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
{ @autoreleasepool
{ {
@autoreleasepool {
const float MM_IN_INCH = 25.4f; const float MM_IN_INCH = 25.4f;
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
@ -488,10 +508,10 @@ int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hd
} }
} }
return 0; return 0;
} }}
}
void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display) void
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{ {
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
CVDisplayLinkRef link = NULL; CVDisplayLinkRef link = NULL;
@ -571,7 +591,8 @@ void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
CVDisplayLinkRelease(link); CVDisplayLinkRelease(link);
} }
static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data) static CGError
SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data)
{ {
/* SDL_DisplayModeData can contain multiple CGDisplayModes to try (with /* SDL_DisplayModeData can contain multiple CGDisplayModes to try (with
* identical properties), some of which might not work. See GetDisplayMode. * identical properties), some of which might not work. See GetDisplayMode.
@ -589,7 +610,8 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
return result; return result;
} }
int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) int
Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{ {
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata; SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
@ -654,7 +676,8 @@ ERR_NO_CAPTURE:
return -1; return -1;
} }
void Cocoa_QuitModes(_THIS) void
Cocoa_QuitModes(_THIS)
{ {
int i, j; int i, j;

View file

@ -31,8 +31,7 @@ extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event);
extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y); extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
extern void Cocoa_QuitMouse(_THIS); extern void Cocoa_QuitMouse(_THIS);
typedef struct typedef struct {
{
/* Whether we've seen a cursor warp since the last move event. */ /* Whether we've seen a cursor warp since the last move event. */
SDL_bool seenWarp; SDL_bool seenWarp;
/* What location our last cursor warp was to. */ /* What location our last cursor warp was to. */

View file

@ -33,9 +33,7 @@
#ifdef DEBUG_COCOAMOUSE #ifdef DEBUG_COCOAMOUSE
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#else #else
#define DLog(...) \ #define DLog(...) do { } while (0)
do { \
} while (0)
#endif #endif
@implementation NSCursor (InvisibleCursor) @implementation NSCursor (InvisibleCursor)
@ -64,9 +62,11 @@
} }
@end @end
static SDL_Cursor *Cocoa_CreateDefaultCursor()
static SDL_Cursor *
Cocoa_CreateDefaultCursor()
{ @autoreleasepool
{ {
@autoreleasepool {
NSCursor *nscursor; NSCursor *nscursor;
SDL_Cursor *cursor = NULL; SDL_Cursor *cursor = NULL;
@ -80,12 +80,12 @@ static SDL_Cursor *Cocoa_CreateDefaultCursor()
} }
return cursor; return cursor;
} }}
}
static SDL_Cursor *Cocoa_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) static SDL_Cursor *
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{ @autoreleasepool
{ {
@autoreleasepool {
NSImage *nsimage; NSImage *nsimage;
NSCursor *nscursor = NULL; NSCursor *nscursor = NULL;
SDL_Cursor *cursor = NULL; SDL_Cursor *cursor = NULL;
@ -103,13 +103,13 @@ static SDL_Cursor *Cocoa_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y
} }
return cursor; return cursor;
} }}
}
/* there are .pdf files of some of the cursors we need, installed by default on macOS, but not available through NSCursor. /* there are .pdf files of some of the cursors we need, installed by default on macOS, but not available through NSCursor.
If we can load them ourselves, use them, otherwise fallback to something standard but not super-great. If we can load them ourselves, use them, otherwise fallback to something standard but not super-great.
Since these are under /System, they should be available even to sandboxed apps. */ Since these are under /System, they should be available even to sandboxed apps. */
static NSCursor *LoadHiddenSystemCursor(NSString *cursorName, SEL fallback) static NSCursor *
LoadHiddenSystemCursor(NSString *cursorName, SEL fallback)
{ {
NSString *cursorPath = [@"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors" stringByAppendingPathComponent:cursorName]; NSString *cursorPath = [@"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors" stringByAppendingPathComponent:cursorName];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]]; NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
@ -146,9 +146,10 @@ static NSCursor *LoadHiddenSystemCursor(NSString *cursorName, SEL fallback)
return cursor; return cursor;
} }
static SDL_Cursor *Cocoa_CreateSystemCursor(SDL_SystemCursor id) static SDL_Cursor *
Cocoa_CreateSystemCursor(SDL_SystemCursor id)
{ @autoreleasepool
{ {
@autoreleasepool {
NSCursor *nscursor = NULL; NSCursor *nscursor = NULL;
SDL_Cursor *cursor = NULL; SDL_Cursor *cursor = NULL;
@ -203,20 +204,20 @@ static SDL_Cursor *Cocoa_CreateSystemCursor(SDL_SystemCursor id)
} }
return cursor; return cursor;
} }}
}
static void Cocoa_FreeCursor(SDL_Cursor *cursor) static void
Cocoa_FreeCursor(SDL_Cursor * cursor)
{ @autoreleasepool
{ {
@autoreleasepool {
CFBridgingRelease(cursor->driverdata); CFBridgingRelease(cursor->driverdata);
SDL_free(cursor); SDL_free(cursor);
} }}
}
static int Cocoa_ShowCursor(SDL_Cursor *cursor) static int
Cocoa_ShowCursor(SDL_Cursor * cursor)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_VideoDevice *device = SDL_GetVideoDevice();
SDL_Window *window = (device ? device->windows : NULL); SDL_Window *window = (device ? device->windows : NULL);
for (; window != NULL; window = window->next) { for (; window != NULL; window = window->next) {
@ -228,10 +229,10 @@ static int Cocoa_ShowCursor(SDL_Cursor *cursor)
} }
} }
return 0; return 0;
} }}
}
static SDL_Window *SDL_FindWindowAtPoint(const int x, const int y) static SDL_Window *
SDL_FindWindowAtPoint(const int x, const int y)
{ {
const SDL_Point pt = { x, y }; const SDL_Point pt = { x, y };
SDL_Window *i; SDL_Window *i;
@ -245,7 +246,8 @@ static SDL_Window *SDL_FindWindowAtPoint(const int x, const int y)
return NULL; return NULL;
} }
static int Cocoa_WarpMouseGlobal(int x, int y) static int
Cocoa_WarpMouseGlobal(int x, int y)
{ {
CGPoint point; CGPoint point;
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
@ -286,12 +288,14 @@ static int Cocoa_WarpMouseGlobal(int x, int y)
return 0; return 0;
} }
static void Cocoa_WarpMouse(SDL_Window *window, int x, int y) static void
Cocoa_WarpMouse(SDL_Window * window, int x, int y)
{ {
Cocoa_WarpMouseGlobal(window->x + x, window->y + y); Cocoa_WarpMouseGlobal(window->x + x, window->y + y);
} }
static int Cocoa_SetRelativeMouseMode(SDL_bool enabled) static int
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{ {
CGError result; CGError result;
SDL_Window *window; SDL_Window *window;
@ -334,14 +338,16 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
return 0; return 0;
} }
static int Cocoa_CaptureMouse(SDL_Window *window) static int
Cocoa_CaptureMouse(SDL_Window *window)
{ {
/* our Cocoa event code already tracks the mouse outside the window, /* our Cocoa event code already tracks the mouse outside the window,
so all we have to do here is say "okay" and do what we always do. */ so all we have to do here is say "okay" and do what we always do. */
return 0; return 0;
} }
static Uint32 Cocoa_GetGlobalMouseState(int *x, int *y) static Uint32
Cocoa_GetGlobalMouseState(int *x, int *y)
{ {
const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons]; const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
const NSPoint cocoaLocation = [NSEvent mouseLocation]; const NSPoint cocoaLocation = [NSEvent mouseLocation];
@ -359,7 +365,8 @@ static Uint32 Cocoa_GetGlobalMouseState(int *x, int *y)
return retval; return retval;
} }
int Cocoa_InitMouse(_THIS) int
Cocoa_InitMouse(_THIS)
{ {
NSPoint location; NSPoint location;
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
@ -387,7 +394,8 @@ int Cocoa_InitMouse(_THIS)
return 0; return 0;
} }
static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event) static void
Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
{ {
SDL_Window *window; SDL_Window *window;
NSWindow *nswindow = [event window]; NSWindow *nswindow = [event window];
@ -420,7 +428,8 @@ static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
} }
} }
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event) void
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
{ {
SDL_Mouse *mouse; SDL_Mouse *mouse;
SDL_MouseData *driverdata; SDL_MouseData *driverdata;
@ -499,7 +508,8 @@ void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY); SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
} }
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) void
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
{ {
SDL_MouseID mouseID; SDL_MouseID mouseID;
SDL_MouseWheelDirection direction; SDL_MouseWheelDirection direction;
@ -536,7 +546,8 @@ void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
SDL_SendMouseWheel(window, mouseID, x, y, direction); SDL_SendMouseWheel(window, mouseID, x, y, direction);
} }
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y) void
Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
{ {
/* This makes Cocoa_HandleMouseEvent ignore the delta caused by the warp, /* This makes Cocoa_HandleMouseEvent ignore the delta caused by the warp,
* since it gets included in the next movement event. * since it gets included in the next movement event.
@ -549,7 +560,8 @@ void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
DLog("(%g, %g)", x, y); DLog("(%g, %g)", x, y);
} }
void Cocoa_QuitMouse(_THIS) void
Cocoa_QuitMouse(_THIS)
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (mouse) { if (mouse) {

View file

@ -40,19 +40,14 @@ struct SDL_GLDriverData
int initialized; int initialized;
}; };
@interface SDLOpenGLContext : NSOpenGLContext @interface SDLOpenGLContext : NSOpenGLContext {
{
SDL_atomic_t dirty; SDL_atomic_t dirty;
SDL_Window *window; SDL_Window *window;
CVDisplayLinkRef displayLink; CVDisplayLinkRef displayLink;
@public @public SDL_mutex *swapIntervalMutex;
SDL_mutex *swapIntervalMutex; @public SDL_cond *swapIntervalCond;
@public @public SDL_atomic_t swapIntervalSetting;
SDL_cond *swapIntervalCond; @public SDL_atomic_t swapIntervalsPassed;
@public
SDL_atomic_t swapIntervalSetting;
@public
SDL_atomic_t swapIntervalsPassed;
} }
- (id)initWithFormat:(NSOpenGLPixelFormat *)format - (id)initWithFormat:(NSOpenGLPixelFormat *)format

View file

@ -56,12 +56,14 @@
static SDL_bool SDL_opengl_async_dispatch = SDL_FALSE; static SDL_bool SDL_opengl_async_dispatch = SDL_FALSE;
static void SDLCALL SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint) static void SDLCALL
SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{ {
SDL_opengl_async_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE); SDL_opengl_async_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
} }
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) static CVReturn
DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
{ {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *) displayLinkContext; SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *) displayLinkContext;
@ -165,9 +167,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
if ([NSThread isMainThread]) { if ([NSThread isMainThread]) {
[self setView:contentview]; [self setView:contentview];
} else { } else {
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:contentview]; });
[self setView:contentview];
});
} }
if (self == [NSOpenGLContext currentContext]) { if (self == [NSOpenGLContext currentContext]) {
[self explicitUpdate]; [self explicitUpdate];
@ -196,13 +196,9 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
[super update]; [super update];
} else { } else {
if (SDL_opengl_async_dispatch) { if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
[super update];
});
} else { } else {
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
[super update];
});
} }
} }
} }
@ -223,7 +219,9 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
@end @end
int Cocoa_GL_LoadLibrary(_THIS, const char *path)
int
Cocoa_GL_LoadLibrary(_THIS, const char *path)
{ {
/* Load the OpenGL library */ /* Load the OpenGL library */
if (path == NULL) { if (path == NULL) {
@ -247,7 +245,8 @@ Cocoa_GL_GetProcAddress(_THIS, const char *proc)
return SDL_LoadFunction(_this->gl_config.dll_handle, proc); return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
} }
void Cocoa_GL_UnloadLibrary(_THIS) void
Cocoa_GL_UnloadLibrary(_THIS)
{ {
SDL_UnloadObject(_this->gl_config.dll_handle); SDL_UnloadObject(_this->gl_config.dll_handle);
_this->gl_config.dll_handle = NULL; _this->gl_config.dll_handle = NULL;
@ -255,8 +254,8 @@ void Cocoa_GL_UnloadLibrary(_THIS)
SDL_GLContext SDL_GLContext
Cocoa_GL_CreateContext(_THIS, SDL_Window * window) Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormatAttribute attr[32];
@ -428,12 +427,12 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window *window)
/*_this->gl_config.minor_version = glversion_minor;*/ /*_this->gl_config.minor_version = glversion_minor;*/
} }
return sdlcontext; return sdlcontext;
} }}
}
int Cocoa_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) int
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{ {
@autoreleasepool {
if (context) { if (context) {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context; SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
if ([nscontext window] != window) { if ([nscontext window] != window) {
@ -446,12 +445,12 @@ int Cocoa_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
} }
return 0; return 0;
} }}
}
int Cocoa_GL_SetSwapInterval(_THIS, int interval) int
Cocoa_GL_SetSwapInterval(_THIS, int interval)
{ @autoreleasepool
{ {
@autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *) SDL_GL_GetCurrentContext(); SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *) SDL_GL_GetCurrentContext();
int status; int status;
@ -466,20 +465,20 @@ int Cocoa_GL_SetSwapInterval(_THIS, int interval)
} }
return status; return status;
} }}
}
int Cocoa_GL_GetSwapInterval(_THIS) int
Cocoa_GL_GetSwapInterval(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext(); SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
return nscontext ? SDL_AtomicGet(&nscontext->swapIntervalSetting) : 0; return nscontext ? SDL_AtomicGet(&nscontext->swapIntervalSetting) : 0;
} }}
}
int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window) int
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{ {
@autoreleasepool {
SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext(); SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting); const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
@ -511,16 +510,15 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window)
[nscontext updateIfNeeded]; [nscontext updateIfNeeded];
SDL_UnlockMutex(videodata.swaplock); SDL_UnlockMutex(videodata.swaplock);
return 0; return 0;
} }}
}
void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context) void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{ {
@autoreleasepool {
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)CFBridgingRelease(context); SDLOpenGLContext *nscontext = (SDLOpenGLContext *)CFBridgingRelease(context);
[nscontext setWindow:NULL]; [nscontext setWindow:NULL];
} }}
}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */ /* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__ #ifdef __clang__

View file

@ -28,7 +28,8 @@
/* EGL implementation of SDL OpenGL support */ /* EGL implementation of SDL OpenGL support */
int Cocoa_GLES_LoadLibrary(_THIS, const char *path) int
Cocoa_GLES_LoadLibrary(_THIS, const char *path)
{ {
/* If the profile requested is not GL ES, switch over to WIN_GL functions */ /* If the profile requested is not GL ES, switch over to WIN_GL functions */
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@ -58,8 +59,8 @@ int Cocoa_GLES_LoadLibrary(_THIS, const char *path)
SDL_GLContext SDL_GLContext
Cocoa_GLES_CreateContext(_THIS, SDL_Window * window) Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_GLContext context; SDL_GLContext context;
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
@ -114,18 +115,12 @@ Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
int int
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window) Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
{ {
@autoreleasepool { NSView* v;
SDL_EGL_DeleteContext(_this, context); /* The current context is lost in here; save it and reset it. */
Cocoa_GLES_UnloadLibrary(_this); SDL_WindowData *windowdata = (__bridge SDL_WindowData *) window->driverdata;
} SDL_Window *current_win = SDL_GL_GetCurrentWindow();
} SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
int Cocoa_GLES_SwapWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_WindowData *)window->driverdata).egl_surface);
}
}
if (_this->egl_data == NULL) { if (_this->egl_data == NULL) {
/* !!! FIXME: commenting out this assertion is (I think) incorrect; figure out why driver_loaded is wrong for ANGLE instead. --ryan. */ /* !!! FIXME: commenting out this assertion is (I think) incorrect; figure out why driver_loaded is wrong for ANGLE instead. --ryan. */
@ -136,11 +131,15 @@ int Cocoa_GLES_SwapWindow(_THIS, SDL_Window *window)
SDL_EGL_UnloadLibrary(_this); SDL_EGL_UnloadLibrary(_this);
return -1; return -1;
} }
_this->gl_config.driver_loaded = 1;
}
if (h) { /* Create the GLES window surface */
*h = height; v = windowdata.nswindow.contentView;
} windowdata.egl_surface = SDL_EGL_CreateSurface(_this, (__bridge NativeWindowType)[v layer]);
}
if (windowdata.egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Could not create GLES window surface");
} }
return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx); return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx);

View file

@ -41,8 +41,8 @@
SDL_WindowShaper* SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window) Cocoa_CreateShaper(SDL_Window* window)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_WindowShaper* result; SDL_WindowShaper* result;
SDL_ShapeData* data; SDL_ShapeData* data;
int resized_properly; int resized_properly;
@ -75,10 +75,10 @@ Cocoa_CreateShaper(SDL_Window *window)
resized_properly = Cocoa_ResizeWindowShape(window); resized_properly = Cocoa_ResizeWindowShape(window);
SDL_assert(resized_properly == 0); SDL_assert(resized_properly == 0);
return result; return result;
} }}
}
void ConvertRects(SDL_ShapeTree *tree, void *closure) void
ConvertRects(SDL_ShapeTree* tree, void* closure)
{ {
SDL_CocoaClosure* data = (__bridge SDL_CocoaClosure*)closure; SDL_CocoaClosure* data = (__bridge SDL_CocoaClosure*)closure;
if(tree->kind == OpaqueShape) { if(tree->kind == OpaqueShape) {
@ -87,9 +87,10 @@ void ConvertRects(SDL_ShapeTree *tree, void *closure)
} }
} }
int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode) int
Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_ShapeData* data = (__bridge SDL_ShapeData*)shaper->driverdata; SDL_ShapeData* data = (__bridge SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (__bridge SDL_WindowData*)shaper->window->driverdata; SDL_WindowData* windata = (__bridge SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure* closure; SDL_CocoaClosure* closure;
@ -115,17 +116,15 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
[closure.path addClip]; [closure.path addClip];
return 0; return 0;
} }}
}
int Cocoa_ResizeWindowShape(SDL_Window *window) int
{ Cocoa_ResizeWindowShape(SDL_Window *window)
@autoreleasepool { { @autoreleasepool {
SDL_ShapeData* data = (__bridge SDL_ShapeData*)window->shaper->driverdata; SDL_ShapeData* data = (__bridge SDL_ShapeData*)window->shaper->driverdata;
SDL_assert(data != NULL); SDL_assert(data != NULL);
return 0; return 0;
} }}
}
#endif /* SDL_VIDEO_DRIVER_COCOA */ #endif /* SDL_VIDEO_DRIVER_COCOA */

View file

@ -44,55 +44,25 @@ static void Cocoa_VideoQuit(_THIS);
/* Cocoa driver bootstrap functions */ /* Cocoa driver bootstrap functions */
static void Cocoa_DeleteDevice(SDL_VideoDevice *device) static void
Cocoa_DeleteDevice(SDL_VideoDevice * device)
{ @autoreleasepool
{ {
@autoreleasepool {
if (device->wakeup_lock) { if (device->wakeup_lock) {
SDL_DestroyMutex(device->wakeup_lock); SDL_DestroyMutex(device->wakeup_lock);
} }
CFBridgingRelease(device->driverdata); CFBridgingRelease(device->driverdata);
SDL_free(device); SDL_free(device);
} }}
}
static SDL_VideoDevice *Cocoa_CreateDevice(void) static SDL_VideoDevice *
Cocoa_CreateDevice(void)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoDevice *device; SDL_VideoDevice *device;
SDL_VideoData *data; SDL_VideoData *data;
device->CreateSDLWindow = Cocoa_CreateWindow; Cocoa_RegisterApp();
device->CreateSDLWindowFrom = Cocoa_CreateWindowFrom;
device->SetWindowTitle = Cocoa_SetWindowTitle;
device->SetWindowIcon = Cocoa_SetWindowIcon;
device->SetWindowPosition = Cocoa_SetWindowPosition;
device->SetWindowSize = Cocoa_SetWindowSize;
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
device->SetWindowOpacity = Cocoa_SetWindowOpacity;
device->GetWindowSizeInPixels = Cocoa_GetWindowSizeInPixels;
device->ShowWindow = Cocoa_ShowWindow;
device->HideWindow = Cocoa_HideWindow;
device->RaiseWindow = Cocoa_RaiseWindow;
device->MaximizeWindow = Cocoa_MaximizeWindow;
device->MinimizeWindow = Cocoa_MinimizeWindow;
device->RestoreWindow = Cocoa_RestoreWindow;
device->SetWindowBordered = Cocoa_SetWindowBordered;
device->SetWindowResizable = Cocoa_SetWindowResizable;
device->SetWindowAlwaysOnTop = Cocoa_SetWindowAlwaysOnTop;
device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
device->GetWindowICCProfile = Cocoa_GetWindowICCProfile;
device->GetWindowDisplayIndex = Cocoa_GetWindowDisplayIndex;
device->SetWindowMouseRect = Cocoa_SetWindowMouseRect;
device->SetWindowMouseGrab = Cocoa_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = Cocoa_SetWindowKeyboardGrab;
device->DestroyWindow = Cocoa_DestroyWindow;
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
device->SetWindowHitTest = Cocoa_SetWindowHitTest;
device->AcceptDragAndDrop = Cocoa_AcceptDragAndDrop;
device->FlashWindow = Cocoa_FlashWindow;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
@ -142,6 +112,8 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
device->SetWindowResizable = Cocoa_SetWindowResizable; device->SetWindowResizable = Cocoa_SetWindowResizable;
device->SetWindowAlwaysOnTop = Cocoa_SetWindowAlwaysOnTop; device->SetWindowAlwaysOnTop = Cocoa_SetWindowAlwaysOnTop;
device->SetWindowFullscreen = Cocoa_SetWindowFullscreen; device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
device->GetWindowICCProfile = Cocoa_GetWindowICCProfile; device->GetWindowICCProfile = Cocoa_GetWindowICCProfile;
device->GetWindowDisplayIndex = Cocoa_GetWindowDisplayIndex; device->GetWindowDisplayIndex = Cocoa_GetWindowDisplayIndex;
device->SetWindowMouseRect = Cocoa_SetWindowMouseRect; device->SetWindowMouseRect = Cocoa_SetWindowMouseRect;
@ -205,17 +177,18 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
device->free = Cocoa_DeleteDevice; device->free = Cocoa_DeleteDevice;
return device; return device;
} }}
}
VideoBootStrap COCOA_bootstrap = { VideoBootStrap COCOA_bootstrap = {
"cocoa", "SDL Cocoa video driver", "cocoa", "SDL Cocoa video driver",
Cocoa_CreateDevice Cocoa_CreateDevice
}; };
int Cocoa_VideoInit(_THIS)
int
Cocoa_VideoInit(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
Cocoa_InitModes(_this); Cocoa_InitModes(_this);
@ -233,20 +206,19 @@ int Cocoa_VideoInit(_THIS)
} }
return 0; return 0;
} }}
}
void Cocoa_VideoQuit(_THIS) void
Cocoa_VideoQuit(_THIS)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
Cocoa_QuitModes(_this); Cocoa_QuitModes(_this);
Cocoa_QuitKeyboard(_this); Cocoa_QuitKeyboard(_this);
Cocoa_QuitMouse(_this); Cocoa_QuitMouse(_this);
SDL_DestroyMutex(data.swaplock); SDL_DestroyMutex(data.swaplock);
data.swaplock = NULL; data.swaplock = NULL;
} }}
}
/* This function assumes that it's called from within an autorelease pool */ /* This function assumes that it's called from within an autorelease pool */
NSImage * NSImage *

View file

@ -139,10 +139,13 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
} }
SDL_free(extensions); SDL_free(extensions);
if (!hasSurfaceExtension) { if (!hasSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability library doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail; goto fail;
} else if (!hasMetalSurfaceExtension && !hasMacOSSurfaceExtension) { } else if (!hasMetalSurfaceExtension && !hasMacOSSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability library doesn't implement the " VK_EXT_METAL_SURFACE_EXTENSION_NAME " or " VK_MVK_MACOS_SURFACE_EXTENSION_NAME " extensions"); SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_EXT_METAL_SURFACE_EXTENSION_NAME " or "
VK_MVK_MACOS_SURFACE_EXTENSION_NAME " extensions");
goto fail; goto fail;
} }
return 0; return 0;

View file

@ -39,8 +39,7 @@ typedef enum
PENDING_OPERATION_MINIMIZE PENDING_OPERATION_MINIMIZE
} PendingWindowOperation; } PendingWindowOperation;
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> @interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
{
/* SDL_WindowData owns this Listener and has a strong reference to it. /* SDL_WindowData owns this Listener and has a strong reference to it.
* To avoid reference cycles, we could have either a weak or an * To avoid reference cycles, we could have either a weak or an
* unretained ref to the WindowData. */ * unretained ref to the WindowData. */

View file

@ -46,11 +46,10 @@
#ifdef DEBUG_COCOAWINDOW #ifdef DEBUG_COCOAWINDOW
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#else #else
#define DLog(...) \ #define DLog(...) do { } while (0)
do { \
} while (0)
#endif #endif
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN) #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
#ifndef MAC_OS_X_VERSION_10_12 #ifndef MAC_OS_X_VERSION_10_12
@ -159,8 +158,8 @@
} }
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ @autoreleasepool
{ {
@autoreleasepool {
NSPasteboard *pasteboard = [sender draggingPasteboard]; NSPasteboard *pasteboard = [sender draggingPasteboard];
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType]; NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
NSString *desiredType = [pasteboard availableTypeFromArray:types]; NSString *desiredType = [pasteboard availableTypeFromArray:types];
@ -223,8 +222,7 @@
SDL_SendDropComplete(sdlwindow); SDL_SendDropComplete(sdlwindow);
return YES; return YES;
} }}
}
- (BOOL)wantsPeriodicDraggingUpdates - (BOOL)wantsPeriodicDraggingUpdates
{ {
@ -251,6 +249,7 @@
@end @end
static Uint32 s_moveHack; static Uint32 s_moveHack;
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r) static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
@ -258,7 +257,8 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
} }
static void ScheduleContextUpdates(SDL_WindowData *data) static void
ScheduleContextUpdates(SDL_WindowData *data)
{ {
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */ /* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#if SDL_VIDEO_OPENGL #if SDL_VIDEO_OPENGL
@ -294,12 +294,14 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
} }
/* !!! FIXME: this should use a hint callback. */ /* !!! FIXME: this should use a hint callback. */
static int GetHintCtrlClickEmulateRightClick() static int
GetHintCtrlClickEmulateRightClick()
{ {
return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE); return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
} }
static NSUInteger GetWindowWindowedStyle(SDL_Window *window) static NSUInteger
GetWindowWindowedStyle(SDL_Window * window)
{ {
/* IF YOU CHANGE ANY FLAGS IN HERE, PLEASE READ /* IF YOU CHANGE ANY FLAGS IN HERE, PLEASE READ
the NSWindowStyleMaskBorderless comments in SetupWindowData()! */ the NSWindowStyleMaskBorderless comments in SetupWindowData()! */
@ -319,7 +321,8 @@ static NSUInteger GetWindowWindowedStyle(SDL_Window *window)
return style; return style;
} }
static NSUInteger GetWindowStyle(SDL_Window *window) static NSUInteger
GetWindowStyle(SDL_Window * window)
{ {
NSUInteger style = 0; NSUInteger style = 0;
@ -331,7 +334,8 @@ static NSUInteger GetWindowStyle(SDL_Window *window)
return style; return style;
} }
static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style) static SDL_bool
SetWindowStyle(SDL_Window * window, NSUInteger style)
{ {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
@ -351,7 +355,8 @@ static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style)
return SDL_TRUE; return SDL_TRUE;
} }
static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window) static SDL_bool
ShouldAdjustCoordinatesForGrab(SDL_Window * window)
{ {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -369,7 +374,8 @@ static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window)
return SDL_FALSE; return SDL_FALSE;
} }
static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, int x, int y, CGPoint *adjusted) static SDL_bool
AdjustCoordinatesForGrab(SDL_Window * window, int x, int y, CGPoint *adjusted)
{ {
if (window->mouse_rect.w > 0 && window->mouse_rect.h > 0) { if (window->mouse_rect.w > 0 && window->mouse_rect.h > 0) {
SDL_Rect window_rect; SDL_Rect window_rect;
@ -408,7 +414,8 @@ static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, int x, int y, CGPoi
return SDL_FALSE; return SDL_FALSE;
} }
static void Cocoa_UpdateClipCursor(SDL_Window *window) static void
Cocoa_UpdateClipCursor(SDL_Window * window)
{ {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -461,6 +468,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
} }
} }
@implementation Cocoa_WindowListener @implementation Cocoa_WindowListener
- (void)listen:(SDL_WindowData *)data - (void)listen:(SDL_WindowData *)data
@ -1179,7 +1187,8 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
return NO; /* not a special area, carry on. */ return NO; /* not a special area, carry on. */
} }
static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button) static int
Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * window, const Uint8 state, const Uint8 button)
{ {
const SDL_MouseID mouseID = mouse->mouseID; const SDL_MouseID mouseID = mouse->mouseID;
const int clicks = (int) [theEvent clickCount]; const int clicks = (int) [theEvent clickCount];
@ -1374,6 +1383,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
Cocoa_HandleMouseWheel(_data.window, theEvent); Cocoa_HandleMouseWheel(_data.window, theEvent);
} }
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent - (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent
{ {
SDL_Window *window = _data.window; SDL_Window *window = _data.window;
@ -1512,8 +1522,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
@end @end
@interface SDLView : NSView @interface SDLView : NSView {
{
SDL_Window *_sdlWindow; SDL_Window *_sdlWindow;
} }
@ -1608,9 +1617,10 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
} }
@end @end
static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView *nsview, SDL_bool created) static int
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview, SDL_bool created)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
SDL_WindowData *data; SDL_WindowData *data;
@ -1699,12 +1709,12 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
/* All done! */ /* All done! */
window->driverdata = (void *)CFBridgingRetain(data); window->driverdata = (void *)CFBridgingRetain(data);
return 0; return 0;
} }}
}
int Cocoa_CreateWindow(_THIS, SDL_Window *window) int
Cocoa_CreateWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
NSWindow *nswindow; NSWindow *nswindow;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -1790,11 +1800,285 @@ int Cocoa_CreateWindow(_THIS, SDL_Window *window)
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
[contentView setWantsLayer:TRUE]; [contentView setWantsLayer:TRUE];
} }
#endif /* SDL_VIDEO_OPENGL_EGL */
#endif /* SDL_VIDEO_OPENGL_ES2 */
[nswindow setContentView:contentView];
if (SetupWindowData(_this, window, nswindow, contentView, SDL_TRUE) < 0) {
return -1;
} }
void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
}
/* The rest of this macro mess is for OpenGL or OpenGL ES windows */
#if SDL_VIDEO_OPENGL_ES2
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
#if SDL_VIDEO_OPENGL_EGL
if (Cocoa_GLES_SetupWindow(_this, window) < 0) {
Cocoa_DestroyWindow(_this, window);
return -1;
}
return 0;
#else
return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
#endif /* SDL_VIDEO_OPENGL_EGL */
}
#endif /* SDL_VIDEO_OPENGL_ES2 */
return 0;
}}
int
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{ @autoreleasepool
{
NSView* nsview = nil;
NSWindow *nswindow = nil;
NSString *title;
BOOL highdpi;
if ([(__bridge id)data isKindOfClass:[NSWindow class]]) {
nswindow = (__bridge NSWindow*)data;
nsview = [nswindow contentView];
} else if ([(__bridge id)data isKindOfClass:[NSView class]]) {
nsview = (__bridge NSView*)data;
nswindow = [nsview window];
} else {
SDL_assert(false);
}
/* Query the title from the existing window */
title = [nswindow title];
if (title) {
window->title = SDL_strdup([title UTF8String]);
}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
* the NSHighResolutionCapable boolean is set in Info.plist. */
highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
[nsview setWantsBestResolutionOpenGLSurface:highdpi];
#ifdef __clang__
#pragma clang diagnostic pop
#endif
return SetupWindowData(_this, window, nswindow, nsview, SDL_FALSE);
}}
void
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
{ @autoreleasepool
{
const char *title = window->title ? window->title : "";
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
NSString *string = [[NSString alloc] initWithUTF8String:title];
[nswindow setTitle:string];
}}
void
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{ @autoreleasepool
{
NSImage *nsimage = Cocoa_CreateImage(icon);
if (nsimage) {
[NSApp setApplicationIconImage:nsimage];
}
}}
void
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = windata.nswindow;
NSRect rect;
Uint32 moveHack;
rect.origin.x = window->x;
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
moveHack = s_moveHack;
s_moveHack = 0;
[nswindow setFrameOrigin:rect.origin];
s_moveHack = moveHack;
ScheduleContextUpdates(windata);
}}
void
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = windata.nswindow;
NSRect rect;
Uint32 moveHack;
/* Cocoa will resize the window from the bottom-left rather than the
* top-left when -[nswindow setContentSize:] is used, so we must set the
* entire frame based on the new size, in order to preserve the position.
*/
rect.origin.x = window->x;
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
moveHack = s_moveHack;
s_moveHack = 0;
[nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
s_moveHack = moveHack;
ScheduleContextUpdates(windata);
}}
void
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSSize minSize;
minSize.width = window->min_w;
minSize.height = window->min_h;
[windata.nswindow setContentMinSize:minSize];
}}
void
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSSize maxSize;
maxSize.width = window->max_w;
maxSize.height = window->max_h;
[windata.nswindow setContentMaxSize:maxSize];
}}
void
Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSView *contentView = windata.sdlContentView;
NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
/* This gives us the correct viewport for a Retina-enabled view. */
viewport = [contentView convertRectToBacking:viewport];
}
*w = viewport.size.width;
*h = viewport.size.height;
}}
void
Cocoa_ShowWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windowData = ((__bridge SDL_WindowData *) window->driverdata);
NSWindow *nswindow = windowData.nswindow;
if (![nswindow isMiniaturized]) {
[windowData.listener pauseVisibleObservation];
[nswindow makeKeyAndOrderFront:nil];
[windowData.listener resumeVisibleObservation];
}
}}
void
Cocoa_HideWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
[nswindow orderOut:nil];
}}
void
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windowData = ((__bridge SDL_WindowData *) window->driverdata);
NSWindow *nswindow = windowData.nswindow;
/* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
a minimized or hidden window, so check for that before showing it.
*/
[windowData.listener pauseVisibleObservation];
if (![nswindow isMiniaturized] && [nswindow isVisible]) {
[NSApp activateIgnoringOtherApps:YES];
[nswindow makeKeyAndOrderFront:nil];
}
[windowData.listener resumeVisibleObservation];
}}
void
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = windata.nswindow;
[nswindow zoom:nil];
ScheduleContextUpdates(windata);
}}
void
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data.nswindow;
if ([data.listener isInFullscreenSpaceTransition]) {
[data.listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
} else {
[nswindow miniaturize:nil];
}
}}
void
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
if ([nswindow isMiniaturized]) {
[nswindow deminiaturize:nil];
} else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
[nswindow zoom:nil];
}
}}
void
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{ @autoreleasepool
{
if (SetWindowStyle(window, GetWindowStyle(window))) {
if (bordered) {
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
}
}
}}
void
Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
{ @autoreleasepool
{ {
@autoreleasepool {
/* Don't set this if we're in a space! /* Don't set this if we're in a space!
* The window will get permanently stuck if resizable is false. * The window will get permanently stuck if resizable is false.
* -flibit * -flibit
@ -1814,18 +2098,31 @@ void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged]; [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
} }
} }
} }}
}
void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) void
Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top)
{ @autoreleasepool
{ {
@autoreleasepool {
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow; NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
if (on_top) { if (on_top) {
[nswindow setLevel:NSFloatingWindowLevel]; [nswindow setLevel:NSFloatingWindowLevel];
} else { } else {
[nswindow setLevel:kCGNormalWindowLevel]; [nswindow setLevel:kCGNormalWindowLevel];
} }
}}
void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data.nswindow;
NSRect rect;
/* The view responder chain gets messed with during setStyleMask */
if ([data.sdlContentView nextResponder] == data.listener) {
[data.sdlContentView setNextResponder:nil];
} }
if (fullscreen) { if (fullscreen) {
@ -2037,27 +2334,54 @@ Cocoa_SetWindowMouseRect(_THIS, SDL_Window * window)
Cocoa_UpdateClipCursor(window); Cocoa_UpdateClipCursor(window);
} }
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) void
Cocoa_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data.nswindow;
NSRect rect;
/* The view responder chain gets messed with during setStyleMask */ Cocoa_UpdateClipCursor(window);
if ([data.sdlContentView nextResponder] == data.listener) {
[data.sdlContentView setNextResponder:nil]; if (data && (window->flags & SDL_WINDOW_FULLSCREEN)) {
if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)
&& ![data.listener isInFullscreenSpace]) {
/* OpenGL is rendering to the window, so make it visible! */
/* Doing this in 10.11 while in a Space breaks things (bug #3152) */
[data.nswindow setLevel:CGShieldingWindowLevel()];
} else if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
[data.nswindow setLevel:NSFloatingWindowLevel];
} else {
[data.nswindow setLevel:kCGNormalWindowLevel];
}
}
}}
void
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *data = (SDL_WindowData *) CFBridgingRelease(window->driverdata);
if (data) {
NSArray *contexts;
if ([data.listener isInFullscreenSpace]) {
[NSMenu setMenuBarVisible:YES];
}
[data.listener close];
data.listener = nil;
if (data.created) {
/* Release the content view to avoid further updateLayer callbacks */
[data.nswindow setContentView:nil];
[data.nswindow close];
} }
if (fullscreen) { #if SDL_VIDEO_OPENGL
SDL_Rect bounds;
Cocoa_GetDisplayBounds(_this, display, &bounds); contexts = [data.nscontexts copy];
rect.origin.x = bounds.x; for (SDLOpenGLContext *context in contexts) {
rect.origin.y = bounds.y; /* Calling setWindow:NULL causes the context to remove itself from the context list. */
rect.size.width = bounds.w; [context setWindow:NULL];
rect.size.height = bounds.h; }
ConvertNSRect([nswindow screen], fullscreen, &rect);
#endif /* SDL_VIDEO_OPENGL */ #endif /* SDL_VIDEO_OPENGL */
@ -2111,255 +2435,6 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
return SDL_FALSE; return SDL_FALSE;
} }
data.inWindowFullscreenTransition = SDL_TRUE;
if ([data.listener setFullscreenSpace:(state ? YES : NO)]) {
const int maxattempts = 3;
int attempt = 0;
while (++attempt <= maxattempts) {
/* Wait for the transition to complete, so application changes
take effect properly (e.g. setting the window size, etc.)
*/
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_14) {
NSRect screenRect = [[nswindow screen] frame];
if (screenRect.size.height >= 1.0f) {
rect.origin.y += (screenRect.size.height - rect.size.height);
}
}
[nswindow setStyleMask:NSWindowStyleMaskBorderless];
} else {
NSRect frameRect;
rect.origin.x = window->windowed.x;
rect.origin.y = window->windowed.y;
rect.size.width = window->windowed.w;
rect.size.height = window->windowed.h;
ConvertNSRect([nswindow screen], fullscreen, &rect);
/* The window is not meant to be fullscreen, but its flags might have a
* fullscreen bit set if it's scheduled to go fullscreen immediately
* after. Always using the windowed mode style here works around bugs in
* macOS 10.15 where the window doesn't properly restore the windowed
* mode decorations after exiting fullscreen-desktop, when the window
* was created as fullscreen-desktop. */
[nswindow setStyleMask:GetWindowWindowedStyle(window)];
/* Hack to restore window decorations on macOS 10.10 */
frameRect = [nswindow frame];
[nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
[nswindow setFrame:frameRect display:NO];
}
/* The view responder chain gets messed with during setStyleMask */
if ([data.sdlContentView nextResponder] != data.listener) {
[data.sdlContentView setNextResponder:data.listener];
}
s_moveHack = 0;
[nswindow setContentSize:rect.size];
[nswindow setFrameOrigin:rect.origin];
s_moveHack = SDL_GetTicks();
/* When the window style changes the title is cleared */
if (!fullscreen) {
Cocoa_SetWindowTitle(_this, window);
}
if (SDL_ShouldAllowTopmost() && fullscreen) {
/* OpenGL is rendering to the window, so make it visible! */
[nswindow setLevel:CGShieldingWindowLevel()];
} else if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
[nswindow setLevel:NSFloatingWindowLevel];
} else {
[nswindow setLevel:kCGNormalWindowLevel];
}
if ([nswindow isVisible] || fullscreen) {
[data.listener pauseVisibleObservation];
[nswindow makeKeyAndOrderFront:nil];
[data.listener resumeVisibleObservation];
}
ScheduleContextUpdates(data);
}
}
void *
Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size)
{
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow;
NSScreen *screen = [nswindow screen];
NSData *iccProfileData = nil;
void *retIccProfileData = NULL;
if (screen == nil) {
SDL_SetError("Could not get screen of window.");
return NULL;
}
if ([screen colorSpace] == nil) {
SDL_SetError("Could not get colorspace information of screen.");
return NULL;
}
iccProfileData = [[screen colorSpace] ICCProfileData];
if (iccProfileData == nil) {
SDL_SetError("Could not get ICC profile data.");
return NULL;
}
retIccProfileData = SDL_malloc([iccProfileData length]);
if (!retIccProfileData) {
SDL_OutOfMemory();
return NULL;
}
[iccProfileData getBytes:retIccProfileData length:[iccProfileData length]];
*size = [iccProfileData length];
return retIccProfileData;
}
}
int Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window *window)
{
@autoreleasepool {
NSScreen *screen;
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
/* Not recognized via CHECK_WINDOW_MAGIC */
if (data == nil) {
/* Don't set the error here, it hides other errors and is ignored anyway */
/*return SDL_SetError("Window data not set");*/
return -1;
}
/* NSWindow.screen may be nil when the window is off-screen. */
screen = data.nswindow.screen;
if (screen != nil) {
CGDirectDisplayID displayid;
int i;
/* https://developer.apple.com/documentation/appkit/nsscreen/1388360-devicedescription?language=objc */
displayid = [[screen.deviceDescription objectForKey:@"NSScreenNumber"] unsignedIntValue];
for (i = 0; i < _this->num_displays; i++) {
SDL_DisplayData *displaydata = (SDL_DisplayData *)_this->displays[i].driverdata;
if (displaydata != NULL && displaydata->display == displayid) {
return i;
}
}
}
/* Other code may expect SDL_GetWindowDisplayIndex to always return a valid
* index for a window. The higher level GetWindowDisplayIndex code will fall
* back to a generic position-based query if the backend implementation
* fails. */
return SDL_SetError("Couldn't find the display where the window is located.");
}
}
void Cocoa_SetWindowMouseRect(_THIS, SDL_Window *window)
{
Cocoa_UpdateClipCursor(window);
}
void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
{
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
Cocoa_UpdateClipCursor(window);
if (data && (window->flags & SDL_WINDOW_FULLSCREEN)) {
if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS) && ![data.listener isInFullscreenSpace]) {
/* OpenGL is rendering to the window, so make it visible! */
/* Doing this in 10.11 while in a Space breaks things (bug #3152) */
[data.nswindow setLevel:CGShieldingWindowLevel()];
} else if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
[data.nswindow setLevel:NSFloatingWindowLevel];
} else {
[data.nswindow setLevel:kCGNormalWindowLevel];
}
}
}
}
void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = (SDL_WindowData *)CFBridgingRelease(window->driverdata);
if (data) {
NSArray *contexts;
if ([data.listener isInFullscreenSpace]) {
[NSMenu setMenuBarVisible:YES];
}
[data.listener close];
data.listener = nil;
if (data.created) {
/* Release the content view to avoid further updateLayer callbacks */
[data.nswindow setContentView:nil];
[data.nswindow close];
}
#if SDL_VIDEO_OPENGL
contexts = [data.nscontexts copy];
for (SDLOpenGLContext *context in contexts) {
/* Calling setWindow:NULL causes the context to remove itself from the context list. */
[context setWindow:NULL];
}
#endif /* SDL_VIDEO_OPENGL */
if (window->shaper) {
CFBridgingRelease(window->shaper->driverdata);
SDL_free(window->shaper);
window->shaper = NULL;
}
}
window->driverdata = NULL;
}
}
int Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{
@autoreleasepool {
NSWindow *nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow;
info->subsystem = SDL_SYSWM_COCOA;
info->info.cocoa.window = nswindow;
return 0;
}
}
SDL_bool
Cocoa_IsWindowInFullscreenSpace(SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
if ([data.listener isInFullscreenSpace]) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
}
SDL_bool
Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state)
{
@autoreleasepool {
SDL_bool succeeded = SDL_FALSE;
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
if (data.inWindowFullscreenTransition) {
return SDL_FALSE;
}
data.inWindowFullscreenTransition = SDL_TRUE; data.inWindowFullscreenTransition = SDL_TRUE;
if ([data.listener setFullscreenSpace:(state ? YES : NO)]) { if ([data.listener setFullscreenSpace:(state ? YES : NO)]) {
const int maxattempts = 3; const int maxattempts = 3;
@ -2390,29 +2465,30 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state)
data.inWindowFullscreenTransition = SDL_FALSE; data.inWindowFullscreenTransition = SDL_FALSE;
return succeeded; return succeeded;
} }}
}
int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled) int
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
{ {
return 0; /* just succeed, the real work is done elsewhere. */ return 0; /* just succeed, the real work is done elsewhere. */
} }
void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept) void
Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
if (accept) { if (accept) {
[data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]]; [data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
} else { } else {
[data.nswindow unregisterDraggedTypes]; [data.nswindow unregisterDraggedTypes];
} }
} }}
}
int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation) int
Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
{ @autoreleasepool
{ {
@autoreleasepool {
/* Note that this is app-wide and not window-specific! */ /* Note that this is app-wide and not window-specific! */
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -2435,17 +2511,16 @@ int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
return SDL_Unsupported(); return SDL_Unsupported();
} }
return 0; return 0;
} }}
}
int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) int
Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
[data.nswindow setAlphaValue:opacity]; [data.nswindow setAlphaValue:opacity];
return 0; return 0;
} }}
}
#endif /* SDL_VIDEO_DRIVER_COCOA */ #endif /* SDL_VIDEO_DRIVER_COCOA */

View file

@ -87,7 +87,8 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
#if !TARGET_OS_TV #if !TARGET_OS_TV
/* Load a launch image using the old UILaunchImageFile-era naming rules. */ /* Load a launch image using the old UILaunchImageFile-era naming rules. */
static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh) static UIImage *
SDL_LoadLaunchImageNamed(NSString *name, int screenh)
{ {
UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation; UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom; UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
@ -131,15 +132,13 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
@implementation SDLLaunchStoryboardViewController @implementation SDLLaunchStoryboardViewController
- (instancetype)initWithStoryboardViewController:(UIViewController *)storyboardViewController - (instancetype)initWithStoryboardViewController:(UIViewController *)storyboardViewController {
{
self = [super init]; self = [super init];
self.storyboardViewController = storyboardViewController; self.storyboardViewController = storyboardViewController;
return self; return self;
} }
- (void)viewDidLoad - (void)viewDidLoad {
{
[super viewDidLoad]; [super viewDidLoad];
[self addChildViewController:self.storyboardViewController]; [self addChildViewController:self.storyboardViewController];
@ -152,13 +151,11 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
UIApplication.sharedApplication.statusBarStyle = self.preferredStatusBarStyle; UIApplication.sharedApplication.statusBarStyle = self.preferredStatusBarStyle;
} }
- (BOOL)prefersStatusBarHidden - (BOOL)prefersStatusBarHidden {
{
return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarHidden"] boolValue]; return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarHidden"] boolValue];
} }
- (UIStatusBarStyle)preferredStatusBarStyle - (UIStatusBarStyle)preferredStatusBarStyle {
{
NSString *statusBarStyle = [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarStyle"]; NSString *statusBarStyle = [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarStyle"];
if ([statusBarStyle isEqualToString:@"UIStatusBarStyleLightContent"]) { if ([statusBarStyle isEqualToString:@"UIStatusBarStyleLightContent"]) {
return UIStatusBarStyleLightContent; return UIStatusBarStyleLightContent;
@ -347,8 +344,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
@end @end
@implementation SDLUIKitDelegate @implementation SDLUIKitDelegate {
{
UIWindow *launchWindow; UIWindow *launchWindow;
} }
@ -379,11 +375,9 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
launchWindow = nil; launchWindow = nil;
/* Do a nice animated fade-out (roughly matches the real launch behavior.) */ /* Do a nice animated fade-out (roughly matches the real launch behavior.) */
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2 animations:^{
animations:^{
window.alpha = 0.0; window.alpha = 0.0;
} } completion:^(BOOL finished) {
completion:^(BOOL finished) {
window.hidden = YES; window.hidden = YES;
UIKit_ForceUpdateHomeIndicator(); /* Wait for launch screen to hide so settings are applied to the actual view controller. */ UIKit_ForceUpdateHomeIndicator(); /* Wait for launch screen to hide so settings are applied to the actual view controller. */
}]; }];

View file

@ -27,7 +27,8 @@
#import <UIKit/UIPasteboard.h> #import <UIKit/UIPasteboard.h>
int UIKit_SetClipboardText(_THIS, const char *text) int
UIKit_SetClipboardText(_THIS, const char *text)
{ {
#if TARGET_OS_TV #if TARGET_OS_TV
return SDL_SetError("The clipboard is not available on tvOS"); return SDL_SetError("The clipboard is not available on tvOS");
@ -71,7 +72,8 @@ UIKit_HasClipboardText(_THIS)
} }
} }
void UIKit_InitClipboard(_THIS) void
UIKit_InitClipboard(_THIS)
{ {
#if !TARGET_OS_TV #if !TARGET_OS_TV
@autoreleasepool { @autoreleasepool {
@ -90,7 +92,8 @@ void UIKit_InitClipboard(_THIS)
#endif #endif
} }
void UIKit_QuitClipboard(_THIS) void
UIKit_QuitClipboard(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;

View file

@ -41,6 +41,7 @@
static BOOL UIKit_EventPumpEnabled = YES; static BOOL UIKit_EventPumpEnabled = YES;
@interface SDL_LifecycleObserver : NSObject @interface SDL_LifecycleObserver : NSObject
@property (nonatomic, assign) BOOL isObservingNotifications; @property (nonatomic, assign) BOOL isObservingNotifications;
@end @end
@ -59,10 +60,7 @@ static BOOL UIKit_EventPumpEnabled = YES;
[notificationCenter addObserver:self selector:@selector(applicationWillTerminate) name:UIApplicationWillTerminateNotification object:nil]; [notificationCenter addObserver:self selector:@selector(applicationWillTerminate) name:UIApplicationWillTerminateNotification object:nil];
[notificationCenter addObserver:self selector:@selector(applicationDidReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [notificationCenter addObserver:self selector:@selector(applicationDidReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
#if !TARGET_OS_TV #if !TARGET_OS_TV
[notificationCenter addObserver:self [notificationCenter addObserver:self selector:@selector(applicationDidChangeStatusBarOrientation) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
selector:@selector(applicationDidChangeStatusBarOrientation)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
#endif #endif
} else if (!UIKit_EventPumpEnabled && self.isObservingNotifications) { } else if (!UIKit_EventPumpEnabled && self.isObservingNotifications) {
self.isObservingNotifications = NO; self.isObservingNotifications = NO;
@ -109,7 +107,9 @@ static BOOL UIKit_EventPumpEnabled = YES;
@end @end
void SDL_iPhoneSetEventPump(SDL_bool enabled)
void
SDL_iPhoneSetEventPump(SDL_bool enabled)
{ {
UIKit_EventPumpEnabled = enabled; UIKit_EventPumpEnabled = enabled;
@ -121,7 +121,8 @@ void SDL_iPhoneSetEventPump(SDL_bool enabled)
[lifecycleObserver eventPumpChanged]; [lifecycleObserver eventPumpChanged];
} }
void UIKit_PumpEvents(_THIS) void
UIKit_PumpEvents(_THIS)
{ {
if (!UIKit_EventPumpEnabled) { if (!UIKit_EventPumpEnabled) {
return; return;
@ -161,7 +162,8 @@ static id keyboard_disconnect_observer = nil;
static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
{ {
keyboard_connected = SDL_TRUE; keyboard_connected = SDL_TRUE;
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) { keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed)
{
SDL_SendKeyboardKey(pressed ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)keyCode); SDL_SendKeyboardKey(pressed ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)keyCode);
}; };
@ -250,6 +252,7 @@ void SDL_QuitGCKeyboard(void)
#endif /* ENABLE_GCKEYBOARD */ #endif /* ENABLE_GCKEYBOARD */
#ifdef ENABLE_GCMOUSE #ifdef ENABLE_GCMOUSE
static int mice_connected = 0; static int mice_connected = 0;
@ -283,31 +286,37 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
{ {
SDL_MouseID mouseID = mice_connected; SDL_MouseID mouseID = mice_connected;
mouse.mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { mouse.mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)
{
OnGCMouseButtonChanged(mouseID, SDL_BUTTON_LEFT, pressed); OnGCMouseButtonChanged(mouseID, SDL_BUTTON_LEFT, pressed);
}; };
mouse.mouseInput.middleButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { mouse.mouseInput.middleButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)
{
OnGCMouseButtonChanged(mouseID, SDL_BUTTON_MIDDLE, pressed); OnGCMouseButtonChanged(mouseID, SDL_BUTTON_MIDDLE, pressed);
}; };
mouse.mouseInput.rightButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { mouse.mouseInput.rightButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)
{
OnGCMouseButtonChanged(mouseID, SDL_BUTTON_RIGHT, pressed); OnGCMouseButtonChanged(mouseID, SDL_BUTTON_RIGHT, pressed);
}; };
int auxiliary_button = SDL_BUTTON_X1; int auxiliary_button = SDL_BUTTON_X1;
for (GCControllerButtonInput *btn in mouse.mouseInput.auxiliaryButtons) { for (GCControllerButtonInput *btn in mouse.mouseInput.auxiliaryButtons) {
btn.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { btn.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)
{
OnGCMouseButtonChanged(mouseID, auxiliary_button, pressed); OnGCMouseButtonChanged(mouseID, auxiliary_button, pressed);
}; };
++auxiliary_button; ++auxiliary_button;
} }
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY) { mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY)
{
if (SDL_GCMouseRelativeMode()) { if (SDL_GCMouseRelativeMode()) {
SDL_SendMouseMotion(SDL_GetMouseFocus(), mouseID, 1, (int)deltaX, -(int)deltaY); SDL_SendMouseMotion(SDL_GetMouseFocus(), mouseID, 1, (int)deltaX, -(int)deltaY);
} }
}; };
mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue)
{
SDL_SendMouseWheel(SDL_GetMouseFocus(), 0, xValue, yValue, SDL_MOUSEWHEEL_NORMAL); SDL_SendMouseWheel(SDL_GetMouseFocus(), 0, xValue, yValue, SDL_MOUSEWHEEL_NORMAL);
}; };

View file

@ -36,7 +36,8 @@ UIKit_ShowingMessageBox(void)
return s_showingMessageBox; return s_showingMessageBox;
} }
static void UIKit_WaitUntilMessageBoxClosed(const SDL_MessageBoxData *messageboxdata, int *clickedindex) static void
UIKit_WaitUntilMessageBoxClosed(const SDL_MessageBoxData *messageboxdata, int *clickedindex)
{ {
*clickedindex = messageboxdata->numbuttons; *clickedindex = messageboxdata->numbuttons;
@ -51,7 +52,8 @@ static void UIKit_WaitUntilMessageBoxClosed(const SDL_MessageBoxData *messagebox
} }
} }
static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messageboxdata, int *buttonid) static BOOL
UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{ {
int i; int i;
int __block clickedindex = messageboxdata->numbuttons; int __block clickedindex = messageboxdata->numbuttons;
@ -122,32 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
return YES; return YES;
} }
static void UIKit_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue) static void
UIKit_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue)
{ @autoreleasepool
{ {
@autoreleasepool {
if (UIKit_ShowMessageBoxAlertController(messageboxdata, buttonid)) { if (UIKit_ShowMessageBoxAlertController(messageboxdata, buttonid)) {
*returnValue = 0; *returnValue = 0;
} else { } else {
*returnValue = SDL_SetError("Could not show message box."); *returnValue = SDL_SetError("Could not show message box.");
} }
} }}
}
int UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) int
UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{ @autoreleasepool
{ {
@autoreleasepool {
__block int returnValue = 0; __block int returnValue = 0;
if ([NSThread isMainThread]) { if ([NSThread isMainThread]) {
UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue); UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
} else { } else {
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue); });
UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
});
} }
return returnValue; return returnValue;
} }}
}
#endif /* SDL_VIDEO_DRIVER_UIKIT */ #endif /* SDL_VIDEO_DRIVER_UIKIT */

View file

@ -38,6 +38,7 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
@interface SDL_uikitmetalview : SDL_uikitview @interface SDL_uikitmetalview : SDL_uikitview
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame

View file

@ -76,8 +76,7 @@
SDL_MetalView SDL_MetalView
UIKit_Metal_CreateView(_THIS, SDL_Window * window) UIKit_Metal_CreateView(_THIS, SDL_Window * window)
{ { @autoreleasepool {
@autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
CGFloat scale = 1.0; CGFloat scale = 1.0;
SDL_uikitmetalview *metalview; SDL_uikitmetalview *metalview;
@ -101,30 +100,27 @@ UIKit_Metal_CreateView(_THIS, SDL_Window *window)
[metalview setSDLWindow:window]; [metalview setSDLWindow:window];
return (void*)CFBridgingRetain(metalview); return (void*)CFBridgingRetain(metalview);
} }}
}
void UIKit_Metal_DestroyView(_THIS, SDL_MetalView view) void
{ UIKit_Metal_DestroyView(_THIS, SDL_MetalView view)
@autoreleasepool { { @autoreleasepool {
SDL_uikitmetalview *metalview = CFBridgingRelease(view); SDL_uikitmetalview *metalview = CFBridgingRelease(view);
if ([metalview isKindOfClass:[SDL_uikitmetalview class]]) { if ([metalview isKindOfClass:[SDL_uikitmetalview class]]) {
[metalview setSDLWindow:NULL]; [metalview setSDLWindow:NULL];
} }
} }}
}
void * void *
UIKit_Metal_GetLayer(_THIS, SDL_MetalView view) UIKit_Metal_GetLayer(_THIS, SDL_MetalView view)
{ { @autoreleasepool {
@autoreleasepool {
SDL_uikitview *uiview = (__bridge SDL_uikitview *)view; SDL_uikitview *uiview = (__bridge SDL_uikitview *)view;
return (__bridge void *)uiview.layer; return (__bridge void *)uiview.layer;
} }}
}
void UIKit_Metal_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h) void
UIKit_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;

View file

@ -141,8 +141,7 @@
struct utsname systemInfo; struct utsname systemInfo;
uname(&systemInfo); uname(&systemInfo);
NSString* deviceName = NSString* deviceName =
[NSString stringWithCString:systemInfo.machine [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
encoding:NSUTF8StringEncoding];
id foundDPI = devices[deviceName]; id foundDPI = devices[deviceName];
if (foundDPI) { if (foundDPI) {
self.screenDPI = (float)[foundDPI integerValue]; self.screenDPI = (float)[foundDPI integerValue];
@ -186,14 +185,10 @@
{ {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self [center addObserver:self selector:@selector(screenConnected:)
selector:@selector(screenConnected:) name:UIScreenDidConnectNotification object:nil];
name:UIScreenDidConnectNotification [center addObserver:self selector:@selector(screenDisconnected:)
object:nil]; name:UIScreenDidDisconnectNotification object:nil];
[center addObserver:self
selector:@selector(screenDisconnected:)
name:UIScreenDidDisconnectNotification
object:nil];
} }
+ (void)stop + (void)stop
@ -201,11 +196,9 @@
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center removeObserver:self [center removeObserver:self
name:UIScreenDidConnectNotification name:UIScreenDidConnectNotification object:nil];
object:nil];
[center removeObserver:self [center removeObserver:self
name:UIScreenDidDisconnectNotification name:UIScreenDidDisconnectNotification object:nil];
object:nil];
} }
+ (void)screenConnected:(NSNotification*)notification + (void)screenConnected:(NSNotification*)notification
@ -222,7 +215,8 @@
@end @end
static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode, static int
UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
UIScreenMode * uiscreenmode) UIScreenMode * uiscreenmode)
{ {
SDL_DisplayModeData *data = nil; SDL_DisplayModeData *data = nil;
@ -242,7 +236,8 @@ static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode,
return 0; return 0;
} }
static void UIKit_FreeDisplayModeData(SDL_DisplayMode *mode) static void
UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
{ {
if (mode->driverdata != NULL) { if (mode->driverdata != NULL) {
CFRelease(mode->driverdata); CFRelease(mode->driverdata);
@ -250,7 +245,8 @@ static void UIKit_FreeDisplayModeData(SDL_DisplayMode *mode)
} }
} }
static NSUInteger UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen) static NSUInteger
UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
{ {
#ifdef __IPHONE_10_3 #ifdef __IPHONE_10_3
if ([uiscreen respondsToSelector:@selector(maximumFramesPerSecond)]) { if ([uiscreen respondsToSelector:@selector(maximumFramesPerSecond)]) {
@ -260,7 +256,8 @@ static NSUInteger UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
return 0; return 0;
} }
static int UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h, static int
UIKit_AddSingleDisplayMode(SDL_VideoDisplay * display, int w, int h,
UIScreen * uiscreen, UIScreenMode * uiscreenmode) UIScreen * uiscreen, UIScreenMode * uiscreenmode)
{ {
SDL_DisplayMode mode; SDL_DisplayMode mode;
@ -283,7 +280,8 @@ static int UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h,
} }
} }
static int UIKit_AddDisplayMode(SDL_VideoDisplay *display, int w, int h, UIScreen *uiscreen, static int
UIKit_AddDisplayMode(SDL_VideoDisplay * display, int w, int h, UIScreen * uiscreen,
UIScreenMode * uiscreenmode, SDL_bool addRotation) UIScreenMode * uiscreenmode, SDL_bool addRotation)
{ {
if (UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode) < 0) { if (UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode) < 0) {
@ -300,7 +298,8 @@ static int UIKit_AddDisplayMode(SDL_VideoDisplay *display, int w, int h, UIScree
return 0; return 0;
} }
int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event) int
UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
{ {
UIScreenMode *uiscreenmode = uiscreen.currentMode; UIScreenMode *uiscreenmode = uiscreen.currentMode;
CGSize size = uiscreen.bounds.size; CGSize size = uiscreen.bounds.size;
@ -341,7 +340,8 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
return 0; return 0;
} }
void UIKit_DelDisplay(UIScreen *uiscreen) void
UIKit_DelDisplay(UIScreen *uiscreen)
{ {
int i; int i;
@ -370,7 +370,8 @@ UIKit_IsDisplayLandscape(UIScreen *uiscreen)
} }
} }
int UIKit_InitModes(_THIS) int
UIKit_InitModes(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
for (UIScreen *uiscreen in [UIScreen screens]) { for (UIScreen *uiscreen in [UIScreen screens]) {
@ -388,7 +389,8 @@ int UIKit_InitModes(_THIS)
return 0; return 0;
} }
void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display) void
UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{ {
@autoreleasepool { @autoreleasepool {
SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
@ -432,7 +434,8 @@ void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
} }
} }
int UIKit_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi) int
UIKit_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
{ {
@autoreleasepool { @autoreleasepool {
SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
@ -452,7 +455,8 @@ int UIKit_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hd
return 0; return 0;
} }
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) int
UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{ {
@autoreleasepool { @autoreleasepool {
SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata; SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
@ -481,7 +485,8 @@ int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode
return 0; return 0;
} }
int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int
UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{ {
@autoreleasepool { @autoreleasepool {
int displayIndex = (int) (display - _this->displays); int displayIndex = (int) (display - _this->displays);
@ -503,7 +508,8 @@ int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
return 0; return 0;
} }
void UIKit_QuitModes(_THIS) void
UIKit_QuitModes(_THIS)
{ {
[SDL_DisplayWatch stop]; [SDL_DisplayWatch stop];

View file

@ -64,7 +64,8 @@ UIKit_GL_GetProcAddress(_THIS, const char *proc)
/* /*
note that SDL_GL_DeleteContext makes it current without passing the window note that SDL_GL_DeleteContext makes it current without passing the window
*/ */
int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) int
UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ {
@autoreleasepool { @autoreleasepool {
SDLEAGLContext *eaglcontext = (__bridge SDLEAGLContext *) context; SDLEAGLContext *eaglcontext = (__bridge SDLEAGLContext *) context;
@ -81,7 +82,8 @@ int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
return 0; return 0;
} }
void UIKit_GL_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h) void
UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
@ -100,7 +102,8 @@ void UIKit_GL_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
} }
} }
int UIKit_GL_LoadLibrary(_THIS, const char *path) int
UIKit_GL_LoadLibrary(_THIS, const char *path)
{ {
/* We shouldn't pass a path to this function, since we've already loaded the /* We shouldn't pass a path to this function, since we've already loaded the
* library. */ * library. */
@ -207,7 +210,8 @@ UIKit_GL_CreateContext(_THIS, SDL_Window *window)
} }
} }
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context) void
UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
{ {
@autoreleasepool { @autoreleasepool {
/* The context was retained in SDL_GL_CreateContext, so we release it /* The context was retained in SDL_GL_CreateContext, so we release it
@ -217,7 +221,8 @@ void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
} }
} }
void UIKit_GL_RestoreCurrentContext(void) void
UIKit_GL_RestoreCurrentContext(void)
{ {
@autoreleasepool { @autoreleasepool {
/* Some iOS system functionality (such as Dictation on the on-screen /* Some iOS system functionality (such as Dictation on the on-screen

View file

@ -27,8 +27,7 @@
#import "SDL_uikitopenglview.h" #import "SDL_uikitopenglview.h"
#include "SDL_uikitwindow.h" #include "SDL_uikitwindow.h"
@implementation SDL_uikitopenglview @implementation SDL_uikitopenglview {
{
/* The renderbuffer and framebuffer used to render to this layer. */ /* The renderbuffer and framebuffer used to render to this layer. */
GLuint viewRenderbuffer, viewFramebuffer; GLuint viewRenderbuffer, viewFramebuffer;

View file

@ -60,7 +60,8 @@ static void UIKit_DeleteDevice(SDL_VideoDevice *device)
} }
} }
static SDL_VideoDevice *UIKit_CreateDevice(void) static SDL_VideoDevice *
UIKit_CreateDevice(void)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoDevice *device; SDL_VideoDevice *device;
@ -126,7 +127,8 @@ static SDL_VideoDevice *UIKit_CreateDevice(void)
#if SDL_VIDEO_VULKAN #if SDL_VIDEO_VULKAN
device->Vulkan_LoadLibrary = UIKit_Vulkan_LoadLibrary; device->Vulkan_LoadLibrary = UIKit_Vulkan_LoadLibrary;
device->Vulkan_UnloadLibrary = UIKit_Vulkan_UnloadLibrary; device->Vulkan_UnloadLibrary = UIKit_Vulkan_UnloadLibrary;
device->Vulkan_GetInstanceExtensions = UIKit_Vulkan_GetInstanceExtensions; device->Vulkan_GetInstanceExtensions
= UIKit_Vulkan_GetInstanceExtensions;
device->Vulkan_CreateSurface = UIKit_Vulkan_CreateSurface; device->Vulkan_CreateSurface = UIKit_Vulkan_CreateSurface;
device->Vulkan_GetDrawableSize = UIKit_Vulkan_GetDrawableSize; device->Vulkan_GetDrawableSize = UIKit_Vulkan_GetDrawableSize;
#endif #endif
@ -149,7 +151,9 @@ VideoBootStrap UIKIT_bootstrap = {
UIKit_CreateDevice UIKit_CreateDevice
}; };
int UIKit_VideoInit(_THIS)
int
UIKit_VideoInit(_THIS)
{ {
_this->gl_config.driver_loaded = 1; _this->gl_config.driver_loaded = 1;
@ -163,7 +167,8 @@ int UIKit_VideoInit(_THIS)
return 0; return 0;
} }
void UIKit_VideoQuit(_THIS) void
UIKit_VideoQuit(_THIS)
{ {
SDL_QuitGCKeyboard(); SDL_QuitGCKeyboard();
SDL_QuitGCMouse(); SDL_QuitGCMouse();
@ -171,7 +176,8 @@ void UIKit_VideoQuit(_THIS)
UIKit_QuitModes(_this); UIKit_QuitModes(_this);
} }
void UIKit_SuspendScreenSaver(_THIS) void
UIKit_SuspendScreenSaver(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
/* Ignore ScreenSaver API calls if the idle timer hint has been set. */ /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
@ -229,7 +235,8 @@ UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
return frame; return frame;
} }
void UIKit_ForceUpdateHomeIndicator() void
UIKit_ForceUpdateHomeIndicator()
{ {
#if !TARGET_OS_TV #if !TARGET_OS_TV
/* Force the main SDL window to re-evaluate home indicator state */ /* Force the main SDL window to re-evaluate home indicator state */

View file

@ -42,8 +42,7 @@
extern int SDL_AppleTVRemoteOpenedAsJoystick; extern int SDL_AppleTVRemoteOpenedAsJoystick;
#endif #endif
@implementation SDL_uikitview @implementation SDL_uikitview {
{
SDL_Window *sdlwindow; SDL_Window *sdlwindow;
SDL_TouchID directTouchId; SDL_TouchID directTouchId;
@ -150,8 +149,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
} }
#if !TARGET_OS_TV && defined(__IPHONE_13_4) #if !TARGET_OS_TV && defined(__IPHONE_13_4)
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)) - (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)){
{
if (request != nil && !SDL_GCMouseRelativeMode()) { if (request != nil && !SDL_GCMouseRelativeMode()) {
CGPoint origin = self.bounds.origin; CGPoint origin = self.bounds.origin;
CGPoint point = request.location; CGPoint point = request.location;
@ -164,8 +162,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
return [UIPointerRegion regionWithRect:self.bounds identifier:nil]; return [UIPointerRegion regionWithRect:self.bounds identifier:nil];
} }
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)) - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)){
{
if (SDL_ShowCursor(-1)) { if (SDL_ShowCursor(-1)) {
return nil; return nil;
} else { } else {

View file

@ -36,7 +36,8 @@
#include "SDL_uikitopengles.h" #include "SDL_uikitopengles.h"
#if TARGET_OS_TV #if TARGET_OS_TV
static void SDLCALL SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint) static void SDLCALL
SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{ {
@autoreleasepool { @autoreleasepool {
SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata; SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
@ -46,7 +47,8 @@ static void SDLCALL SDL_AppleTVControllerUIHintChanged(void *userdata, const cha
#endif #endif
#if !TARGET_OS_TV #if !TARGET_OS_TV
static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint) static void SDLCALL
SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{ {
@autoreleasepool { @autoreleasepool {
SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata; SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
@ -62,8 +64,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
} }
#endif #endif
@implementation SDL_uikitviewcontroller @implementation SDL_uikitviewcontroller {
{
CADisplayLink *displayLink; CADisplayLink *displayLink;
int animationInterval; int animationInterval;
void (*animationCallback)(void*); void (*animationCallback)(void*);
@ -149,7 +150,9 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
#ifdef __IPHONE_10_3 #ifdef __IPHONE_10_3
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)] && data != nil && data.uiwindow != nil && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) { if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)]
&& data != nil && data.uiwindow != nil
&& [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval; displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
} else } else
#endif #endif
@ -274,16 +277,10 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
#if !TARGET_OS_TV #if !TARGET_OS_TV
[center addObserver:self [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
#endif #endif
[center addObserver:self [center addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
selector:@selector(textFieldTextDidChange:)
name:UITextFieldTextDidChangeNotification
object:nil];
} }
- (NSArray *)keyCommands - (NSArray *)keyCommands
@ -334,9 +331,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
{ {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
rotatingOrientation = YES; rotatingOrientation = YES;
[coordinator [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self->rotatingOrientation = NO; self->rotatingOrientation = NO;
}]; }];
@ -346,14 +341,10 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
{ {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
#if !TARGET_OS_TV #if !TARGET_OS_TV
[center removeObserver:self [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
name:UIKeyboardWillShowNotification
object:nil];
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil]; [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
#endif #endif
[center removeObserver:self [center removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
name:UITextFieldTextDidChangeNotification
object:nil];
} }
/* reveal onscreen virtual keyboard */ /* reveal onscreen virtual keyboard */
@ -497,7 +488,8 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
/* iPhone keyboard addition functions */ /* iPhone keyboard addition functions */
#if SDL_IPHONE_KEYBOARD #if SDL_IPHONE_KEYBOARD
static SDL_uikitviewcontroller *GetWindowViewController(SDL_Window *window) static SDL_uikitviewcontroller *
GetWindowViewController(SDL_Window * window)
{ {
if (!window || !window->driverdata) { if (!window || !window->driverdata) {
SDL_SetError("Invalid window"); SDL_SetError("Invalid window");
@ -515,7 +507,8 @@ UIKit_HasScreenKeyboardSupport(_THIS)
return SDL_TRUE; return SDL_TRUE;
} }
void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window) void
UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_uikitviewcontroller *vc = GetWindowViewController(window); SDL_uikitviewcontroller *vc = GetWindowViewController(window);
@ -523,7 +516,8 @@ void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
} }
} }
void UIKit_HideScreenKeyboard(_THIS, SDL_Window *window) void
UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_uikitviewcontroller *vc = GetWindowViewController(window); SDL_uikitviewcontroller *vc = GetWindowViewController(window);
@ -543,7 +537,8 @@ UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
} }
} }
void UIKit_SetTextInputRect(_THIS, const SDL_Rect *rect) void
UIKit_SetTextInputRect(_THIS, const SDL_Rect *rect)
{ {
if (!rect) { if (!rect) {
SDL_InvalidParamError("rect"); SDL_InvalidParamError("rect");
@ -562,6 +557,7 @@ void UIKit_SetTextInputRect(_THIS, const SDL_Rect *rect)
} }
} }
#endif /* SDL_IPHONE_KEYBOARD */ #endif /* SDL_IPHONE_KEYBOARD */
#endif /* SDL_VIDEO_DRIVER_UIKIT */ #endif /* SDL_VIDEO_DRIVER_UIKIT */

View file

@ -145,10 +145,13 @@ int UIKit_Vulkan_LoadLibrary(_THIS, const char *path)
SDL_free(extensions); SDL_free(extensions);
if (!hasSurfaceExtension) { if (!hasSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); SDL_SetError("Installed Vulkan Portability doesn't implement the "
VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail; goto fail;
} else if (!hasMetalSurfaceExtension && !hasIOSSurfaceExtension) { } else if (!hasMetalSurfaceExtension && !hasIOSSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability doesn't implement the " VK_EXT_METAL_SURFACE_EXTENSION_NAME " or " VK_MVK_IOS_SURFACE_EXTENSION_NAME " extensions"); SDL_SetError("Installed Vulkan Portability doesn't implement the "
VK_EXT_METAL_SURFACE_EXTENSION_NAME " or "
VK_MVK_IOS_SURFACE_EXTENSION_NAME " extensions");
goto fail; goto fail;
} }
@ -211,7 +214,8 @@ SDL_bool UIKit_Vulkan_CreateSurface(_THIS,
} }
if (!vkCreateMetalSurfaceEXT && !vkCreateIOSSurfaceMVK) { if (!vkCreateMetalSurfaceEXT && !vkCreateIOSSurfaceMVK) {
SDL_SetError(VK_EXT_METAL_SURFACE_EXTENSION_NAME " or " VK_MVK_IOS_SURFACE_EXTENSION_NAME SDL_SetError(VK_EXT_METAL_SURFACE_EXTENSION_NAME " or "
VK_MVK_IOS_SURFACE_EXTENSION_NAME
" extensions are not enabled in the Vulkan instance."); " extensions are not enabled in the Vulkan instance.");
return SDL_FALSE; return SDL_FALSE;
} }

View file

@ -83,7 +83,9 @@
@end @end
static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
static int
SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
{ {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata; SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
@ -156,7 +158,8 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
return 0; return 0;
} }
int UIKit_CreateWindow(_THIS, SDL_Window *window) int
UIKit_CreateWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -226,7 +229,8 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
return 1; return 1;
} }
void UIKit_SetWindowTitle(_THIS, SDL_Window *window) void
UIKit_SetWindowTitle(_THIS, SDL_Window * window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -234,7 +238,8 @@ void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
} }
} }
void UIKit_ShowWindow(_THIS, SDL_Window *window) void
UIKit_ShowWindow(_THIS, SDL_Window * window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -250,7 +255,8 @@ void UIKit_ShowWindow(_THIS, SDL_Window *window)
} }
} }
void UIKit_HideWindow(_THIS, SDL_Window *window) void
UIKit_HideWindow(_THIS, SDL_Window * window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -258,7 +264,8 @@ void UIKit_HideWindow(_THIS, SDL_Window *window)
} }
} }
void UIKit_RaiseWindow(_THIS, SDL_Window *window) void
UIKit_RaiseWindow(_THIS, SDL_Window * window)
{ {
/* We don't currently offer a concept of "raising" the SDL window, since /* We don't currently offer a concept of "raising" the SDL window, since
* we only allow one per display, in the iOS fashion. * we only allow one per display, in the iOS fashion.
@ -267,7 +274,8 @@ void UIKit_RaiseWindow(_THIS, SDL_Window *window)
_this->GL_MakeCurrent(_this, _this->current_glwin, _this->current_glctx); _this->GL_MakeCurrent(_this, _this->current_glwin, _this->current_glctx);
} }
static void UIKit_UpdateWindowBorder(_THIS, SDL_Window *window) static void
UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
{ {
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
SDL_uikitviewcontroller *viewcontroller = data.viewcontroller; SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
@ -296,26 +304,30 @@ static void UIKit_UpdateWindowBorder(_THIS, SDL_Window *window)
[viewcontroller.view layoutIfNeeded]; [viewcontroller.view layoutIfNeeded];
} }
void UIKit_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered) void
UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{ {
@autoreleasepool { @autoreleasepool {
UIKit_UpdateWindowBorder(_this, window); UIKit_UpdateWindowBorder(_this, window);
} }
} }
void UIKit_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) void
UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{ {
@autoreleasepool { @autoreleasepool {
UIKit_UpdateWindowBorder(_this, window); UIKit_UpdateWindowBorder(_this, window);
} }
} }
void UIKit_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void
UIKit_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{ {
/* There really isn't a concept of window grab or cursor confinement on iOS */ /* There really isn't a concept of window grab or cursor confinement on iOS */
} }
void UIKit_UpdatePointerLock(_THIS, SDL_Window *window) void
UIKit_UpdatePointerLock(_THIS, SDL_Window * window)
{ {
#if !TARGET_OS_TV #if !TARGET_OS_TV
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
@ -330,7 +342,8 @@ void UIKit_UpdatePointerLock(_THIS, SDL_Window *window)
#endif /* !TARGET_OS_TV */ #endif /* !TARGET_OS_TV */
} }
void UIKit_DestroyWindow(_THIS, SDL_Window *window) void
UIKit_DestroyWindow(_THIS, SDL_Window * window)
{ {
@autoreleasepool { @autoreleasepool {
if (window->driverdata != NULL) { if (window->driverdata != NULL) {
@ -358,9 +371,10 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
window->driverdata = NULL; window->driverdata = NULL;
} }
void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) void
UIKit_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h)
{ @autoreleasepool
{ {
@autoreleasepool {
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata; SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
UIView *view = windata.viewcontroller.view; UIView *view = windata.viewcontroller.view;
CGSize size = view.bounds.size; CGSize size = view.bounds.size;
@ -370,13 +384,6 @@ void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h)
scale = windata.uiwindow.screen.nativeScale; scale = windata.uiwindow.screen.nativeScale;
} }
/* Integer truncation of fractional values matches SDL_uikitmetalview and
* SDL_uikitopenglview. */
*w = size.width * scale;
*h = size.height * scale;
}
}
/* Integer truncation of fractional values matches SDL_uikitmetalview and /* Integer truncation of fractional values matches SDL_uikitmetalview and
* SDL_uikitopenglview. */ * SDL_uikitopenglview. */
*w = size.width * scale; *w = size.width * scale;
@ -490,7 +497,8 @@ UIKit_GetSupportedOrientations(SDL_Window *window)
} }
#endif /* !TARGET_OS_TV */ #endif /* !TARGET_OS_TV */
int SDL_iPhoneSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam) int
SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
{ {
if (!window || !window->driverdata) { if (!window || !window->driverdata) {
return SDL_SetError("Invalid window"); return SDL_SetError("Invalid window");