mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-03-24 04:45:12 +00:00
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:
parent
9e997cc787
commit
7b1000013e
|
@ -159,7 +159,8 @@ typedef struct METAL_ShaderPipelines
|
|||
@implementation METAL_TextureData
|
||||
@end
|
||||
|
||||
static int IsMetalAvailable(const SDL_SysWMinfo *syswm)
|
||||
static int
|
||||
IsMetalAvailable(const SDL_SysWMinfo *syswm)
|
||||
{
|
||||
if (syswm->subsystem != SDL_SYSWM_COCOA && syswm->subsystem != SDL_SYSWM_UIKIT) {
|
||||
return SDL_SetError("Metal render target only supports Cocoa and UIKit video targets at the moment.");
|
||||
|
@ -178,83 +179,62 @@ static int IsMetalAvailable(const SDL_SysWMinfo *syswm)
|
|||
static const MTLBlendOperation invalidBlendOperation = (MTLBlendOperation)0xFFFFFFFF;
|
||||
static const MTLBlendFactor invalidBlendFactor = (MTLBlendFactor)0xFFFFFFFF;
|
||||
|
||||
static MTLBlendOperation GetBlendOperation(SDL_BlendOperation operation)
|
||||
static MTLBlendOperation
|
||||
GetBlendOperation(SDL_BlendOperation operation)
|
||||
{
|
||||
switch (operation) {
|
||||
case SDL_BLENDOPERATION_ADD:
|
||||
return MTLBlendOperationAdd;
|
||||
case SDL_BLENDOPERATION_SUBTRACT:
|
||||
return MTLBlendOperationSubtract;
|
||||
case SDL_BLENDOPERATION_REV_SUBTRACT:
|
||||
return MTLBlendOperationReverseSubtract;
|
||||
case SDL_BLENDOPERATION_MINIMUM:
|
||||
return MTLBlendOperationMin;
|
||||
case SDL_BLENDOPERATION_MAXIMUM:
|
||||
return MTLBlendOperationMax;
|
||||
default:
|
||||
return invalidBlendOperation;
|
||||
case SDL_BLENDOPERATION_ADD: return MTLBlendOperationAdd;
|
||||
case SDL_BLENDOPERATION_SUBTRACT: return MTLBlendOperationSubtract;
|
||||
case SDL_BLENDOPERATION_REV_SUBTRACT: return MTLBlendOperationReverseSubtract;
|
||||
case SDL_BLENDOPERATION_MINIMUM: return MTLBlendOperationMin;
|
||||
case SDL_BLENDOPERATION_MAXIMUM: return MTLBlendOperationMax;
|
||||
default: return invalidBlendOperation;
|
||||
}
|
||||
}
|
||||
|
||||
static MTLBlendFactor GetBlendFactor(SDL_BlendFactor factor)
|
||||
static MTLBlendFactor
|
||||
GetBlendFactor(SDL_BlendFactor factor)
|
||||
{
|
||||
switch (factor) {
|
||||
case SDL_BLENDFACTOR_ZERO:
|
||||
return MTLBlendFactorZero;
|
||||
case SDL_BLENDFACTOR_ONE:
|
||||
return MTLBlendFactorOne;
|
||||
case SDL_BLENDFACTOR_SRC_COLOR:
|
||||
return MTLBlendFactorSourceColor;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
|
||||
return MTLBlendFactorOneMinusSourceColor;
|
||||
case SDL_BLENDFACTOR_SRC_ALPHA:
|
||||
return MTLBlendFactorSourceAlpha;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
|
||||
return MTLBlendFactorOneMinusSourceAlpha;
|
||||
case SDL_BLENDFACTOR_DST_COLOR:
|
||||
return MTLBlendFactorDestinationColor;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
|
||||
return MTLBlendFactorOneMinusDestinationColor;
|
||||
case SDL_BLENDFACTOR_DST_ALPHA:
|
||||
return MTLBlendFactorDestinationAlpha;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
|
||||
return MTLBlendFactorOneMinusDestinationAlpha;
|
||||
default:
|
||||
return invalidBlendFactor;
|
||||
case SDL_BLENDFACTOR_ZERO: return MTLBlendFactorZero;
|
||||
case SDL_BLENDFACTOR_ONE: return MTLBlendFactorOne;
|
||||
case SDL_BLENDFACTOR_SRC_COLOR: return MTLBlendFactorSourceColor;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return MTLBlendFactorOneMinusSourceColor;
|
||||
case SDL_BLENDFACTOR_SRC_ALPHA: return MTLBlendFactorSourceAlpha;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return MTLBlendFactorOneMinusSourceAlpha;
|
||||
case SDL_BLENDFACTOR_DST_COLOR: return MTLBlendFactorDestinationColor;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR: return MTLBlendFactorOneMinusDestinationColor;
|
||||
case SDL_BLENDFACTOR_DST_ALPHA: return MTLBlendFactorDestinationAlpha;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return MTLBlendFactorOneMinusDestinationAlpha;
|
||||
default: return invalidBlendFactor;
|
||||
}
|
||||
}
|
||||
|
||||
static NSString *GetVertexFunctionName(SDL_MetalVertexFunction function)
|
||||
static NSString *
|
||||
GetVertexFunctionName(SDL_MetalVertexFunction function)
|
||||
{
|
||||
switch (function) {
|
||||
case SDL_METAL_VERTEX_SOLID:
|
||||
return @"SDL_Solid_vertex";
|
||||
case SDL_METAL_VERTEX_COPY:
|
||||
return @"SDL_Copy_vertex";
|
||||
default:
|
||||
return nil;
|
||||
case SDL_METAL_VERTEX_SOLID: return @"SDL_Solid_vertex";
|
||||
case SDL_METAL_VERTEX_COPY: return @"SDL_Copy_vertex";
|
||||
default: return nil;
|
||||
}
|
||||
}
|
||||
|
||||
static NSString *GetFragmentFunctionName(SDL_MetalFragmentFunction function)
|
||||
static NSString *
|
||||
GetFragmentFunctionName(SDL_MetalFragmentFunction function)
|
||||
{
|
||||
switch (function) {
|
||||
case SDL_METAL_FRAGMENT_SOLID:
|
||||
return @"SDL_Solid_fragment";
|
||||
case SDL_METAL_FRAGMENT_COPY:
|
||||
return @"SDL_Copy_fragment";
|
||||
case SDL_METAL_FRAGMENT_YUV:
|
||||
return @"SDL_YUV_fragment";
|
||||
case SDL_METAL_FRAGMENT_NV12:
|
||||
return @"SDL_NV12_fragment";
|
||||
case SDL_METAL_FRAGMENT_NV21:
|
||||
return @"SDL_NV21_fragment";
|
||||
default:
|
||||
return nil;
|
||||
case SDL_METAL_FRAGMENT_SOLID: return @"SDL_Solid_fragment";
|
||||
case SDL_METAL_FRAGMENT_COPY: return @"SDL_Copy_fragment";
|
||||
case SDL_METAL_FRAGMENT_YUV: return @"SDL_YUV_fragment";
|
||||
case SDL_METAL_FRAGMENT_NV12: return @"SDL_NV12_fragment";
|
||||
case SDL_METAL_FRAGMENT_NV21: return @"SDL_NV21_fragment";
|
||||
default: return nil;
|
||||
}
|
||||
}
|
||||
|
||||
static id<MTLRenderPipelineState> MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
|
||||
static id<MTLRenderPipelineState>
|
||||
MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
|
||||
NSString *blendlabel, SDL_BlendMode blendmode)
|
||||
{
|
||||
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)
|
||||
{
|
||||
SDL_zerop(cache);
|
||||
|
@ -367,7 +348,8 @@ static void MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache
|
|||
MakePipelineState(data, cache, @" (blend=mul)", SDL_BLENDMODE_MUL);
|
||||
}
|
||||
|
||||
static void DestroyPipelineCache(METAL_PipelineCache *cache)
|
||||
static void
|
||||
DestroyPipelineCache(METAL_PipelineCache *cache)
|
||||
{
|
||||
if (cache != NULL) {
|
||||
for (int i = 0; i < cache->count; i++) {
|
||||
|
@ -378,7 +360,8 @@ static void DestroyPipelineCache(METAL_PipelineCache *cache)
|
|||
}
|
||||
}
|
||||
|
||||
void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat)
|
||||
void
|
||||
MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat)
|
||||
{
|
||||
SDL_zerop(pipelines);
|
||||
|
||||
|
@ -391,7 +374,8 @@ void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipeline
|
|||
MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_NV21], "SDL NV21 pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_NV21);
|
||||
}
|
||||
|
||||
static METAL_ShaderPipelines *ChooseShaderPipelines(METAL_RenderData *data, MTLPixelFormat rtformat)
|
||||
static METAL_ShaderPipelines *
|
||||
ChooseShaderPipelines(METAL_RenderData *data, MTLPixelFormat rtformat)
|
||||
{
|
||||
METAL_ShaderPipelines *allpipelines = data.allpipelines;
|
||||
int count = data.pipelinescount;
|
||||
|
@ -417,7 +401,8 @@ static METAL_ShaderPipelines *ChooseShaderPipelines(METAL_RenderData *data, MTLP
|
|||
return &data.allpipelines[count];
|
||||
}
|
||||
|
||||
static void DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
|
||||
static void
|
||||
DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
|
||||
{
|
||||
if (allpipelines != NULL) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
@ -430,7 +415,8 @@ static void DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
|
|||
}
|
||||
}
|
||||
|
||||
static inline id<MTLRenderPipelineState> ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SDL_MetalFragmentFunction fragfn, SDL_BlendMode blendmode)
|
||||
static inline id<MTLRenderPipelineState>
|
||||
ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SDL_MetalFragmentFunction fragfn, SDL_BlendMode blendmode)
|
||||
{
|
||||
METAL_PipelineCache *cache = &pipelines->caches[fragfn];
|
||||
|
||||
|
@ -443,7 +429,8 @@ static inline id<MTLRenderPipelineState> ChoosePipelineState(METAL_RenderData *d
|
|||
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;
|
||||
|
||||
|
@ -510,13 +497,14 @@ static SDL_bool METAL_ActivateRenderCommandEncoder(SDL_Renderer *renderer, MTLLo
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static void METAL_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
|
||||
static void
|
||||
METAL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
|
||||
{
|
||||
}
|
||||
|
||||
static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static int
|
||||
METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
if (w) {
|
||||
*w = (int)data.mtllayer.drawableSize.width;
|
||||
|
@ -525,10 +513,10 @@ static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
|||
*h = (int)data.mtllayer.drawableSize.height;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static SDL_bool METAL_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
|
||||
static SDL_bool
|
||||
METAL_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
|
||||
{
|
||||
SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
|
||||
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
|
||||
|
@ -548,9 +536,9 @@ static SDL_bool METAL_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode bl
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static int
|
||||
METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
MTLPixelFormat pixfmt;
|
||||
MTLTextureDescriptor *mtltexdesc;
|
||||
|
@ -576,9 +564,7 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
}
|
||||
|
||||
mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixfmt
|
||||
width:(NSUInteger)texture->w
|
||||
height:(NSUInteger)texture->h
|
||||
mipmapped:NO];
|
||||
width:(NSUInteger)texture->w height:(NSUInteger)texture->h mipmapped:NO];
|
||||
|
||||
/* Not available in iOS 8. */
|
||||
if ([mtltexdesc respondsToSelector:@selector(usage)]) {
|
||||
|
@ -646,18 +632,10 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
size_t offset = 0;
|
||||
SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h);
|
||||
switch (mode) {
|
||||
case SDL_YUV_CONVERSION_JPEG:
|
||||
offset = CONSTANTS_OFFSET_DECODE_JPEG;
|
||||
break;
|
||||
case SDL_YUV_CONVERSION_BT601:
|
||||
offset = CONSTANTS_OFFSET_DECODE_BT601;
|
||||
break;
|
||||
case SDL_YUV_CONVERSION_BT709:
|
||||
offset = CONSTANTS_OFFSET_DECODE_BT709;
|
||||
break;
|
||||
default:
|
||||
offset = 0;
|
||||
break;
|
||||
case SDL_YUV_CONVERSION_JPEG: offset = CONSTANTS_OFFSET_DECODE_JPEG; break;
|
||||
case SDL_YUV_CONVERSION_BT601: offset = CONSTANTS_OFFSET_DECODE_BT601; break;
|
||||
case SDL_YUV_CONVERSION_BT709: offset = CONSTANTS_OFFSET_DECODE_BT709; break;
|
||||
default: offset = 0; break;
|
||||
}
|
||||
texturedata.conversionBufferOffset = offset;
|
||||
}
|
||||
|
@ -665,10 +643,10 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
texture->driverdata = (void*)CFBridgingRetain(texturedata);
|
||||
|
||||
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)
|
||||
{
|
||||
[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];
|
||||
}
|
||||
|
||||
static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource)
|
||||
static MTLStorageMode
|
||||
METAL_GetStorageMode(id<MTLResource> resource)
|
||||
{
|
||||
/* iOS 8 does not have this method. */
|
||||
if ([resource respondsToSelector:@selector(storageMode)]) {
|
||||
|
@ -688,7 +667,8 @@ static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource)
|
|||
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,
|
||||
const void * pixels, int pitch)
|
||||
{
|
||||
|
@ -756,10 +736,10 @@ static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, METAL_TextureData
|
|||
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)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
|
||||
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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#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 Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *Uplane, int Upitch,
|
||||
const Uint8 *Vplane, int Vpitch)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
const int Uslice = 0;
|
||||
const int Vslice = 1;
|
||||
|
@ -833,15 +812,14 @@ static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
texturedata.hasdata = YES;
|
||||
|
||||
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 Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *UVplane, int UVpitch)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
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};
|
||||
|
||||
|
@ -861,14 +839,13 @@ static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
texturedata.hasdata = YES;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
#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)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
int buffersize = 0;
|
||||
|
@ -898,12 +875,11 @@ static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||
*pixels = [lockedbuffer contents];
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static void
|
||||
METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
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.hasdata = YES;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void METAL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static void
|
||||
METAL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
|
||||
|
@ -997,12 +972,11 @@ static void METAL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu
|
|||
} else {
|
||||
texturedata.mtlsampler = data.mtlsamplerlinear;
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static int
|
||||
METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
|
||||
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,
|
||||
* which are only available when beginning a new render pass. */
|
||||
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 */
|
||||
const int w = cmd->data.viewport.rect.w;
|
||||
|
@ -1046,7 +1021,8 @@ static int METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd
|
|||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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 = {
|
||||
cmd->data.draw.r,
|
||||
|
@ -1088,7 +1065,8 @@ static int METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
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 = {
|
||||
cmd->data.draw.r,
|
||||
|
@ -1141,7 +1119,8 @@ static int METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
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,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
|
@ -1202,7 +1181,8 @@ typedef struct
|
|||
size_t color_offset;
|
||||
} 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static int
|
||||
METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
id<MTLBuffer> mtlbufvertex = nil;
|
||||
METAL_DrawStateCache statecache;
|
||||
|
@ -1356,8 +1337,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
|
||||
while (cmd) {
|
||||
switch (cmd->command) {
|
||||
case SDL_RENDERCMD_SETVIEWPORT:
|
||||
{
|
||||
case SDL_RENDERCMD_SETVIEWPORT: {
|
||||
SDL_memcpy(&statecache.viewport, &cmd->data.viewport.rect, sizeof (statecache.viewport));
|
||||
statecache.projection_offset = cmd->data.viewport.first;
|
||||
statecache.viewport_dirty = SDL_TRUE;
|
||||
|
@ -1365,23 +1345,20 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_SETCLIPRECT:
|
||||
{
|
||||
case SDL_RENDERCMD_SETCLIPRECT: {
|
||||
SDL_memcpy(&statecache.cliprect, &cmd->data.cliprect.rect, sizeof (statecache.cliprect));
|
||||
statecache.cliprect_enabled = cmd->data.cliprect.enabled;
|
||||
statecache.cliprect_dirty = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_SETDRAWCOLOR:
|
||||
{
|
||||
case SDL_RENDERCMD_SETDRAWCOLOR: {
|
||||
statecache.color_offset = cmd->data.color.first;
|
||||
statecache.color_dirty = SDL_TRUE;
|
||||
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
|
||||
clear all its work anyhow, and starting a new encoder will let us use a hardware clear
|
||||
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_LINES:
|
||||
{
|
||||
case SDL_RENDERCMD_DRAW_LINES: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
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)) {
|
||||
|
@ -1436,8 +1412,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY:
|
||||
{
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
|
||||
|
@ -1460,13 +1435,12 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
id<MTLTexture> mtltexture;
|
||||
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);
|
||||
SDL_free(temp_pixels);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static int METAL_RenderPresent(SDL_Renderer *renderer)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static int
|
||||
METAL_RenderPresent(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
SDL_bool ready = SDL_TRUE;
|
||||
|
||||
|
@ -1553,20 +1526,18 @@ static int METAL_RenderPresent(SDL_Renderer *renderer)
|
|||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void METAL_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static void
|
||||
METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{ @autoreleasepool {
|
||||
CFBridgingRelease(texture->driverdata);
|
||||
texture->driverdata = NULL;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void METAL_DestroyRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static void
|
||||
METAL_DestroyRenderer(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
if (renderer->driverdata) {
|
||||
METAL_RenderData *data = CFBridgingRelease(renderer->driverdata);
|
||||
|
||||
|
@ -1584,20 +1555,18 @@ static void METAL_DestroyRenderer(SDL_Renderer *renderer)
|
|||
}
|
||||
|
||||
SDL_free(renderer);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void *METAL_GetMetalLayer(SDL_Renderer *renderer)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static void *
|
||||
METAL_GetMetalLayer(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
return (__bridge void*)data.mtllayer;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void *METAL_GetMetalCommandEncoder(SDL_Renderer *renderer)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static void *
|
||||
METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
// 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
|
||||
// usable for presentation. Check your return values!
|
||||
|
@ -1605,10 +1574,10 @@ static void *METAL_GetMetalCommandEncoder(SDL_Renderer *renderer)
|
|||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
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 (@available(macOS 10.13, *)) {
|
||||
|
@ -1654,9 +1623,9 @@ static SDL_MetalView GetWindowView(SDL_Window *window)
|
|||
return nil;
|
||||
}
|
||||
|
||||
static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
@autoreleasepool {
|
||||
static SDL_Renderer *
|
||||
METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{ @autoreleasepool {
|
||||
SDL_Renderer *renderer = NULL;
|
||||
METAL_RenderData *data = NULL;
|
||||
id<MTLDevice> mtldevice = nil;
|
||||
|
@ -1679,41 +1648,17 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
|
||||
/* Note: matrices are column major. */
|
||||
float identitytransform[16] = {
|
||||
1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.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,
|
||||
1.0f, 0.0f, 0.0f, 0.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] = {
|
||||
1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.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,
|
||||
1.0f, 0.0f, 0.0f, 0.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. */
|
||||
|
@ -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
|
||||
// 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];
|
||||
data.mtllibrary = mtllibrary;
|
||||
SDL_assert(err == nil);
|
||||
|
@ -1918,6 +1862,11 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
if (data.mtllayer.displaySyncEnabled) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
/* https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf */
|
||||
maxtexsize = 4096;
|
||||
|
@ -1957,8 +1906,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
renderer->info.max_texture_height = maxtexsize;
|
||||
|
||||
return renderer;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
SDL_RenderDriver METAL_RenderDriver = {
|
||||
METAL_CreateRenderer,
|
||||
|
@ -1966,14 +1914,15 @@ SDL_RenderDriver METAL_RenderDriver = {
|
|||
"metal",
|
||||
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
|
||||
6,
|
||||
{ SDL_PIXELFORMAT_ARGB8888,
|
||||
{
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_PIXELFORMAT_ABGR8888,
|
||||
SDL_PIXELFORMAT_YV12,
|
||||
SDL_PIXELFORMAT_IYUV,
|
||||
SDL_PIXELFORMAT_NV12,
|
||||
SDL_PIXELFORMAT_NV21 },
|
||||
0,
|
||||
0,
|
||||
SDL_PIXELFORMAT_NV21
|
||||
},
|
||||
0, 0,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,9 +25,10 @@
|
|||
#include "SDL_cocoavideo.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;
|
||||
NSPasteboard *pasteboard;
|
||||
NSString *format = NSPasteboardTypeString;
|
||||
|
@ -41,13 +42,12 @@ int Cocoa_SetClipboardText(_THIS, const char *text)
|
|||
[pasteboard setString:nsstr forType:format];
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
char *
|
||||
Cocoa_GetClipboardText(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSPasteboard *pasteboard;
|
||||
NSString *format = NSPasteboardTypeString;
|
||||
NSString *available;
|
||||
|
@ -71,8 +71,7 @@ Cocoa_GetClipboardText(_THIS)
|
|||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
SDL_bool
|
||||
Cocoa_HasClipboardText(_THIS)
|
||||
|
@ -86,9 +85,10 @@ Cocoa_HasClipboardText(_THIS)
|
|||
return result;
|
||||
}
|
||||
|
||||
void Cocoa_CheckClipboardUpdate(SDL_VideoData *data)
|
||||
void
|
||||
Cocoa_CheckClipboardUpdate(SDL_VideoData * data)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSPasteboard *pasteboard;
|
||||
NSInteger count;
|
||||
|
||||
|
@ -100,8 +100,7 @@ void Cocoa_CheckClipboardUpdate(SDL_VideoData *data)
|
|||
}
|
||||
data.clipboard_count = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
||||
|
|
|
@ -130,8 +130,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
|||
- (void)setAppleMenu:(NSMenu *)menu;
|
||||
@end
|
||||
|
||||
@interface SDLAppDelegate : NSObject <NSApplicationDelegate>
|
||||
{
|
||||
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
|
||||
@public
|
||||
BOOL seenFirstActivate;
|
||||
}
|
||||
|
@ -313,7 +312,8 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
|||
|
||||
static SDLAppDelegate *appDelegate = nil;
|
||||
|
||||
static NSString *GetApplicationName(void)
|
||||
static NSString *
|
||||
GetApplicationName(void)
|
||||
{
|
||||
NSString *appName;
|
||||
|
||||
|
@ -330,7 +330,8 @@ static NSString *GetApplicationName(void)
|
|||
return appName;
|
||||
}
|
||||
|
||||
static bool LoadMainMenuNibIfAvailable(void)
|
||||
static bool
|
||||
LoadMainMenuNibIfAvailable(void)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
|
||||
NSDictionary *infoDict;
|
||||
|
@ -355,7 +356,8 @@ static bool LoadMainMenuNibIfAvailable(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void CreateApplicationMenus(void)
|
||||
static void
|
||||
CreateApplicationMenus(void)
|
||||
{
|
||||
NSString *appName;
|
||||
NSString *title;
|
||||
|
@ -444,9 +446,10 @@ static void CreateApplicationMenus(void)
|
|||
[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! */
|
||||
|
||||
if (NSApp == nil) {
|
||||
|
@ -500,10 +503,10 @@ void Cocoa_RegisterApp(void)
|
|||
appDelegate->seenFirstActivate = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
int Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
|
||||
int
|
||||
Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
|
||||
{
|
||||
for ( ; ; ) {
|
||||
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;
|
||||
}
|
||||
|
||||
int Cocoa_WaitEventTimeout(_THIS, int timeout)
|
||||
int
|
||||
Cocoa_WaitEventTimeout(_THIS, int timeout)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (timeout > 0) {
|
||||
NSDate *limitDate = [NSDate dateWithTimeIntervalSinceNow: (double) timeout / 1000.0];
|
||||
return Cocoa_PumpEventsUntilDate(_this, limitDate, false);
|
||||
|
@ -537,19 +541,18 @@ int Cocoa_WaitEventTimeout(_THIS, int timeout)
|
|||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_PumpEvents(_THIS)
|
||||
void
|
||||
Cocoa_PumpEvents(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
Cocoa_PumpEventsUntilDate(_this, [NSDate distantPast], true);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
|
||||
location: NSMakePoint(0,0)
|
||||
modifierFlags: 0
|
||||
|
@ -561,12 +564,12 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
|
|||
data2: 0];
|
||||
|
||||
[NSApp postEvent: event atStart: YES];
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_SuspendScreenSaver(_THIS)
|
||||
void
|
||||
Cocoa_SuspendScreenSaver(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata;
|
||||
|
||||
if (data.screensaver_assertion) {
|
||||
|
@ -588,7 +591,7 @@ void Cocoa_SuspendScreenSaver(_THIS)
|
|||
&assertion);
|
||||
data.screensaver_assertion = assertion;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
/*#define DEBUG_IME NSLog */
|
||||
#define DEBUG_IME(...)
|
||||
|
||||
@interface SDLTranslatorResponder : NSView <NSTextInputClient>
|
||||
{
|
||||
@interface SDLTranslatorResponder : NSView <NSTextInputClient> {
|
||||
NSString *_markedText;
|
||||
NSRange _markedRange;
|
||||
NSRange _selectedRange;
|
||||
|
@ -183,7 +182,8 @@
|
|||
|
||||
@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];
|
||||
|
||||
|
@ -199,8 +199,7 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
|
|||
SDL_SCANCODE_LSHIFT,
|
||||
SDL_SCANCODE_LCTRL,
|
||||
SDL_SCANCODE_LALT,
|
||||
SDL_SCANCODE_LGUI,
|
||||
};
|
||||
SDL_SCANCODE_LGUI, };
|
||||
|
||||
const unsigned int modifiers[] = {
|
||||
NX_DEVICELSHIFTKEYMASK,
|
||||
|
@ -214,11 +213,12 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
|
|||
NX_SHIFTMASK,
|
||||
NX_CONTROLMASK,
|
||||
NX_ALTERNATEMASK,
|
||||
NX_COMMANDMASK
|
||||
};
|
||||
NX_COMMANDMASK };
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (code == codes[i]) {
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
if (code == codes[i])
|
||||
{
|
||||
if (modifierFlags & modifiers[i])
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, code);
|
||||
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;
|
||||
const void *chr_data;
|
||||
|
@ -291,7 +292,8 @@ cleanup:
|
|||
CFRelease(key_layout);
|
||||
}
|
||||
|
||||
void Cocoa_InitKeyboard(_THIS)
|
||||
void
|
||||
Cocoa_InitKeyboard(_THIS)
|
||||
{
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
|
||||
|
@ -309,9 +311,10 @@ void Cocoa_InitKeyboard(_THIS)
|
|||
SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) != 0);
|
||||
}
|
||||
|
||||
void Cocoa_StartTextInput(_THIS)
|
||||
void
|
||||
Cocoa_StartTextInput(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSView *parentView;
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||
|
@ -338,22 +341,22 @@ void Cocoa_StartTextInput(_THIS)
|
|||
[parentView addSubview: data.fieldEdit];
|
||||
[nswindow makeFirstResponder: data.fieldEdit];
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_StopTextInput(_THIS)
|
||||
void
|
||||
Cocoa_StopTextInput(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
|
||||
if (data && data.fieldEdit) {
|
||||
[data.fieldEdit removeFromSuperview];
|
||||
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;
|
||||
|
||||
|
@ -365,7 +368,8 @@ void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect)
|
|||
[data.fieldEdit setInputRect:rect];
|
||||
}
|
||||
|
||||
void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
|
||||
void
|
||||
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
|
||||
{
|
||||
unsigned short scancode;
|
||||
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 enum
|
||||
{
|
||||
typedef enum {
|
||||
CGSGlobalHotKeyEnable = 0,
|
||||
CGSGlobalHotKeyDisable = 1,
|
||||
} CGSGlobalHotKeyOperatingMode;
|
||||
|
@ -441,7 +445,8 @@ typedef enum
|
|||
extern CGSConnection _CGSDefaultConnection(void);
|
||||
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
|
||||
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), grabbed ? CGSGlobalHotKeyDisable : CGSGlobalHotKeyEnable);
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
#include "SDL_messagebox.h"
|
||||
#include "SDL_cocoavideo.h"
|
||||
|
||||
@interface SDLMessageBoxPresenter : NSObject
|
||||
{
|
||||
@interface SDLMessageBoxPresenter : NSObject {
|
||||
@public
|
||||
NSInteger clicked;
|
||||
NSWindow *nswindow;
|
||||
|
@ -60,18 +59,14 @@
|
|||
if (nswindow) {
|
||||
#ifdef MAC_OS_X_VERSION_10_9
|
||||
if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
|
||||
[alert beginSheetModalForWindow:nswindow
|
||||
completionHandler:^(NSModalResponse returnCode) {
|
||||
[alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
|
||||
self->clicked = returnCode;
|
||||
}];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
|
||||
[alert beginSheetModalForWindow:nswindow
|
||||
modalDelegate:self
|
||||
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
|
||||
contextInfo:nil];
|
||||
[alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -93,7 +88,9 @@
|
|||
|
||||
@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;
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
|
@ -153,21 +150,19 @@ static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, i
|
|||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
if ([NSThread isMainThread]) {
|
||||
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
|
||||
});
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{ Cocoa_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue); });
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
|
||||
|
||||
@interface SDL_cocoametalview : NSView
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frame
|
||||
|
@ -66,3 +67,4 @@ void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h);
|
|||
#endif /* SDL_cocoametalview_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
|
|
@ -33,7 +33,9 @@
|
|||
#include "SDL_events.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
|
||||
* 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);
|
||||
}
|
||||
|
||||
- (NSView *)hitTest:(NSPoint)point
|
||||
{
|
||||
- (NSView *)hitTest:(NSPoint)point {
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -131,8 +132,7 @@ static int SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
|
|||
|
||||
SDL_MetalView
|
||||
Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
|
||||
NSView *view = data.nswindow.contentView;
|
||||
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);
|
||||
|
||||
return metalview;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
|
||||
{
|
||||
@autoreleasepool {
|
||||
void
|
||||
Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
|
||||
{ @autoreleasepool {
|
||||
SDL_cocoametalview *metalview = CFBridgingRelease(view);
|
||||
[metalview removeFromSuperview];
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void *
|
||||
Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
SDL_cocoametalview *cocoaview = (__bridge SDL_cocoametalview *)view;
|
||||
return (__bridge void *)cocoaview.layer;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
|
||||
{
|
||||
@autoreleasepool {
|
||||
void
|
||||
Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
||||
{ @autoreleasepool {
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
||||
NSView *contentView = data.sdlContentView;
|
||||
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. */
|
||||
SDL_GetWindowSizeInPixels(window, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */
|
||||
|
||||
|
|
|
@ -41,7 +41,9 @@
|
|||
#define kDisplayModeNativeFlag 0x02000000
|
||||
#endif
|
||||
|
||||
static int CG_SetError(const char *prefix, CGDisplayErr result)
|
||||
|
||||
static int
|
||||
CG_SetError(const char *prefix, CGDisplayErr result)
|
||||
{
|
||||
const char *error;
|
||||
|
||||
|
@ -83,7 +85,8 @@ static int CG_SetError(const char *prefix, CGDisplayErr result)
|
|||
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);
|
||||
|
||||
|
@ -98,7 +101,8 @@ static int GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef
|
|||
return refreshRate;
|
||||
}
|
||||
|
||||
static SDL_bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
|
||||
static SDL_bool
|
||||
HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
|
||||
{
|
||||
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
|
||||
|
||||
|
@ -115,7 +119,8 @@ static SDL_bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
|
|||
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). */
|
||||
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
||||
|
@ -139,7 +144,8 @@ static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
|
|||
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;
|
||||
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
|
||||
* 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);
|
||||
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
|
||||
* 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);
|
||||
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
|
||||
* 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);
|
||||
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
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +283,8 @@ static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmode
|
|||
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). */
|
||||
io_service_t servicePort = CGDisplayIOServicePort(displayID);
|
||||
|
@ -282,9 +299,10 @@ static const char *Cocoa_GetDisplayName(CGDirectDisplayID displayID)
|
|||
return displayName;
|
||||
}
|
||||
|
||||
void Cocoa_InitModes(_THIS)
|
||||
void
|
||||
Cocoa_InitModes(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
CGDisplayErr result;
|
||||
CGDirectDisplayID *displays;
|
||||
CGDisplayCount numDisplays;
|
||||
|
@ -364,10 +382,10 @@ void Cocoa_InitModes(_THIS)
|
|||
}
|
||||
}
|
||||
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;
|
||||
CGRect cgrect;
|
||||
|
@ -380,7 +398,8 @@ int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
|||
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;
|
||||
const CGDirectDisplayID cgdisplay = displaydata->display;
|
||||
|
@ -412,9 +431,10 @@ int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
|
|||
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;
|
||||
|
||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||
|
@ -488,10 +508,10 @@ int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hd
|
|||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
|
||||
void
|
||||
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||
{
|
||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||
CVDisplayLinkRef link = NULL;
|
||||
|
@ -571,7 +591,8 @@ void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
|
|||
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
|
||||
* identical properties), some of which might not work. See GetDisplayMode.
|
||||
|
@ -589,7 +610,8 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
|
|||
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_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
|
||||
|
@ -654,7 +676,8 @@ ERR_NO_CAPTURE:
|
|||
return -1;
|
||||
}
|
||||
|
||||
void Cocoa_QuitModes(_THIS)
|
||||
void
|
||||
Cocoa_QuitModes(_THIS)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event);
|
|||
extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
|
||||
extern void Cocoa_QuitMouse(_THIS);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
/* Whether we've seen a cursor warp since the last move event. */
|
||||
SDL_bool seenWarp;
|
||||
/* What location our last cursor warp was to. */
|
||||
|
|
|
@ -33,9 +33,7 @@
|
|||
#ifdef DEBUG_COCOAMOUSE
|
||||
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DLog(...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#define DLog(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
@implementation NSCursor (InvisibleCursor)
|
||||
|
@ -64,9 +62,11 @@
|
|||
}
|
||||
@end
|
||||
|
||||
static SDL_Cursor *Cocoa_CreateDefaultCursor()
|
||||
|
||||
static SDL_Cursor *
|
||||
Cocoa_CreateDefaultCursor()
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSCursor *nscursor;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
|
||||
|
@ -80,12 +80,12 @@ static SDL_Cursor *Cocoa_CreateDefaultCursor()
|
|||
}
|
||||
|
||||
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;
|
||||
NSCursor *nscursor = 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;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
/* 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.
|
||||
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];
|
||||
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
|
||||
|
@ -146,9 +146,10 @@ static NSCursor *LoadHiddenSystemCursor(NSString *cursorName, SEL fallback)
|
|||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
||||
static SDL_Cursor *
|
||||
Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSCursor *nscursor = NULL;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
|
||||
|
@ -203,20 +204,20 @@ static SDL_Cursor *Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
|||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static void Cocoa_FreeCursor(SDL_Cursor *cursor)
|
||||
static void
|
||||
Cocoa_FreeCursor(SDL_Cursor * cursor)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
CFBridgingRelease(cursor->driverdata);
|
||||
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_Window *window = (device ? device->windows : NULL);
|
||||
for (; window != NULL; window = window->next) {
|
||||
|
@ -228,10 +229,10 @@ static int Cocoa_ShowCursor(SDL_Cursor *cursor)
|
|||
}
|
||||
}
|
||||
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 };
|
||||
SDL_Window *i;
|
||||
|
@ -245,7 +246,8 @@ static SDL_Window *SDL_FindWindowAtPoint(const int x, const int y)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int Cocoa_WarpMouseGlobal(int x, int y)
|
||||
static int
|
||||
Cocoa_WarpMouseGlobal(int x, int y)
|
||||
{
|
||||
CGPoint point;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
@ -286,12 +288,14 @@ static int Cocoa_WarpMouseGlobal(int x, int y)
|
|||
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);
|
||||
}
|
||||
|
||||
static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||
static int
|
||||
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
CGError result;
|
||||
SDL_Window *window;
|
||||
|
@ -334,14 +338,16 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
|||
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,
|
||||
so all we have to do here is say "okay" and do what we always do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Uint32 Cocoa_GetGlobalMouseState(int *x, int *y)
|
||||
static Uint32
|
||||
Cocoa_GetGlobalMouseState(int *x, int *y)
|
||||
{
|
||||
const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
|
||||
const NSPoint cocoaLocation = [NSEvent mouseLocation];
|
||||
|
@ -359,7 +365,8 @@ static Uint32 Cocoa_GetGlobalMouseState(int *x, int *y)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int Cocoa_InitMouse(_THIS)
|
||||
int
|
||||
Cocoa_InitMouse(_THIS)
|
||||
{
|
||||
NSPoint location;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
@ -387,7 +394,8 @@ int Cocoa_InitMouse(_THIS)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
|
||||
static void
|
||||
Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
|
||||
{
|
||||
SDL_Window *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_MouseData *driverdata;
|
||||
|
@ -499,7 +508,8 @@ void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
|||
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_MouseWheelDirection direction;
|
||||
|
@ -536,7 +546,8 @@ void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
|||
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,
|
||||
* 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);
|
||||
}
|
||||
|
||||
void Cocoa_QuitMouse(_THIS)
|
||||
void
|
||||
Cocoa_QuitMouse(_THIS)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (mouse) {
|
||||
|
|
|
@ -40,19 +40,14 @@ struct SDL_GLDriverData
|
|||
int initialized;
|
||||
};
|
||||
|
||||
@interface SDLOpenGLContext : NSOpenGLContext
|
||||
{
|
||||
@interface SDLOpenGLContext : NSOpenGLContext {
|
||||
SDL_atomic_t dirty;
|
||||
SDL_Window *window;
|
||||
CVDisplayLinkRef displayLink;
|
||||
@public
|
||||
SDL_mutex *swapIntervalMutex;
|
||||
@public
|
||||
SDL_cond *swapIntervalCond;
|
||||
@public
|
||||
SDL_atomic_t swapIntervalSetting;
|
||||
@public
|
||||
SDL_atomic_t swapIntervalsPassed;
|
||||
@public SDL_mutex *swapIntervalMutex;
|
||||
@public SDL_cond *swapIntervalCond;
|
||||
@public SDL_atomic_t swapIntervalSetting;
|
||||
@public SDL_atomic_t swapIntervalsPassed;
|
||||
}
|
||||
|
||||
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
|
||||
|
|
|
@ -56,12 +56,14 @@
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@ -165,9 +167,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||
if ([NSThread isMainThread]) {
|
||||
[self setView:contentview];
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[self setView:contentview];
|
||||
});
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:contentview]; });
|
||||
}
|
||||
if (self == [NSOpenGLContext currentContext]) {
|
||||
[self explicitUpdate];
|
||||
|
@ -196,13 +196,9 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||
[super update];
|
||||
} else {
|
||||
if (SDL_opengl_async_dispatch) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[super update];
|
||||
});
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[super update];
|
||||
});
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +219,9 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||
|
||||
@end
|
||||
|
||||
int Cocoa_GL_LoadLibrary(_THIS, const char *path)
|
||||
|
||||
int
|
||||
Cocoa_GL_LoadLibrary(_THIS, const char *path)
|
||||
{
|
||||
/* Load the OpenGL library */
|
||||
if (path == NULL) {
|
||||
|
@ -247,7 +245,8 @@ Cocoa_GL_GetProcAddress(_THIS, const char *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);
|
||||
_this->gl_config.dll_handle = NULL;
|
||||
|
@ -255,8 +254,8 @@ void Cocoa_GL_UnloadLibrary(_THIS)
|
|||
|
||||
SDL_GLContext
|
||||
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
NSOpenGLPixelFormatAttribute attr[32];
|
||||
|
@ -428,12 +427,12 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window *window)
|
|||
/*_this->gl_config.minor_version = glversion_minor;*/
|
||||
}
|
||||
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) {
|
||||
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
|
||||
if ([nscontext window] != window) {
|
||||
|
@ -446,12 +445,12 @@ int Cocoa_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
|
|||
}
|
||||
|
||||
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();
|
||||
int status;
|
||||
|
||||
|
@ -466,20 +465,20 @@ int Cocoa_GL_SetSwapInterval(_THIS, int interval)
|
|||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
int Cocoa_GL_GetSwapInterval(_THIS)
|
||||
int
|
||||
Cocoa_GL_GetSwapInterval(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
|
||||
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();
|
||||
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
|
||||
|
@ -511,16 +510,15 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window)
|
|||
[nscontext updateIfNeeded];
|
||||
SDL_UnlockMutex(videodata.swaplock);
|
||||
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);
|
||||
[nscontext setWindow:NULL];
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
|
||||
#ifdef __clang__
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
/* 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 (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
|
@ -58,8 +59,8 @@ int Cocoa_GLES_LoadLibrary(_THIS, const char *path)
|
|||
|
||||
SDL_GLContext
|
||||
Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_GLContext context;
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
||||
|
||||
|
@ -114,18 +115,12 @@ Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
|||
int
|
||||
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_EGL_DeleteContext(_this, context);
|
||||
Cocoa_GLES_UnloadLibrary(_this);
|
||||
}
|
||||
}
|
||||
NSView* v;
|
||||
/* The current context is lost in here; save it and reset it. */
|
||||
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) {
|
||||
/* !!! 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);
|
||||
return -1;
|
||||
}
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
}
|
||||
|
||||
if (h) {
|
||||
*h = height;
|
||||
}
|
||||
}
|
||||
/* Create the GLES window surface */
|
||||
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);
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
|
||||
SDL_WindowShaper*
|
||||
Cocoa_CreateShaper(SDL_Window* window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_WindowShaper* result;
|
||||
SDL_ShapeData* data;
|
||||
int resized_properly;
|
||||
|
@ -75,10 +75,10 @@ Cocoa_CreateShaper(SDL_Window *window)
|
|||
resized_properly = Cocoa_ResizeWindowShape(window);
|
||||
SDL_assert(resized_properly == 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void ConvertRects(SDL_ShapeTree *tree, void *closure)
|
||||
void
|
||||
ConvertRects(SDL_ShapeTree* tree, void* closure)
|
||||
{
|
||||
SDL_CocoaClosure* data = (__bridge SDL_CocoaClosure*)closure;
|
||||
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_WindowData* windata = (__bridge SDL_WindowData*)shaper->window->driverdata;
|
||||
SDL_CocoaClosure* closure;
|
||||
|
@ -115,17 +116,15 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
|
|||
[closure.path addClip];
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
int Cocoa_ResizeWindowShape(SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
int
|
||||
Cocoa_ResizeWindowShape(SDL_Window *window)
|
||||
{ @autoreleasepool {
|
||||
SDL_ShapeData* data = (__bridge SDL_ShapeData*)window->shaper->driverdata;
|
||||
SDL_assert(data != NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
||||
|
|
|
@ -44,55 +44,25 @@ static void Cocoa_VideoQuit(_THIS);
|
|||
|
||||
/* Cocoa driver bootstrap functions */
|
||||
|
||||
static void Cocoa_DeleteDevice(SDL_VideoDevice *device)
|
||||
static void
|
||||
Cocoa_DeleteDevice(SDL_VideoDevice * device)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (device->wakeup_lock) {
|
||||
SDL_DestroyMutex(device->wakeup_lock);
|
||||
}
|
||||
CFBridgingRelease(device->driverdata);
|
||||
SDL_free(device);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
static SDL_VideoDevice *Cocoa_CreateDevice(void)
|
||||
static SDL_VideoDevice *
|
||||
Cocoa_CreateDevice(void)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoDevice *device;
|
||||
SDL_VideoData *data;
|
||||
|
||||
device->CreateSDLWindow = Cocoa_CreateWindow;
|
||||
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;
|
||||
Cocoa_RegisterApp();
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
|
@ -142,6 +112,8 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
|
|||
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;
|
||||
|
@ -205,17 +177,18 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
|
|||
device->free = Cocoa_DeleteDevice;
|
||||
|
||||
return device;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
VideoBootStrap COCOA_bootstrap = {
|
||||
"cocoa", "SDL Cocoa video driver",
|
||||
Cocoa_CreateDevice
|
||||
};
|
||||
|
||||
int Cocoa_VideoInit(_THIS)
|
||||
|
||||
int
|
||||
Cocoa_VideoInit(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
|
||||
Cocoa_InitModes(_this);
|
||||
|
@ -233,20 +206,19 @@ int Cocoa_VideoInit(_THIS)
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void Cocoa_VideoQuit(_THIS)
|
||||
void
|
||||
Cocoa_VideoQuit(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
Cocoa_QuitModes(_this);
|
||||
Cocoa_QuitKeyboard(_this);
|
||||
Cocoa_QuitMouse(_this);
|
||||
SDL_DestroyMutex(data.swaplock);
|
||||
data.swaplock = NULL;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
/* This function assumes that it's called from within an autorelease pool */
|
||||
NSImage *
|
||||
|
|
|
@ -139,10 +139,13 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
|
|||
}
|
||||
SDL_free(extensions);
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -39,8 +39,7 @@ typedef enum
|
|||
PENDING_OPERATION_MINIMIZE
|
||||
} PendingWindowOperation;
|
||||
|
||||
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate>
|
||||
{
|
||||
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
|
||||
/* SDL_WindowData owns this Listener and has a strong reference to it.
|
||||
* To avoid reference cycles, we could have either a weak or an
|
||||
* unretained ref to the WindowData. */
|
||||
|
|
|
@ -46,11 +46,10 @@
|
|||
#ifdef DEBUG_COCOAWINDOW
|
||||
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DLog(...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#define DLog(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
|
||||
|
||||
#ifndef MAC_OS_X_VERSION_10_12
|
||||
|
@ -159,8 +158,8 @@
|
|||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
||||
{ @autoreleasepool
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
|
||||
NSString *desiredType = [pasteboard availableTypeFromArray:types];
|
||||
|
@ -223,8 +222,7 @@
|
|||
|
||||
SDL_SendDropComplete(sdlwindow);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
- (BOOL)wantsPeriodicDraggingUpdates
|
||||
{
|
||||
|
@ -251,6 +249,7 @@
|
|||
|
||||
@end
|
||||
|
||||
|
||||
static Uint32 s_moveHack;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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. */
|
||||
#if SDL_VIDEO_OPENGL
|
||||
|
@ -294,12 +294,14 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
|||
}
|
||||
|
||||
/* !!! 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);
|
||||
}
|
||||
|
||||
static NSUInteger GetWindowWindowedStyle(SDL_Window *window)
|
||||
static NSUInteger
|
||||
GetWindowWindowedStyle(SDL_Window * window)
|
||||
{
|
||||
/* IF YOU CHANGE ANY FLAGS IN HERE, PLEASE READ
|
||||
the NSWindowStyleMaskBorderless comments in SetupWindowData()! */
|
||||
|
@ -319,7 +321,8 @@ static NSUInteger GetWindowWindowedStyle(SDL_Window *window)
|
|||
return style;
|
||||
}
|
||||
|
||||
static NSUInteger GetWindowStyle(SDL_Window *window)
|
||||
static NSUInteger
|
||||
GetWindowStyle(SDL_Window * window)
|
||||
{
|
||||
NSUInteger style = 0;
|
||||
|
||||
|
@ -331,7 +334,8 @@ static NSUInteger GetWindowStyle(SDL_Window *window)
|
|||
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;
|
||||
NSWindow *nswindow = data.nswindow;
|
||||
|
@ -351,7 +355,8 @@ static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style)
|
|||
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;
|
||||
|
||||
|
@ -369,7 +374,8 @@ static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window)
|
|||
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) {
|
||||
SDL_Rect window_rect;
|
||||
|
@ -408,7 +414,8 @@ static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, int x, int y, CGPoi
|
|||
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;
|
||||
|
||||
|
@ -461,6 +468,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@implementation Cocoa_WindowListener
|
||||
|
||||
- (void)listen:(SDL_WindowData *)data
|
||||
|
@ -1179,7 +1187,8 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
|||
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 int clicks = (int) [theEvent clickCount];
|
||||
|
@ -1374,6 +1383,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
|
|||
Cocoa_HandleMouseWheel(_data.window, theEvent);
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent
|
||||
{
|
||||
SDL_Window *window = _data.window;
|
||||
|
@ -1512,8 +1522,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
|
|||
|
||||
@end
|
||||
|
||||
@interface SDLView : NSView
|
||||
{
|
||||
@interface SDLView : NSView {
|
||||
SDL_Window *_sdlWindow;
|
||||
}
|
||||
|
||||
|
@ -1608,9 +1617,10 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
|
|||
}
|
||||
@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_WindowData *data;
|
||||
|
||||
|
@ -1699,12 +1709,12 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
|
|||
/* All done! */
|
||||
window->driverdata = (void *)CFBridgingRetain(data);
|
||||
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;
|
||||
NSWindow *nswindow;
|
||||
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) {
|
||||
[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!
|
||||
* The window will get permanently stuck if resizable is false.
|
||||
* -flibit
|
||||
|
@ -1814,18 +2098,31 @@ void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
|
|||
[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;
|
||||
if (on_top) {
|
||||
[nswindow setLevel:NSFloatingWindowLevel];
|
||||
} else {
|
||||
[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) {
|
||||
|
@ -2037,27 +2334,54 @@ Cocoa_SetWindowMouseRect(_THIS, SDL_Window * 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;
|
||||
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];
|
||||
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 (fullscreen) {
|
||||
SDL_Rect bounds;
|
||||
#if SDL_VIDEO_OPENGL
|
||||
|
||||
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
||||
rect.origin.x = bounds.x;
|
||||
rect.origin.y = bounds.y;
|
||||
rect.size.width = bounds.w;
|
||||
rect.size.height = bounds.h;
|
||||
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
||||
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 */
|
||||
|
||||
|
@ -2111,255 +2435,6 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
|
|||
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;
|
||||
if ([data.listener setFullscreenSpace:(state ? YES : NO)]) {
|
||||
const int maxattempts = 3;
|
||||
|
@ -2390,29 +2465,30 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state)
|
|||
data.inWindowFullscreenTransition = SDL_FALSE;
|
||||
|
||||
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. */
|
||||
}
|
||||
|
||||
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;
|
||||
if (accept) {
|
||||
[data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
|
||||
} else {
|
||||
[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! */
|
||||
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 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;
|
||||
[data.nswindow setAlphaValue:opacity];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
|
|||
|
||||
#if !TARGET_OS_TV
|
||||
/* 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;
|
||||
UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
|
||||
|
@ -131,15 +132,13 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
|||
|
||||
@implementation SDLLaunchStoryboardViewController
|
||||
|
||||
- (instancetype)initWithStoryboardViewController:(UIViewController *)storyboardViewController
|
||||
{
|
||||
- (instancetype)initWithStoryboardViewController:(UIViewController *)storyboardViewController {
|
||||
self = [super init];
|
||||
self.storyboardViewController = storyboardViewController;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self addChildViewController:self.storyboardViewController];
|
||||
|
@ -152,13 +151,11 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
|||
UIApplication.sharedApplication.statusBarStyle = self.preferredStatusBarStyle;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
{
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarHidden"] boolValue];
|
||||
}
|
||||
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle
|
||||
{
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle {
|
||||
NSString *statusBarStyle = [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarStyle"];
|
||||
if ([statusBarStyle isEqualToString:@"UIStatusBarStyleLightContent"]) {
|
||||
return UIStatusBarStyleLightContent;
|
||||
|
@ -347,8 +344,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
|||
|
||||
@end
|
||||
|
||||
@implementation SDLUIKitDelegate
|
||||
{
|
||||
@implementation SDLUIKitDelegate {
|
||||
UIWindow *launchWindow;
|
||||
}
|
||||
|
||||
|
@ -379,11 +375,9 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
|||
launchWindow = nil;
|
||||
|
||||
/* Do a nice animated fade-out (roughly matches the real launch behavior.) */
|
||||
[UIView animateWithDuration:0.2
|
||||
animations:^{
|
||||
[UIView animateWithDuration:0.2 animations:^{
|
||||
window.alpha = 0.0;
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
} completion:^(BOOL finished) {
|
||||
window.hidden = YES;
|
||||
UIKit_ForceUpdateHomeIndicator(); /* Wait for launch screen to hide so settings are applied to the actual view controller. */
|
||||
}];
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
|
||||
#import <UIKit/UIPasteboard.h>
|
||||
|
||||
int UIKit_SetClipboardText(_THIS, const char *text)
|
||||
int
|
||||
UIKit_SetClipboardText(_THIS, const char *text)
|
||||
{
|
||||
#if TARGET_OS_TV
|
||||
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
|
||||
@autoreleasepool {
|
||||
|
@ -90,7 +92,8 @@ void UIKit_InitClipboard(_THIS)
|
|||
#endif
|
||||
}
|
||||
|
||||
void UIKit_QuitClipboard(_THIS)
|
||||
void
|
||||
UIKit_QuitClipboard(_THIS)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
static BOOL UIKit_EventPumpEnabled = YES;
|
||||
|
||||
|
||||
@interface SDL_LifecycleObserver : NSObject
|
||||
@property (nonatomic, assign) BOOL isObservingNotifications;
|
||||
@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(applicationDidReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||
#if !TARGET_OS_TV
|
||||
[notificationCenter addObserver:self
|
||||
selector:@selector(applicationDidChangeStatusBarOrientation)
|
||||
name:UIApplicationDidChangeStatusBarOrientationNotification
|
||||
object:nil];
|
||||
[notificationCenter addObserver:self selector:@selector(applicationDidChangeStatusBarOrientation) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
|
||||
#endif
|
||||
} else if (!UIKit_EventPumpEnabled && self.isObservingNotifications) {
|
||||
self.isObservingNotifications = NO;
|
||||
|
@ -109,7 +107,9 @@ static BOOL UIKit_EventPumpEnabled = YES;
|
|||
|
||||
@end
|
||||
|
||||
void SDL_iPhoneSetEventPump(SDL_bool enabled)
|
||||
|
||||
void
|
||||
SDL_iPhoneSetEventPump(SDL_bool enabled)
|
||||
{
|
||||
UIKit_EventPumpEnabled = enabled;
|
||||
|
||||
|
@ -121,7 +121,8 @@ void SDL_iPhoneSetEventPump(SDL_bool enabled)
|
|||
[lifecycleObserver eventPumpChanged];
|
||||
}
|
||||
|
||||
void UIKit_PumpEvents(_THIS)
|
||||
void
|
||||
UIKit_PumpEvents(_THIS)
|
||||
{
|
||||
if (!UIKit_EventPumpEnabled) {
|
||||
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))
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -250,6 +252,7 @@ void SDL_QuitGCKeyboard(void)
|
|||
|
||||
#endif /* ENABLE_GCKEYBOARD */
|
||||
|
||||
|
||||
#ifdef ENABLE_GCMOUSE
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
};
|
||||
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);
|
||||
};
|
||||
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);
|
||||
};
|
||||
|
||||
int auxiliary_button = SDL_BUTTON_X1;
|
||||
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);
|
||||
};
|
||||
++auxiliary_button;
|
||||
}
|
||||
|
||||
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY) {
|
||||
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY)
|
||||
{
|
||||
if (SDL_GCMouseRelativeMode()) {
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ UIKit_ShowingMessageBox(void)
|
|||
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;
|
||||
|
||||
|
@ -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 __block clickedindex = messageboxdata->numbuttons;
|
||||
|
@ -122,32 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
|
|||
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)) {
|
||||
*returnValue = 0;
|
||||
} else {
|
||||
*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;
|
||||
|
||||
if ([NSThread isMainThread]) {
|
||||
UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue);
|
||||
});
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{ UIKit_ShowMessageBoxImpl(messageboxdata, buttonid, &returnValue); });
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
|
||||
|
||||
@interface SDL_uikitmetalview : SDL_uikitview
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
|
|
|
@ -76,8 +76,7 @@
|
|||
|
||||
SDL_MetalView
|
||||
UIKit_Metal_CreateView(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
||||
CGFloat scale = 1.0;
|
||||
SDL_uikitmetalview *metalview;
|
||||
|
@ -101,30 +100,27 @@ UIKit_Metal_CreateView(_THIS, SDL_Window *window)
|
|||
[metalview setSDLWindow:window];
|
||||
|
||||
return (void*)CFBridgingRetain(metalview);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void UIKit_Metal_DestroyView(_THIS, SDL_MetalView view)
|
||||
{
|
||||
@autoreleasepool {
|
||||
void
|
||||
UIKit_Metal_DestroyView(_THIS, SDL_MetalView view)
|
||||
{ @autoreleasepool {
|
||||
SDL_uikitmetalview *metalview = CFBridgingRelease(view);
|
||||
|
||||
if ([metalview isKindOfClass:[SDL_uikitmetalview class]]) {
|
||||
[metalview setSDLWindow:NULL];
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
void *
|
||||
UIKit_Metal_GetLayer(_THIS, SDL_MetalView view)
|
||||
{
|
||||
@autoreleasepool {
|
||||
{ @autoreleasepool {
|
||||
SDL_uikitview *uiview = (__bridge SDL_uikitview *)view;
|
||||
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 {
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
||||
|
|
|
@ -141,8 +141,7 @@
|
|||
struct utsname systemInfo;
|
||||
uname(&systemInfo);
|
||||
NSString* deviceName =
|
||||
[NSString stringWithCString:systemInfo.machine
|
||||
encoding:NSUTF8StringEncoding];
|
||||
[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
|
||||
id foundDPI = devices[deviceName];
|
||||
if (foundDPI) {
|
||||
self.screenDPI = (float)[foundDPI integerValue];
|
||||
|
@ -186,14 +185,10 @@
|
|||
{
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center addObserver:self
|
||||
selector:@selector(screenConnected:)
|
||||
name:UIScreenDidConnectNotification
|
||||
object:nil];
|
||||
[center addObserver:self
|
||||
selector:@selector(screenDisconnected:)
|
||||
name:UIScreenDidDisconnectNotification
|
||||
object:nil];
|
||||
[center addObserver:self selector:@selector(screenConnected:)
|
||||
name:UIScreenDidConnectNotification object:nil];
|
||||
[center addObserver:self selector:@selector(screenDisconnected:)
|
||||
name:UIScreenDidDisconnectNotification object:nil];
|
||||
}
|
||||
|
||||
+ (void)stop
|
||||
|
@ -201,11 +196,9 @@
|
|||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center removeObserver:self
|
||||
name:UIScreenDidConnectNotification
|
||||
object:nil];
|
||||
name:UIScreenDidConnectNotification object:nil];
|
||||
[center removeObserver:self
|
||||
name:UIScreenDidDisconnectNotification
|
||||
object:nil];
|
||||
name:UIScreenDidDisconnectNotification object:nil];
|
||||
}
|
||||
|
||||
+ (void)screenConnected:(NSNotification*)notification
|
||||
|
@ -222,7 +215,8 @@
|
|||
|
||||
@end
|
||||
|
||||
static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode,
|
||||
static int
|
||||
UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
|
||||
UIScreenMode * uiscreenmode)
|
||||
{
|
||||
SDL_DisplayModeData *data = nil;
|
||||
|
@ -242,7 +236,8 @@ static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void UIKit_FreeDisplayModeData(SDL_DisplayMode *mode)
|
||||
static void
|
||||
UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
|
||||
{
|
||||
if (mode->driverdata != NULL) {
|
||||
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
|
||||
if ([uiscreen respondsToSelector:@selector(maximumFramesPerSecond)]) {
|
||||
|
@ -260,7 +256,8 @@ static NSUInteger UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
|
|||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
|
||||
int
|
||||
UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
|
||||
{
|
||||
UIScreenMode *uiscreenmode = uiscreen.currentMode;
|
||||
CGSize size = uiscreen.bounds.size;
|
||||
|
@ -341,7 +340,8 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void UIKit_DelDisplay(UIScreen *uiscreen)
|
||||
void
|
||||
UIKit_DelDisplay(UIScreen *uiscreen)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -370,7 +370,8 @@ UIKit_IsDisplayLandscape(UIScreen *uiscreen)
|
|||
}
|
||||
}
|
||||
|
||||
int UIKit_InitModes(_THIS)
|
||||
int
|
||||
UIKit_InitModes(_THIS)
|
||||
{
|
||||
@autoreleasepool {
|
||||
for (UIScreen *uiscreen in [UIScreen screens]) {
|
||||
|
@ -388,7 +389,8 @@ int UIKit_InitModes(_THIS)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
|
||||
void
|
||||
UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||
{
|
||||
@autoreleasepool {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
|
||||
int
|
||||
UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
|
||||
|
@ -481,7 +485,8 @@ int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode
|
|||
return 0;
|
||||
}
|
||||
|
||||
int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
int
|
||||
UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
|
||||
{
|
||||
@autoreleasepool {
|
||||
int displayIndex = (int) (display - _this->displays);
|
||||
|
@ -503,7 +508,8 @@ int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
|
|||
return 0;
|
||||
}
|
||||
|
||||
void UIKit_QuitModes(_THIS)
|
||||
void
|
||||
UIKit_QuitModes(_THIS)
|
||||
{
|
||||
[SDL_DisplayWatch stop];
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ UIKit_GL_GetProcAddress(_THIS, const char *proc)
|
|||
/*
|
||||
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 {
|
||||
SDLEAGLContext *eaglcontext = (__bridge SDLEAGLContext *) context;
|
||||
|
@ -81,7 +82,8 @@ int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
|
|||
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 {
|
||||
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
|
||||
* 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 {
|
||||
/* 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 {
|
||||
/* Some iOS system functionality (such as Dictation on the on-screen
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
#import "SDL_uikitopenglview.h"
|
||||
#include "SDL_uikitwindow.h"
|
||||
|
||||
@implementation SDL_uikitopenglview
|
||||
{
|
||||
@implementation SDL_uikitopenglview {
|
||||
/* The renderbuffer and framebuffer used to render to this layer. */
|
||||
GLuint viewRenderbuffer, viewFramebuffer;
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ static void UIKit_DeleteDevice(SDL_VideoDevice *device)
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_VideoDevice *UIKit_CreateDevice(void)
|
||||
static SDL_VideoDevice *
|
||||
UIKit_CreateDevice(void)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoDevice *device;
|
||||
|
@ -126,7 +127,8 @@ static SDL_VideoDevice *UIKit_CreateDevice(void)
|
|||
#if SDL_VIDEO_VULKAN
|
||||
device->Vulkan_LoadLibrary = UIKit_Vulkan_LoadLibrary;
|
||||
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_GetDrawableSize = UIKit_Vulkan_GetDrawableSize;
|
||||
#endif
|
||||
|
@ -149,7 +151,9 @@ VideoBootStrap UIKIT_bootstrap = {
|
|||
UIKit_CreateDevice
|
||||
};
|
||||
|
||||
int UIKit_VideoInit(_THIS)
|
||||
|
||||
int
|
||||
UIKit_VideoInit(_THIS)
|
||||
{
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
|
||||
|
@ -163,7 +167,8 @@ int UIKit_VideoInit(_THIS)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void UIKit_VideoQuit(_THIS)
|
||||
void
|
||||
UIKit_VideoQuit(_THIS)
|
||||
{
|
||||
SDL_QuitGCKeyboard();
|
||||
SDL_QuitGCMouse();
|
||||
|
@ -171,7 +176,8 @@ void UIKit_VideoQuit(_THIS)
|
|||
UIKit_QuitModes(_this);
|
||||
}
|
||||
|
||||
void UIKit_SuspendScreenSaver(_THIS)
|
||||
void
|
||||
UIKit_SuspendScreenSaver(_THIS)
|
||||
{
|
||||
@autoreleasepool {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
void UIKit_ForceUpdateHomeIndicator()
|
||||
void
|
||||
UIKit_ForceUpdateHomeIndicator()
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
/* Force the main SDL window to re-evaluate home indicator state */
|
||||
|
|
|
@ -42,8 +42,7 @@
|
|||
extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
||||
#endif
|
||||
|
||||
@implementation SDL_uikitview
|
||||
{
|
||||
@implementation SDL_uikitview {
|
||||
SDL_Window *sdlwindow;
|
||||
|
||||
SDL_TouchID directTouchId;
|
||||
|
@ -150,8 +149,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
}
|
||||
|
||||
#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()) {
|
||||
CGPoint origin = self.bounds.origin;
|
||||
CGPoint point = request.location;
|
||||
|
@ -164,8 +162,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
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)) {
|
||||
return nil;
|
||||
} else {
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
#include "SDL_uikitopengles.h"
|
||||
|
||||
#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 {
|
||||
SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
|
||||
|
@ -46,7 +47,8 @@ static void SDLCALL SDL_AppleTVControllerUIHintChanged(void *userdata, const cha
|
|||
#endif
|
||||
|
||||
#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 {
|
||||
SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
|
||||
|
@ -62,8 +64,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||
}
|
||||
#endif
|
||||
|
||||
@implementation SDL_uikitviewcontroller
|
||||
{
|
||||
@implementation SDL_uikitviewcontroller {
|
||||
CADisplayLink *displayLink;
|
||||
int animationInterval;
|
||||
void (*animationCallback)(void*);
|
||||
|
@ -149,7 +150,9 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||
#ifdef __IPHONE_10_3
|
||||
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;
|
||||
} else
|
||||
#endif
|
||||
|
@ -274,16 +277,10 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
#if !TARGET_OS_TV
|
||||
[center addObserver:self
|
||||
selector:@selector(keyboardWillShow:)
|
||||
name:UIKeyboardWillShowNotification
|
||||
object:nil];
|
||||
[center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
#endif
|
||||
[center addObserver:self
|
||||
selector:@selector(textFieldTextDidChange:)
|
||||
name:UITextFieldTextDidChangeNotification
|
||||
object:nil];
|
||||
[center addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (NSArray *)keyCommands
|
||||
|
@ -334,9 +331,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||
{
|
||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
rotatingOrientation = YES;
|
||||
[coordinator
|
||||
animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
||||
}
|
||||
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
|
||||
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
||||
self->rotatingOrientation = NO;
|
||||
}];
|
||||
|
@ -346,14 +341,10 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||
{
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
#if !TARGET_OS_TV
|
||||
[center removeObserver:self
|
||||
name:UIKeyboardWillShowNotification
|
||||
object:nil];
|
||||
[center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
|
||||
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
|
||||
#endif
|
||||
[center removeObserver:self
|
||||
name:UITextFieldTextDidChangeNotification
|
||||
object:nil];
|
||||
[center removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
/* reveal onscreen virtual keyboard */
|
||||
|
@ -497,7 +488,8 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||
/* iPhone keyboard addition functions */
|
||||
#if SDL_IPHONE_KEYBOARD
|
||||
|
||||
static SDL_uikitviewcontroller *GetWindowViewController(SDL_Window *window)
|
||||
static SDL_uikitviewcontroller *
|
||||
GetWindowViewController(SDL_Window * window)
|
||||
{
|
||||
if (!window || !window->driverdata) {
|
||||
SDL_SetError("Invalid window");
|
||||
|
@ -515,7 +507,8 @@ UIKit_HasScreenKeyboardSupport(_THIS)
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
|
||||
void
|
||||
UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
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 {
|
||||
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) {
|
||||
SDL_InvalidParamError("rect");
|
||||
|
@ -562,6 +557,7 @@ void UIKit_SetTextInputRect(_THIS, const SDL_Rect *rect)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* SDL_IPHONE_KEYBOARD */
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||
|
|
|
@ -145,10 +145,13 @@ int UIKit_Vulkan_LoadLibrary(_THIS, const char *path)
|
|||
SDL_free(extensions);
|
||||
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
@ -211,7 +214,8 @@ SDL_bool UIKit_Vulkan_CreateSurface(_THIS,
|
|||
}
|
||||
|
||||
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.");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,9 @@
|
|||
|
||||
@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_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
|
||||
|
@ -156,7 +158,8 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
|
|||
return 0;
|
||||
}
|
||||
|
||||
int UIKit_CreateWindow(_THIS, SDL_Window *window)
|
||||
int
|
||||
UIKit_CreateWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
|
@ -226,7 +229,8 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
|
||||
void
|
||||
UIKit_SetWindowTitle(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
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 {
|
||||
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 {
|
||||
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 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);
|
||||
}
|
||||
|
||||
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_uikitviewcontroller *viewcontroller = data.viewcontroller;
|
||||
|
@ -296,26 +304,30 @@ static void UIKit_UpdateWindowBorder(_THIS, SDL_Window *window)
|
|||
[viewcontroller.view layoutIfNeeded];
|
||||
}
|
||||
|
||||
void UIKit_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
|
||||
void
|
||||
UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
||||
{
|
||||
@autoreleasepool {
|
||||
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 {
|
||||
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 */
|
||||
}
|
||||
|
||||
void UIKit_UpdatePointerLock(_THIS, SDL_Window *window)
|
||||
void
|
||||
UIKit_UpdatePointerLock(_THIS, SDL_Window * window)
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
#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 */
|
||||
}
|
||||
|
||||
void UIKit_DestroyWindow(_THIS, SDL_Window *window)
|
||||
void
|
||||
UIKit_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (window->driverdata != NULL) {
|
||||
|
@ -358,9 +371,10 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
|
|||
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;
|
||||
UIView *view = windata.viewcontroller.view;
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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
|
||||
* SDL_uikitopenglview. */
|
||||
*w = size.width * scale;
|
||||
|
@ -490,7 +497,8 @@ UIKit_GetSupportedOrientations(SDL_Window *window)
|
|||
}
|
||||
#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) {
|
||||
return SDL_SetError("Invalid window");
|
||||
|
|
Loading…
Reference in a new issue