mac: Rename Objective-C classes that conflict with SDL2.

Fixes #6709.
This commit is contained in:
Ryan C. Gordon
2024-07-24 01:35:04 -04:00
parent f0363a0466
commit 06c0ed68b1
13 changed files with 121 additions and 121 deletions

View File

@@ -1323,13 +1323,13 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
#ifdef ENABLE_MFI_RUMBLE #ifdef ENABLE_MFI_RUMBLE
@interface SDL_RumbleMotor : NSObject @interface SDL3_RumbleMotor : NSObject
@property(nonatomic, strong) CHHapticEngine *engine API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0)); @property(nonatomic, strong) CHHapticEngine *engine API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
@property(nonatomic, strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0)); @property(nonatomic, strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
@property bool active; @property bool active;
@end @end
@implementation SDL_RumbleMotor @implementation SDL3_RumbleMotor
{ {
} }
@@ -1420,7 +1420,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
} }
self.engine.stoppedHandler = ^(CHHapticEngineStoppedReason stoppedReason) { self.engine.stoppedHandler = ^(CHHapticEngineStoppedReason stoppedReason) {
SDL_RumbleMotor *_this = weakSelf; SDL3_RumbleMotor *_this = weakSelf;
if (_this == nil) { if (_this == nil) {
return; return;
} }
@@ -1429,7 +1429,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
_this.engine = nil; _this.engine = nil;
}; };
self.engine.resetHandler = ^{ self.engine.resetHandler = ^{
SDL_RumbleMotor *_this = weakSelf; SDL3_RumbleMotor *_this = weakSelf;
if (_this == nil) { if (_this == nil) {
return; return;
} }
@@ -1444,21 +1444,21 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
@end @end
@interface SDL_RumbleContext : NSObject @interface SDL3_RumbleContext : NSObject
@property(nonatomic, strong) SDL_RumbleMotor *lowFrequencyMotor; @property(nonatomic, strong) SDL3_RumbleMotor *lowFrequencyMotor;
@property(nonatomic, strong) SDL_RumbleMotor *highFrequencyMotor; @property(nonatomic, strong) SDL3_RumbleMotor *highFrequencyMotor;
@property(nonatomic, strong) SDL_RumbleMotor *leftTriggerMotor; @property(nonatomic, strong) SDL3_RumbleMotor *leftTriggerMotor;
@property(nonatomic, strong) SDL_RumbleMotor *rightTriggerMotor; @property(nonatomic, strong) SDL3_RumbleMotor *rightTriggerMotor;
@end @end
@implementation SDL_RumbleContext @implementation SDL3_RumbleContext
{ {
} }
- (id)initWithLowFrequencyMotor:(SDL_RumbleMotor *)low_frequency_motor - (id)initWithLowFrequencyMotor:(SDL3_RumbleMotor *)low_frequency_motor
HighFrequencyMotor:(SDL_RumbleMotor *)high_frequency_motor HighFrequencyMotor:(SDL3_RumbleMotor *)high_frequency_motor
LeftTriggerMotor:(SDL_RumbleMotor *)left_trigger_motor LeftTriggerMotor:(SDL3_RumbleMotor *)left_trigger_motor
RightTriggerMotor:(SDL_RumbleMotor *)right_trigger_motor RightTriggerMotor:(SDL3_RumbleMotor *)right_trigger_motor
{ {
self = [super init]; self = [super init];
self.lowFrequencyMotor = low_frequency_motor; self.lowFrequencyMotor = low_frequency_motor;
@@ -1498,16 +1498,16 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
@end @end
static SDL_RumbleContext *IOS_JoystickInitRumble(GCController *controller) static SDL3_RumbleContext *IOS_JoystickInitRumble(GCController *controller)
{ {
@autoreleasepool { @autoreleasepool {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
SDL_RumbleMotor *low_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftHandle]; SDL3_RumbleMotor *low_frequency_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftHandle];
SDL_RumbleMotor *high_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightHandle]; SDL3_RumbleMotor *high_frequency_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightHandle];
SDL_RumbleMotor *left_trigger_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftTrigger]; SDL3_RumbleMotor *left_trigger_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftTrigger];
SDL_RumbleMotor *right_trigger_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightTrigger]; SDL3_RumbleMotor *right_trigger_motor = [[SDL3_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightTrigger];
if (low_frequency_motor && high_frequency_motor) { if (low_frequency_motor && high_frequency_motor) {
return [[SDL_RumbleContext alloc] initWithLowFrequencyMotor:low_frequency_motor return [[SDL3_RumbleContext alloc] initWithLowFrequencyMotor:low_frequency_motor
HighFrequencyMotor:high_frequency_motor HighFrequencyMotor:high_frequency_motor
LeftTriggerMotor:left_trigger_motor LeftTriggerMotor:left_trigger_motor
RightTriggerMotor:right_trigger_motor]; RightTriggerMotor:right_trigger_motor];
@@ -1530,7 +1530,7 @@ static int IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) { if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller); SDL3_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) { if (rumble) {
device->rumble = (void *)CFBridgingRetain(rumble); device->rumble = (void *)CFBridgingRetain(rumble);
} }
@@ -1538,7 +1538,7 @@ static int IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
} }
if (device->rumble) { if (device->rumble) {
SDL_RumbleContext *rumble = (__bridge SDL_RumbleContext *)device->rumble; SDL3_RumbleContext *rumble = (__bridge SDL3_RumbleContext *)device->rumble;
return [rumble rumbleWithLowFrequency:low_frequency_rumble andHighFrequency:high_frequency_rumble]; return [rumble rumbleWithLowFrequency:low_frequency_rumble andHighFrequency:high_frequency_rumble];
} else { } else {
return SDL_Unsupported(); return SDL_Unsupported();
@@ -1559,7 +1559,7 @@ static int IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) { if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller); SDL3_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) { if (rumble) {
device->rumble = (void *)CFBridgingRetain(rumble); device->rumble = (void *)CFBridgingRetain(rumble);
} }
@@ -1567,7 +1567,7 @@ static int IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble
} }
if (device->rumble) { if (device->rumble) {
SDL_RumbleContext *rumble = (__bridge SDL_RumbleContext *)device->rumble; SDL3_RumbleContext *rumble = (__bridge SDL3_RumbleContext *)device->rumble;
return [rumble rumbleLeftTrigger:left_rumble andRightTrigger:right_rumble]; return [rumble rumbleLeftTrigger:left_rumble andRightTrigger:right_rumble];
} else { } else {
return SDL_Unsupported(); return SDL_Unsupported();
@@ -1658,7 +1658,7 @@ static void IOS_JoystickClose(SDL_Joystick *joystick)
@autoreleasepool { @autoreleasepool {
#ifdef ENABLE_MFI_RUMBLE #ifdef ENABLE_MFI_RUMBLE
if (device->rumble) { if (device->rumble) {
SDL_RumbleContext *rumble = (__bridge SDL_RumbleContext *)device->rumble; SDL3_RumbleContext *rumble = (__bridge SDL3_RumbleContext *)device->rumble;
[rumble cleanup]; [rumble cleanup];
CFRelease(device->rumble); CFRelease(device->rumble);

View File

@@ -133,7 +133,7 @@ typedef struct METAL_ShaderPipelines
METAL_PipelineCache caches[SDL_METAL_FRAGMENT_COUNT]; METAL_PipelineCache caches[SDL_METAL_FRAGMENT_COUNT];
} METAL_ShaderPipelines; } METAL_ShaderPipelines;
@interface METAL_RenderData : NSObject @interface SDL3METAL_RenderData : NSObject
@property(nonatomic, retain) id<MTLDevice> mtldevice; @property(nonatomic, retain) id<MTLDevice> mtldevice;
@property(nonatomic, retain) id<MTLCommandQueue> mtlcmdqueue; @property(nonatomic, retain) id<MTLCommandQueue> mtlcmdqueue;
@property(nonatomic, retain) id<MTLCommandBuffer> mtlcmdbuffer; @property(nonatomic, retain) id<MTLCommandBuffer> mtlcmdbuffer;
@@ -151,10 +151,10 @@ typedef struct METAL_ShaderPipelines
@property(nonatomic, assign) int pipelinescount; @property(nonatomic, assign) int pipelinescount;
@end @end
@implementation METAL_RenderData @implementation SDL3METAL_RenderData
@end @end
@interface METAL_TextureData : NSObject @interface SDL3METAL_TextureData : NSObject
@property(nonatomic, retain) id<MTLTexture> mtltexture; @property(nonatomic, retain) id<MTLTexture> mtltexture;
@property(nonatomic, retain) id<MTLTexture> mtltextureUv; @property(nonatomic, retain) id<MTLTexture> mtltextureUv;
@property(nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction; @property(nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction;
@@ -168,7 +168,7 @@ typedef struct METAL_ShaderPipelines
@property(nonatomic, assign) SDL_Rect lockedrect; @property(nonatomic, assign) SDL_Rect lockedrect;
@end @end
@implementation METAL_TextureData @implementation SDL3METAL_TextureData
@end @end
static SDL_bool IsMetalAvailable() static SDL_bool IsMetalAvailable()
@@ -260,7 +260,7 @@ static NSString *GetFragmentFunctionName(SDL_MetalFragmentFunction function)
} }
} }
static id<MTLRenderPipelineState> MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache, static id<MTLRenderPipelineState> MakePipelineState(SDL3METAL_RenderData *data, METAL_PipelineCache *cache,
NSString *blendlabel, SDL_BlendMode blendmode) NSString *blendlabel, SDL_BlendMode blendmode)
{ {
MTLRenderPipelineDescriptor *mtlpipedesc; MTLRenderPipelineDescriptor *mtlpipedesc;
@@ -353,7 +353,7 @@ static id<MTLRenderPipelineState> MakePipelineState(METAL_RenderData *data, META
} }
} }
static void MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char *label, static void MakePipelineCache(SDL3METAL_RenderData *data, METAL_PipelineCache *cache, const char *label,
MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn) MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn)
{ {
SDL_zerop(cache); SDL_zerop(cache);
@@ -383,7 +383,7 @@ static void DestroyPipelineCache(METAL_PipelineCache *cache)
} }
} }
void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat) void MakeShaderPipelines(SDL3METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat)
{ {
SDL_zerop(pipelines); SDL_zerop(pipelines);
@@ -395,7 +395,7 @@ void MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipeline
MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_ADVANCED], "SDL advanced pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_ADVANCED); MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_ADVANCED], "SDL advanced pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_ADVANCED);
} }
static METAL_ShaderPipelines *ChooseShaderPipelines(METAL_RenderData *data, MTLPixelFormat rtformat) static METAL_ShaderPipelines *ChooseShaderPipelines(SDL3METAL_RenderData *data, MTLPixelFormat rtformat)
{ {
METAL_ShaderPipelines *allpipelines = data.allpipelines; METAL_ShaderPipelines *allpipelines = data.allpipelines;
int count = data.pipelinescount; int count = data.pipelinescount;
@@ -433,7 +433,7 @@ 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(SDL3METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SDL_MetalFragmentFunction fragfn, SDL_BlendMode blendmode)
{ {
METAL_PipelineCache *cache = &pipelines->caches[fragfn]; METAL_PipelineCache *cache = &pipelines->caches[fragfn];
@@ -448,7 +448,7 @@ static inline id<MTLRenderPipelineState> ChoosePipelineState(METAL_RenderData *d
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->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
/* Our SetRenderTarget just signals that the next render operation should /* Our SetRenderTarget just signals that the next render operation should
* set up a new render pass. This is where that work happens. */ * set up a new render pass. This is where that work happens. */
@@ -456,7 +456,7 @@ static SDL_bool METAL_ActivateRenderCommandEncoder(SDL_Renderer *renderer, MTLLo
id<MTLTexture> mtltexture = nil; id<MTLTexture> mtltexture = nil;
if (renderer->target != NULL) { if (renderer->target != NULL) {
METAL_TextureData *texdata = (__bridge METAL_TextureData *)renderer->target->internal; SDL3METAL_TextureData *texdata = (__bridge SDL3METAL_TextureData *)renderer->target->internal;
mtltexture = texdata.mtltexture; mtltexture = texdata.mtltexture;
} else { } else {
if (data.mtlbackbuffer == nil) { if (data.mtlbackbuffer == nil) {
@@ -520,7 +520,7 @@ static void METAL_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *eve
static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
if (w) { if (w) {
*w = (int)data.mtllayer.drawableSize.width; *w = (int)data.mtllayer.drawableSize.width;
} }
@@ -632,11 +632,11 @@ size_t GetYCbCRtoRGBConversionMatrix(SDL_Colorspace colorspace, int w, int h, in
static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
MTLPixelFormat pixfmt; MTLPixelFormat pixfmt;
MTLTextureDescriptor *mtltexdesc; MTLTextureDescriptor *mtltexdesc;
id<MTLTexture> mtltexture = nil, mtltextureUv = nil; id<MTLTexture> mtltexture = nil, mtltextureUv = nil;
METAL_TextureData *texturedata; SDL3METAL_TextureData *texturedata;
CVPixelBufferRef pixelbuffer = nil; CVPixelBufferRef pixelbuffer = nil;
IOSurfaceRef surface = nil; IOSurfaceRef surface = nil;
@@ -746,7 +746,7 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
} }
} }
#endif /* SDL_HAVE_YUV */ #endif /* SDL_HAVE_YUV */
texturedata = [[METAL_TextureData alloc] init]; texturedata = [[SDL3METAL_TextureData alloc] init];
if (SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_SRGB) { if (SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_SRGB) {
texturedata.fragmentFunction = SDL_METAL_FRAGMENT_COPY; texturedata.fragmentFunction = SDL_METAL_FRAGMENT_COPY;
#if SDL_HAVE_YUV #if SDL_HAVE_YUV
@@ -795,11 +795,11 @@ static MTLStorageMode METAL_GetStorageMode(id<MTLResource> resource)
return MTLStorageModeShared; return MTLStorageModeShared;
} }
static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, METAL_TextureData *texturedata, static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, SDL3METAL_TextureData *texturedata,
id<MTLTexture> texture, SDL_Rect rect, int slice, id<MTLTexture> texture, SDL_Rect rect, int slice,
const void *pixels, int pitch) const void *pixels, int pitch)
{ {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
SDL_Rect stagingrect = { 0, 0, rect.w, rect.h }; SDL_Rect stagingrect = { 0, 0, rect.w, rect.h };
MTLTextureDescriptor *desc; MTLTextureDescriptor *desc;
id<MTLTexture> stagingtex; id<MTLTexture> stagingtex;
@@ -867,7 +867,7 @@ static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels, int pitch) const SDL_Rect *rect, const void *pixels, int pitch)
{ {
@autoreleasepool { @autoreleasepool {
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->internal; SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal;
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch) < 0) { if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch) < 0) {
return -1; return -1;
@@ -917,7 +917,7 @@ static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const Uint8 *Vplane, int Vpitch) const Uint8 *Vplane, int Vpitch)
{ {
@autoreleasepool { @autoreleasepool {
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->internal; SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal;
const int Uslice = 0; const int Uslice = 0;
const int Vslice = 1; const int Vslice = 1;
SDL_Rect UVrect = { rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2 }; SDL_Rect UVrect = { rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2 };
@@ -949,7 +949,7 @@ static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
const Uint8 *UVplane, int UVpitch) const Uint8 *UVplane, int UVpitch)
{ {
@autoreleasepool { @autoreleasepool {
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->internal; SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal;
SDL_Rect UVrect = { rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2 }; SDL_Rect UVrect = { rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2 };
/* Bail out if we're supposed to update an empty rectangle */ /* Bail out if we're supposed to update an empty rectangle */
@@ -976,8 +976,8 @@ static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch) const SDL_Rect *rect, void **pixels, int *pitch)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->internal; SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal;
int buffersize = 0; int buffersize = 0;
id<MTLBuffer> lockedbuffer = nil; id<MTLBuffer> lockedbuffer = nil;
@@ -1011,8 +1011,8 @@ static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->internal; SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal;
id<MTLBlitCommandEncoder> blitcmd; id<MTLBlitCommandEncoder> blitcmd;
SDL_Rect rect = texturedata.lockedrect; SDL_Rect rect = texturedata.lockedrect;
int pitch = SDL_BYTESPERPIXEL(texture->format) * rect.w; int pitch = SDL_BYTESPERPIXEL(texture->format) * rect.w;
@@ -1102,7 +1102,7 @@ static void METAL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu
static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
if (data.mtlcmdencoder) { if (data.mtlcmdencoder) {
/* End encoding for the previous render target so we can set up a new /* End encoding for the previous render target so we can set up a new
@@ -1392,7 +1392,7 @@ static void SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand
static SDL_bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_MetalFragmentFunction shader, PixelShaderConstants *shader_constants, const size_t constants_offset, id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache) static SDL_bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_MetalFragmentFunction shader, PixelShaderConstants *shader_constants, const size_t constants_offset, id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache)
{ {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
const SDL_BlendMode blend = cmd->data.draw.blend; const SDL_BlendMode blend = cmd->data.draw.blend;
size_t first = cmd->data.draw.first; size_t first = cmd->data.draw.first;
id<MTLRenderPipelineState> newpipeline; id<MTLRenderPipelineState> newpipeline;
@@ -1484,9 +1484,9 @@ static SDL_bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cm
static SDL_bool SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t constants_offset, static SDL_bool SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t constants_offset,
id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache) id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache)
{ {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
SDL_Texture *texture = cmd->data.draw.texture; SDL_Texture *texture = cmd->data.draw.texture;
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->internal; SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal;
PixelShaderConstants constants; PixelShaderConstants constants;
SetupShaderConstants(renderer, cmd, texture, &constants); SetupShaderConstants(renderer, cmd, texture, &constants);
@@ -1543,7 +1543,7 @@ static void METAL_InvalidateCachedState(SDL_Renderer *renderer)
static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
id<MTLBuffer> mtlbufvertex = nil; id<MTLBuffer> mtlbufvertex = nil;
METAL_DrawStateCache statecache; METAL_DrawStateCache statecache;
SDL_zero(statecache); SDL_zero(statecache);
@@ -1692,7 +1692,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
static SDL_Surface *METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) static SDL_Surface *METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
id<MTLTexture> mtltexture; id<MTLTexture> mtltexture;
MTLRegion mtlregion; MTLRegion mtlregion;
Uint32 format; Uint32 format;
@@ -1757,7 +1757,7 @@ static SDL_Surface *METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
static int METAL_RenderPresent(SDL_Renderer *renderer) static int METAL_RenderPresent(SDL_Renderer *renderer)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
SDL_bool ready = SDL_TRUE; SDL_bool ready = SDL_TRUE;
// If we don't have a command buffer, we can't present, so activate to get one. // If we don't have a command buffer, we can't present, so activate to get one.
@@ -1806,7 +1806,7 @@ static void METAL_DestroyRenderer(SDL_Renderer *renderer)
{ {
@autoreleasepool { @autoreleasepool {
if (renderer->internal) { if (renderer->internal) {
METAL_RenderData *data = CFBridgingRelease(renderer->internal); SDL3METAL_RenderData *data = CFBridgingRelease(renderer->internal);
if (data.mtlcmdencoder != nil) { if (data.mtlcmdencoder != nil) {
[data.mtlcmdencoder endEncoding]; [data.mtlcmdencoder endEncoding];
@@ -1826,7 +1826,7 @@ static void METAL_DestroyRenderer(SDL_Renderer *renderer)
static void *METAL_GetMetalLayer(SDL_Renderer *renderer) static void *METAL_GetMetalLayer(SDL_Renderer *renderer)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
return (__bridge void *)data.mtllayer; return (__bridge void *)data.mtllayer;
} }
} }
@@ -1837,9 +1837,9 @@ static void *METAL_GetMetalCommandEncoder(SDL_Renderer *renderer)
// note that data.mtlcmdencoder can be nil if METAL_ActivateRenderCommandEncoder fails. // note that data.mtlcmdencoder can be nil if METAL_ActivateRenderCommandEncoder fails.
// Before SDL 2.0.18, it might have returned a non-nil encoding that might not have been // Before SDL 2.0.18, it might have returned a non-nil encoding that might not have been
// usable for presentation. Check your return values! // usable for presentation. Check your return values!
METAL_RenderData *data; SDL3METAL_RenderData *data;
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil); METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
data = (__bridge METAL_RenderData *)renderer->internal; data = (__bridge SDL3METAL_RenderData *)renderer->internal;
return (__bridge void *)data.mtlcmdencoder; return (__bridge void *)data.mtlcmdencoder;
} }
} }
@@ -1848,7 +1848,7 @@ static int METAL_SetVSync(SDL_Renderer *renderer, const int vsync)
{ {
#if (defined(SDL_PLATFORM_MACOS) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST #if (defined(SDL_PLATFORM_MACOS) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST
if (@available(macOS 10.13, *)) { if (@available(macOS 10.13, *)) {
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->internal; SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal;
switch (vsync) { switch (vsync) {
case 0: case 0:
data.mtllayer.displaySyncEnabled = NO; data.mtllayer.displaySyncEnabled = NO;
@@ -1903,7 +1903,7 @@ static SDL_MetalView GetWindowView(SDL_Window *window)
static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props)
{ {
@autoreleasepool { @autoreleasepool {
METAL_RenderData *data = NULL; SDL3METAL_RenderData *data = NULL;
id<MTLDevice> mtldevice = nil; id<MTLDevice> mtldevice = nil;
SDL_MetalView view = NULL; SDL_MetalView view = NULL;
CAMetalLayer *layer = nil; CAMetalLayer *layer = nil;
@@ -2012,7 +2012,7 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_
} }
// !!! FIXME: error checking on all of this. // !!! FIXME: error checking on all of this.
data = [[METAL_RenderData alloc] init]; data = [[SDL3METAL_RenderData alloc] init];
if (data == nil) { if (data == nil) {
/* Release the metal view instead of destroying it, /* Release the metal view instead of destroying it,
@@ -2020,7 +2020,7 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_
*/ */
/* SDL_Metal_DestroyView(view); */ /* SDL_Metal_DestroyView(view); */
CFBridgingRelease(view); CFBridgingRelease(view);
return SDL_SetError("METAL_RenderData alloc/init failed"); return SDL_SetError("SDL3METAL_RenderData alloc/init failed");
} }
renderer->internal = (void *)CFBridgingRetain(data); renderer->internal = (void *)CFBridgingRetain(data);

View File

@@ -45,7 +45,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
return sdlwindow; return sdlwindow;
} }
@interface SDLApplication : NSApplication @interface SDL3Application : NSApplication
- (void)terminate:(id)sender; - (void)terminate:(id)sender;
- (void)sendEvent:(NSEvent *)theEvent; - (void)sendEvent:(NSEvent *)theEvent;
@@ -54,7 +54,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
@end @end
@implementation SDLApplication @implementation SDL3Application
// Override terminate to handle Quit and System Shutdown smoothly. // Override terminate to handle Quit and System Shutdown smoothly.
- (void)terminate:(id)sender - (void)terminate:(id)sender
@@ -114,14 +114,14 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
} }
@end // SDLApplication @end // SDL3Application
/* setAppleMenu disappeared from the headers in 10.4 */ /* setAppleMenu disappeared from the headers in 10.4 */
@interface NSApplication (NSAppleMenu) @interface NSApplication (NSAppleMenu)
- (void)setAppleMenu:(NSMenu *)menu; - (void)setAppleMenu:(NSMenu *)menu;
@end @end
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> @interface SDL3AppDelegate : NSObject <NSApplicationDelegate>
{ {
@public @public
BOOL seenFirstActivate; BOOL seenFirstActivate;
@@ -136,7 +136,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app; - (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app;
@end @end
@implementation SDLAppDelegate : NSObject @implementation SDL3AppDelegate : NSObject
- (id)init - (id)init
{ {
self = [super init]; self = [super init];
@@ -330,7 +330,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
/* If we call this before NSApp activation, macOS might print a complaint /* If we call this before NSApp activation, macOS might print a complaint
* about ApplePersistenceIgnoreState. */ * about ApplePersistenceIgnoreState. */
[SDLApplication registerUserDefaults]; [SDL3Application registerUserDefaults];
} }
- (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
@@ -358,7 +358,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
@end @end
static SDLAppDelegate *appDelegate = nil; static SDL3AppDelegate *appDelegate = nil;
static NSString *GetApplicationName(void) static NSString *GetApplicationName(void)
{ {
@@ -490,7 +490,7 @@ void Cocoa_RegisterApp(void)
/* This can get called more than once! Be careful what you initialize! */ /* This can get called more than once! Be careful what you initialize! */
if (NSApp == nil) { if (NSApp == nil) {
[SDLApplication sharedApplication]; [SDL3Application sharedApplication];
SDL_assert(NSApp != nil); SDL_assert(NSApp != nil);
s_bShouldHandleEventsInSDLApplication = SDL_TRUE; s_bShouldHandleEventsInSDLApplication = SDL_TRUE;
@@ -516,11 +516,11 @@ void Cocoa_RegisterApp(void)
/* The SDL app delegate calls this in didFinishLaunching if it's /* The SDL app delegate calls this in didFinishLaunching if it's
* attached to the NSApp, otherwise we need to call it manually. * attached to the NSApp, otherwise we need to call it manually.
*/ */
[SDLApplication registerUserDefaults]; [SDL3Application registerUserDefaults];
} }
} }
if (NSApp && !appDelegate) { if (NSApp && !appDelegate) {
appDelegate = [[SDLAppDelegate alloc] init]; appDelegate = [[SDL3AppDelegate alloc] init];
/* If someone else has an app delegate, it means we can't turn a /* If someone else has an app delegate, it means we can't turn a
* termination into SDL_Quit, and we can't handle application:openFile: * termination into SDL_Quit, and we can't handle application:openFile:
@@ -581,7 +581,7 @@ int Cocoa_PumpEventsUntilDate(SDL_VideoDevice *_this, NSDate *expiration, bool a
Cocoa_DispatchEvent(event); Cocoa_DispatchEvent(event);
} }
// Pass events down to SDLApplication to be handled in sendEvent: // Pass events down to SDL3Application to be handled in sendEvent:
[NSApp sendEvent:event]; [NSApp sendEvent:event];
if (!accumulate) { if (!accumulate) {
break; break;

View File

@@ -33,7 +33,7 @@
/*#define DEBUG_IME NSLog */ /*#define DEBUG_IME NSLog */
#define DEBUG_IME(...) #define DEBUG_IME(...)
@interface SDLTranslatorResponder : NSView <NSTextInputClient> @interface SDL3TranslatorResponder : NSView <NSTextInputClient>
{ {
NSString *_markedText; NSString *_markedText;
NSRange _markedRange; NSRange _markedRange;
@@ -44,7 +44,7 @@
- (void)setInputRect:(const SDL_Rect *)rect; - (void)setInputRect:(const SDL_Rect *)rect;
@end @end
@implementation SDLTranslatorResponder @implementation SDL3TranslatorResponder
- (void)setInputRect:(const SDL_Rect *)rect - (void)setInputRect:(const SDL_Rect *)rect
{ {
@@ -359,7 +359,7 @@ int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window)
* text input, simply remove the field editor from its superview then add * text input, simply remove the field editor from its superview then add
* it to the front most window's content view */ * it to the front most window's content view */
if (!data.fieldEdit) { if (!data.fieldEdit) {
data.fieldEdit = [[SDLTranslatorResponder alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)]; data.fieldEdit = [[SDL3TranslatorResponder alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
} }
if (![[data.fieldEdit superview] isEqual:parentView]) { if (![[data.fieldEdit superview] isEqual:parentView]) {

View File

@@ -24,7 +24,7 @@
#include "SDL_cocoavideo.h" #include "SDL_cocoavideo.h"
@interface SDLMessageBoxPresenter : NSObject @interface SDL3MessageBoxPresenter : NSObject
{ {
@public @public
NSInteger clicked; NSInteger clicked;
@@ -33,7 +33,7 @@
- (id)initWithParentWindow:(SDL_Window *)window; - (id)initWithParentWindow:(SDL_Window *)window;
@end @end
@implementation SDLMessageBoxPresenter @implementation SDL3MessageBoxPresenter
- (id)initWithParentWindow:(SDL_Window *)window - (id)initWithParentWindow:(SDL_Window *)window
{ {
self = [super init]; self = [super init];
@@ -70,7 +70,7 @@ static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, i
{ {
NSAlert *alert; NSAlert *alert;
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
SDLMessageBoxPresenter *presenter; SDL3MessageBoxPresenter *presenter;
NSInteger clicked; NSInteger clicked;
int i; int i;
Cocoa_RegisterApp(); Cocoa_RegisterApp();
@@ -108,7 +108,7 @@ static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, i
} }
} }
presenter = [[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window]; presenter = [[SDL3MessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window];
[presenter showAlert:alert]; [presenter showAlert:alert];

View File

@@ -39,7 +39,7 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
@interface SDL_cocoametalview : NSView @interface SDL3_cocoametalview : NSView
- (instancetype)initWithFrame:(NSRect)frame - (instancetype)initWithFrame:(NSRect)frame
highDPI:(BOOL)highDPI highDPI:(BOOL)highDPI

View File

@@ -41,7 +41,7 @@ static int SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
* exit-space button). */ * exit-space button). */
if (event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) { if (event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
@autoreleasepool { @autoreleasepool {
SDL_cocoametalview *view = (__bridge SDL_cocoametalview *)userdata; SDL3_cocoametalview *view = (__bridge SDL3_cocoametalview *)userdata;
if (view.sdlWindowID == event->window.windowID) { if (view.sdlWindowID == event->window.windowID) {
[view updateDrawableSize]; [view updateDrawableSize];
} }
@@ -50,7 +50,7 @@ static int SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
return 0; return 0;
} }
@implementation SDL_cocoametalview @implementation SDL3_cocoametalview
/* Return a Metal-compatible layer. */ /* Return a Metal-compatible layer. */
+ (Class)layerClass + (Class)layerClass
@@ -138,10 +138,10 @@ SDL_MetalView Cocoa_Metal_CreateView(SDL_VideoDevice *_this, SDL_Window *window)
BOOL highDPI = (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) != 0; BOOL highDPI = (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) != 0;
BOOL opaque = (window->flags & SDL_WINDOW_TRANSPARENT) == 0; BOOL opaque = (window->flags & SDL_WINDOW_TRANSPARENT) == 0;
Uint32 windowID = SDL_GetWindowID(window); Uint32 windowID = SDL_GetWindowID(window);
SDL_cocoametalview *newview; SDL3_cocoametalview *newview;
SDL_MetalView metalview; SDL_MetalView metalview;
newview = [[SDL_cocoametalview alloc] initWithFrame:view.frame newview = [[SDL3_cocoametalview alloc] initWithFrame:view.frame
highDPI:highDPI highDPI:highDPI
windowID:windowID windowID:windowID
opaque:opaque]; opaque:opaque];
@@ -164,7 +164,7 @@ SDL_MetalView Cocoa_Metal_CreateView(SDL_VideoDevice *_this, SDL_Window *window)
void Cocoa_Metal_DestroyView(SDL_VideoDevice *_this, SDL_MetalView view) void Cocoa_Metal_DestroyView(SDL_VideoDevice *_this, SDL_MetalView view)
{ {
@autoreleasepool { @autoreleasepool {
SDL_cocoametalview *metalview = CFBridgingRelease(view); SDL3_cocoametalview *metalview = CFBridgingRelease(view);
[metalview removeFromSuperview]; [metalview removeFromSuperview];
} }
} }
@@ -172,7 +172,7 @@ void Cocoa_Metal_DestroyView(SDL_VideoDevice *_this, SDL_MetalView view)
void *Cocoa_Metal_GetLayer(SDL_VideoDevice *_this, SDL_MetalView view) void *Cocoa_Metal_GetLayer(SDL_VideoDevice *_this, SDL_MetalView view)
{ {
@autoreleasepool { @autoreleasepool {
SDL_cocoametalview *cocoaview = (__bridge SDL_cocoametalview *)view; SDL3_cocoametalview *cocoaview = (__bridge SDL3_cocoametalview *)view;
return (__bridge void *)cocoaview.layer; return (__bridge void *)cocoaview.layer;
} }
} }

View File

@@ -500,7 +500,7 @@ void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event)
data->lastMoveY = location.y; data->lastMoveY = location.y;
DLog("Last seen mouse: (%g, %g)", location.x, location.y); DLog("Last seen mouse: (%g, %g)", location.x, location.y);
/* Non-relative movement is handled in -[Cocoa_WindowListener mouseMoved:] */ /* Non-relative movement is handled in -[SDL3Cocoa_WindowListener mouseMoved:] */
if (!mouse->relative_mode) { if (!mouse->relative_mode) {
return; return;
} }

View File

@@ -39,7 +39,7 @@ struct SDL_GLDriverData
int initialized; int initialized;
}; };
@interface SDLOpenGLContext : NSOpenGLContext @interface SDL3OpenGLContext : NSOpenGLContext
{ {
SDL_AtomicInt dirty; SDL_AtomicInt dirty;
SDL_Window *window; SDL_Window *window;

View File

@@ -61,7 +61,7 @@ static void SDLCALL SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *n
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; SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)displayLinkContext;
/*printf("DISPLAY LINK! %u\n", (unsigned int) SDL_GetTicks()); */ /*printf("DISPLAY LINK! %u\n", (unsigned int) SDL_GetTicks()); */
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting); const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
@@ -75,7 +75,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
return kCVReturnSuccess; return kCVReturnSuccess;
} }
@implementation SDLOpenGLContext : NSOpenGLContext @implementation SDL3OpenGLContext : NSOpenGLContext
- (id)initWithFormat:(NSOpenGLPixelFormat *)format - (id)initWithFormat:(NSOpenGLPixelFormat *)format
shareContext:(NSOpenGLContext *)share shareContext:(NSOpenGLContext *)share
@@ -121,7 +121,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
{ {
const int value = SDL_AtomicSet(&self->dirty, 0); const int value = SDL_AtomicSet(&self->dirty, 0);
if (value > 0) { if (value > 0) {
/* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */ /* We call the real underlying update here, since -[SDL3OpenGLContext update] just calls us. */
[self explicitUpdate]; [self explicitUpdate];
} }
} }
@@ -261,7 +261,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt; NSOpenGLPixelFormat *fmt;
SDLOpenGLContext *context; SDL3OpenGLContext *context;
SDL_GLContext sdlcontext; SDL_GLContext sdlcontext;
NSOpenGLContext *share_context = nil; NSOpenGLContext *share_context = nil;
int i = 0; int i = 0;
@@ -369,7 +369,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
share_context = (__bridge NSOpenGLContext *)SDL_GL_GetCurrentContext(); share_context = (__bridge NSOpenGLContext *)SDL_GL_GetCurrentContext();
} }
context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context]; context = [[SDL3OpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
if (context == nil) { if (context == nil) {
SDL_SetError("Failed creating OpenGL context"); SDL_SetError("Failed creating OpenGL context");
@@ -439,7 +439,7 @@ int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLConte
{ {
@autoreleasepool { @autoreleasepool {
if (context) { if (context) {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context; SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)context;
if ([nscontext window] != window) { if ([nscontext window] != window) {
[nscontext setWindow:window]; [nscontext setWindow:window];
[nscontext updateIfNeeded]; [nscontext updateIfNeeded];
@@ -456,7 +456,7 @@ int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLConte
int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{ {
@autoreleasepool { @autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)SDL_GL_GetCurrentContext(); SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext();
int status; int status;
if (nscontext == nil) { if (nscontext == nil) {
@@ -476,7 +476,7 @@ int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
{ {
@autoreleasepool { @autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)SDL_GL_GetCurrentContext(); SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext();
if (nscontext) { if (nscontext) {
*interval = SDL_AtomicGet(&nscontext->swapIntervalSetting); *interval = SDL_AtomicGet(&nscontext->swapIntervalSetting);
return 0; return 0;
@@ -489,7 +489,7 @@ int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)SDL_GL_GetCurrentContext(); SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext();
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->internal; SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->internal;
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting); const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
@@ -526,7 +526,7 @@ int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
int Cocoa_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) int Cocoa_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
{ {
@autoreleasepool { @autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context; SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)context;
[nscontext cleanup]; [nscontext cleanup];
CFRelease(context); CFRelease(context);
} }

View File

@@ -94,14 +94,14 @@ DECLARE_ALERT_STYLE(Critical);
/* Private display data */ /* Private display data */
@class SDLTranslatorResponder; @class SDL3TranslatorResponder;
@interface SDL_CocoaVideoData : NSObject @interface SDL_CocoaVideoData : NSObject
@property(nonatomic) int allow_spaces; @property(nonatomic) int allow_spaces;
@property(nonatomic) int trackpad_is_touch_only; @property(nonatomic) int trackpad_is_touch_only;
@property(nonatomic) unsigned int modifierFlags; @property(nonatomic) unsigned int modifierFlags;
@property(nonatomic) void *key_layout; @property(nonatomic) void *key_layout;
@property(nonatomic) SDLTranslatorResponder *fieldEdit; @property(nonatomic) SDL3TranslatorResponder *fieldEdit;
@property(nonatomic) NSInteger clipboard_count; @property(nonatomic) NSInteger clipboard_count;
@property(nonatomic) IOPMAssertionID screensaver_assertion; @property(nonatomic) IOPMAssertionID screensaver_assertion;
@property(nonatomic) SDL_Mutex *swaplock; @property(nonatomic) SDL_Mutex *swaplock;

View File

@@ -41,7 +41,7 @@ typedef enum
PENDING_OPERATION_MINIMIZE = 0x04 PENDING_OPERATION_MINIMIZE = 0x04
} PendingWindowOperation; } PendingWindowOperation;
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> @interface SDL3Cocoa_WindowListener : NSResponder <NSWindowDelegate>
{ {
/* SDL_CocoaWindowData owns this Listener and has a strong reference to it. /* SDL_CocoaWindowData owns this Listener and has a strong reference to it.
* To avoid reference cycles, we could have either a weak or an * To avoid reference cycles, we could have either a weak or an
@@ -124,7 +124,7 @@ typedef enum
@end @end
/* *INDENT-ON* */ /* *INDENT-ON* */
@class SDLOpenGLContext; @class SDL3OpenGLContext;
@class SDL_CocoaVideoData; @class SDL_CocoaVideoData;
@interface SDL_CocoaWindowData : NSObject @interface SDL_CocoaWindowData : NSObject
@@ -137,7 +137,7 @@ typedef enum
@property(nonatomic) NSInteger window_number; @property(nonatomic) NSInteger window_number;
@property(nonatomic) NSInteger flash_request; @property(nonatomic) NSInteger flash_request;
@property(nonatomic) SDL_Window *keyboard_focus; @property(nonatomic) SDL_Window *keyboard_focus;
@property(nonatomic) Cocoa_WindowListener *listener; @property(nonatomic) SDL3Cocoa_WindowListener *listener;
@property(nonatomic) NSModalSession modal_session; @property(nonatomic) NSModalSession modal_session;
@property(nonatomic) SDL_CocoaVideoData *videodata; @property(nonatomic) SDL_CocoaVideoData *videodata;
@property(nonatomic) SDL_bool send_floating_size; @property(nonatomic) SDL_bool send_floating_size;

View File

@@ -73,7 +73,7 @@
@property(nonatomic) NSRect mouseConfinementRect; @property(nonatomic) NSRect mouseConfinementRect;
@end @end
@interface SDLWindow : NSWindow <NSDraggingDestination> @interface SDL3Window : NSWindow <NSDraggingDestination>
/* These are needed for borderless/fullscreen windows */ /* These are needed for borderless/fullscreen windows */
- (BOOL)canBecomeKeyWindow; - (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow; - (BOOL)canBecomeMainWindow;
@@ -90,7 +90,7 @@
- (SDL_Window *)findSDLWindow; - (SDL_Window *)findSDLWindow;
@end @end
@implementation SDLWindow @implementation SDL3Window
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{ {
@@ -140,7 +140,7 @@
} }
delegate = [self delegate]; delegate = [self delegate];
if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) { if (![delegate isKindOfClass:[SDL3Cocoa_WindowListener class]]) {
return; return;
} }
@@ -418,7 +418,7 @@ static void ScheduleContextUpdates(SDL_CocoaWindowData *data)
currentContext = [NSOpenGLContext currentContext]; currentContext = [NSOpenGLContext currentContext];
contexts = data.nscontexts; contexts = data.nscontexts;
@synchronized(contexts) { @synchronized(contexts) {
for (SDLOpenGLContext *context in contexts) { for (SDL3OpenGLContext *context in contexts) {
if (context == currentContext) { if (context == currentContext) {
[context update]; [context update];
} else { } else {
@@ -672,7 +672,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
return [NSCursor invisibleCursor]; return [NSCursor invisibleCursor];
} }
@implementation Cocoa_WindowListener @implementation SDL3Cocoa_WindowListener
- (void)listen:(SDL_CocoaWindowData *)data - (void)listen:(SDL_CocoaWindowData *)data
{ {
@@ -994,7 +994,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
- (void)windowWillMove:(NSNotification *)aNotification - (void)windowWillMove:(NSNotification *)aNotification
{ {
if ([_data.nswindow isKindOfClass:[SDLWindow class]]) { if ([_data.nswindow isKindOfClass:[SDL3Window class]]) {
pendingWindowWarpX = pendingWindowWarpY = FLT_MAX; pendingWindowWarpX = pendingWindowWarpY = FLT_MAX;
isMoving = YES; isMoving = YES;
} }
@@ -1245,7 +1245,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
if (_data && _data.nscontexts) { if (_data && _data.nscontexts) {
for (SDLOpenGLContext *context in _data.nscontexts) { for (SDL3OpenGLContext *context in _data.nscontexts) {
[context movedToNewScreen]; [context movedToNewScreen];
} }
} }
@@ -1894,7 +1894,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
@end @end
@interface SDLView : NSView @interface SDL3View : NSView
{ {
SDL_Window *_sdlWindow; SDL_Window *_sdlWindow;
} }
@@ -1910,7 +1910,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
- (void)updateLayer; - (void)updateLayer;
@end @end
@implementation SDLView @implementation SDL3View
- (void)setSDLWindow:(SDL_Window *)window - (void)setSDLWindow:(SDL_Window *)window
{ {
@@ -2007,7 +2007,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
data.sdlContentView = nsview; data.sdlContentView = nsview;
/* Create an event listener for the window */ /* Create an event listener for the window */
data.listener = [[Cocoa_WindowListener alloc] init]; data.listener = [[SDL3Cocoa_WindowListener alloc] init];
/* Fill in the SDL window with the window data */ /* Fill in the SDL window with the window data */
{ {
@@ -2157,7 +2157,7 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
NSScreen *screen; NSScreen *screen;
NSRect rect, screenRect; NSRect rect, screenRect;
NSUInteger style; NSUInteger style;
SDLView *contentView; SDL3View *contentView;
SDL_RelativeToGlobalForWindow(window, window->x, window->y, &x, &y); SDL_RelativeToGlobalForWindow(window, window->x, window->y, &x, &y);
rect.origin.x = x; rect.origin.x = x;
@@ -2187,7 +2187,7 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
} }
@try { @try {
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen]; nswindow = [[SDL3Window alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
} }
@catch (NSException *e) { @catch (NSException *e) {
return SDL_SetError("%s", [[e reason] UTF8String]); return SDL_SetError("%s", [[e reason] UTF8String]);
@@ -2212,7 +2212,7 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
/* Create a default view for this window */ /* Create a default view for this window */
rect = [nswindow contentRectForFrameRect:[nswindow frame]]; rect = [nswindow contentRectForFrameRect:[nswindow frame]];
contentView = [[SDLView alloc] initWithFrame:rect]; contentView = [[SDL3View alloc] initWithFrame:rect];
[contentView setSDLWindow:window]; [contentView setSDLWindow:window];
nsview = contentView; nsview = contentView;
} }
@@ -2651,7 +2651,7 @@ void Cocoa_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bo
* -flibit * -flibit
*/ */
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
Cocoa_WindowListener *listener = data.listener; SDL3Cocoa_WindowListener *listener = data.listener;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
SDL_CocoaVideoData *videodata = data.videodata; SDL_CocoaVideoData *videodata = data.videodata;
if (![listener isInFullscreenSpace] && ![listener isInFullscreenSpaceTransition]) { if (![listener isInFullscreenSpace] && ![listener isInFullscreenSpaceTransition]) {
@@ -2951,7 +2951,7 @@ void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
contexts = [data.nscontexts copy]; contexts = [data.nscontexts copy];
for (SDLOpenGLContext *context in contexts) { for (SDL3OpenGLContext *context in contexts) {
/* Calling setWindow:NULL causes the context to remove itself from the context list. */ /* Calling setWindow:NULL causes the context to remove itself from the context list. */
[context setWindow:NULL]; [context setWindow:NULL];
} }