summaryrefslogtreecommitdiff
path: root/Source/3rdParty/SDL2/src/video/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'Source/3rdParty/SDL2/src/video/cocoa')
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaevents.m4
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.h8
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.m65
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamouse.m10
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamousetap.m9
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaopengl.m16
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.h2
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.m9
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavulkan.m23
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.h1
-rw-r--r--Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.m38
11 files changed, 125 insertions, 60 deletions
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaevents.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaevents.m
index 38f4ba6..76d235e 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaevents.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaevents.m
@@ -390,8 +390,8 @@ Cocoa_RegisterApp(void)
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
- }
-
+ }
+
if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.h b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.h
index c0a582f..185d45d 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.h
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.h
@@ -39,16 +39,16 @@
#define METALVIEW_TAG 255
-@interface SDL_cocoametalview : NSView {
- NSInteger _tag;
-}
+@interface SDL_cocoametalview : NSView
- (instancetype)initWithFrame:(NSRect)frame
- scale:(CGFloat)scale;
+ highDPI:(BOOL)highDPI;
/* Override superclass tag so this class can set it. */
@property (assign, readonly) NSInteger tag;
+@property (nonatomic) BOOL highDPI;
+
@end
SDL_cocoametalview* Cocoa_Mtl_AddMetalView(SDL_Window* window);
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.m
index e9c08a0..9447fb8 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoametalview.m
@@ -33,13 +33,10 @@
@implementation SDL_cocoametalview
-/* The synthesized getter should be called by super's viewWithTag. */
-@synthesize tag = _tag;
-
/* Return a Metal-compatible layer. */
+ (Class)layerClass
{
- return NSClassFromString(@"CAMetalLayer");
+ return NSClassFromString(@"CAMetalLayer");
}
/* Indicate the view wants to draw using a backing layer instead of drawRect. */
@@ -57,28 +54,48 @@
}
- (instancetype)initWithFrame:(NSRect)frame
- scale:(CGFloat)scale
+ highDPI:(BOOL)highDPI
{
- if ((self = [super initWithFrame:frame])) {
- _tag = METALVIEW_TAG;
+ if ((self = [super initWithFrame:frame])) {
+ self.highDPI = highDPI;
self.wantsLayer = YES;
/* Allow resize. */
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- /* Set the desired scale. The default drawableSize of a CAMetalLayer
- * is its bounds x its scale so nothing further needs to be done.
- */
- self.layer.contentsScale = scale;
- }
+ [self updateDrawableSize];
+ }
- return self;
+ return self;
+}
+
+- (NSInteger)tag
+{
+ return METALVIEW_TAG;
+}
+
+- (void)updateDrawableSize
+{
+ CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
+ CGSize size = self.bounds.size;
+ CGSize backingSize = size;
+
+ if (self.highDPI) {
+ /* Note: NSHighResolutionCapable must be set to true in the app's
+ * Info.plist in order for the backing size to be high res.
+ */
+ backingSize = [self convertSizeToBacking:size];
+ }
+
+ metalLayer.contentsScale = backingSize.height / size.height;
+ metalLayer.drawableSize = backingSize;
}
/* Set the size of the metal drawables when the view is resized. */
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
{
[super resizeWithOldSuperviewSize:oldSize];
+ [self updateDrawableSize];
}
@end
@@ -88,24 +105,10 @@ Cocoa_Mtl_AddMetalView(SDL_Window* window)
{
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data->nswindow.contentView;
- CGFloat scale = 1.0;
-
- if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
- /* Set the scale to the natural scale factor of the screen - then
- * the backing dimensions of the Metal view will match the pixel
- * dimensions of the screen rather than the dimensions in points
- * yielding high resolution on retine displays.
- *
- * N.B. In order for backingScaleFactor to be > 1,
- * NSHighResolutionCapable must be set to true in the app's Info.plist.
- */
- NSWindow* nswindow = data->nswindow;
- if ([nswindow.screen respondsToSelector:@selector(backingScaleFactor)])
- scale = data->nswindow.screen.backingScaleFactor;
- }
-
- SDL_cocoametalview *metalview
- = [[SDL_cocoametalview alloc] initWithFrame:view.frame scale:scale];
+ BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
+ SDL_cocoametalview *metalview;
+
+ metalview = [[SDL_cocoametalview alloc] initWithFrame:view.frame highDPI:highDPI];
[view addSubview:metalview];
return metalview;
}
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamouse.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamouse.m
index 029a318..c9db253 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamouse.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamouse.m
@@ -432,6 +432,16 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
}
}
+ if (x > 0) {
+ x = SDL_ceil(x);
+ } else if (x < 0) {
+ x = SDL_floor(x);
+ }
+ if (y > 0) {
+ y = SDL_ceil(y);
+ } else if (y < 0) {
+ y = SDL_floor(y);
+ }
SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
}
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamousetap.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamousetap.m
index 3c4fcf2..aa4f152 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamousetap.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoamousetap.m
@@ -211,7 +211,7 @@ Cocoa_InitMouseEventTap(SDL_MouseData* driverdata)
tapdata->thread = SDL_CreateThreadInternal(&Cocoa_MouseTapThread, "Event Tap Loop", 512 * 1024, tapdata);
if (tapdata->thread) {
/* Success - early out. Ownership transferred to thread. */
- return;
+ return;
}
CFRelease(tapdata->tap);
}
@@ -237,6 +237,13 @@ Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
int status;
+ if (tapdata == NULL) {
+ /* event tap was already cleaned up (possibly due to CGEventTapCreate
+ * returning null.)
+ */
+ return;
+ }
+
/* Ensure that the runloop has been started first.
* TODO: Move this to InitMouseEventTap, check for error conditions that can
* happen in Cocoa_MouseTapThread, and fall back to the non-EventTap way of
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaopengl.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaopengl.m
index 5f18a2e..9539c17 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaopengl.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoaopengl.m
@@ -347,10 +347,12 @@ Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
NSView *contentView = [windata->nswindow contentView];
NSRect viewport = [contentView bounds];
- /* This gives us the correct viewport for a Retina-enabled view, only
- * supported on 10.7+. */
- if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
- viewport = [contentView convertRectToBacking:viewport];
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ /* This gives us the correct viewport for a Retina-enabled view, only
+ * supported on 10.7+. */
+ if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
+ viewport = [contentView convertRectToBacking:viewport];
+ }
}
if (w) {
@@ -408,8 +410,14 @@ Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+
+ /* on 10.14 ("Mojave") and later, this deadlocks if two contexts in two
+ threads try to swap at the same time, so put a mutex around it. */
+ SDL_LockMutex(videodata->swaplock);
[nscontext flushBuffer];
[nscontext updateIfNeeded];
+ SDL_UnlockMutex(videodata->swaplock);
return 0;
}}
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.h b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.h
index 05bbd34..b1c26fa 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.h
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.h
@@ -107,7 +107,7 @@ typedef struct SDL_VideoData
Uint32 screensaver_activity;
BOOL screensaver_use_iopm;
IOPMAssertionID screensaver_assertion;
-
+ SDL_mutex *swaplock;
} SDL_VideoData;
/* Utility functions */
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.m
index 545dc1e..20bdfa7 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavideo.m
@@ -105,6 +105,7 @@ Cocoa_CreateDevice(int devindex)
device->DestroyWindow = Cocoa_DestroyWindow;
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
device->SetWindowHitTest = Cocoa_SetWindowHitTest;
+ device->AcceptDragAndDrop = Cocoa_AcceptDragAndDrop;
device->shape_driver.CreateShaper = Cocoa_CreateShaper;
device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
@@ -174,15 +175,23 @@ Cocoa_VideoInit(_THIS)
/* The IOPM assertion API can disable the screensaver as of 10.7. */
data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
+ data->swaplock = SDL_CreateMutex();
+ if (!data->swaplock) {
+ return -1;
+ }
+
return 0;
}
void
Cocoa_VideoQuit(_THIS)
{
+ SDL_VideoData *data = (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 */
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavulkan.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavulkan.m
index 2cf55bb..0e53d21 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavulkan.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoavulkan.m
@@ -58,8 +58,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if (_this->vulkan_config.loader_handle) {
- SDL_SetError("Vulkan/MoltenVK already loaded");
- return -1;
+ return SDL_SetError("Vulkan/MoltenVK already loaded");
}
/* Load the Vulkan loader library */
@@ -80,6 +79,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
_this->vulkan_config.loader_handle = DEFAULT_HANDLE;
} else {
const char** paths;
+ const char *foundPath = NULL;
int numPaths;
int i;
@@ -92,18 +92,17 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
paths = defaultPaths;
numPaths = SDL_arraysize(defaultPaths);
}
-
- for (i=0; i < numPaths; i++) {
- _this->vulkan_config.loader_handle = SDL_LoadObject(paths[i]);
- if (_this->vulkan_config.loader_handle)
- break;
- else
- continue;
+
+ for (i = 0; i < numPaths && _this->vulkan_config.loader_handle == NULL; i++) {
+ foundPath = paths[i];
+ _this->vulkan_config.loader_handle = SDL_LoadObject(foundPath);
+ }
+
+ if (_this->vulkan_config.loader_handle == NULL) {
+ return SDL_SetError("Failed to load Vulkan/MoltenVK library");
}
- if (i == numPaths)
- return -1;
- SDL_strlcpy(_this->vulkan_config.loader_path, paths[i],
+ SDL_strlcpy(_this->vulkan_config.loader_path, foundPath,
SDL_arraysize(_this->vulkan_config.loader_path));
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
_this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.h b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.h
index df6f173..2311e3d 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.h
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.h
@@ -148,6 +148,7 @@ extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info);
extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
+extern void Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
#endif /* SDL_cocoawindow_h_ */
diff --git a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.m b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.m
index b1a5b46..a8e95cc 100644
--- a/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.m
+++ b/Source/3rdParty/SDL2/src/video/cocoa/SDL_cocoawindow.m
@@ -241,7 +241,7 @@ ScheduleContextUpdates(SDL_WindowData *data)
static int
GetHintCtrlClickEmulateRightClick()
{
- return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
+ return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
}
static NSUInteger
@@ -908,7 +908,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
switch ([theEvent buttonNumber]) {
case 0:
if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
- GetHintCtrlClickEmulateRightClick()) {
+ GetHintCtrlClickEmulateRightClick()) {
wasCtrlLeft = YES;
button = SDL_BUTTON_RIGHT;
} else {
@@ -1143,14 +1143,18 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (BOOL)mouseDownCanMoveWindow;
- (void)drawRect:(NSRect)dirtyRect;
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
+- (BOOL)wantsUpdateLayer;
+- (void)updateLayer;
@end
@implementation SDLView
+
- (void)setSDLWindow:(SDL_Window*)window
{
_sdlWindow = window;
}
+/* this is used on older macOS revisions. 10.8 and later use updateLayer. */
- (void)drawRect:(NSRect)dirtyRect
{
/* Force the graphics context to clear to black so we don't get a flash of
@@ -1161,6 +1165,21 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
}
+-(BOOL) wantsUpdateLayer
+{
+ return YES;
+}
+
+-(void) updateLayer
+{
+ /* Force the graphics context to clear to black so we don't get a flash of
+ white until the app is ready to draw. In practice on modern macOS, this
+ only gets called for window creation and other extraordinary events. */
+ self.layer.backgroundColor = NSColor.blackColor.CGColor;
+ ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata);
+ SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
+}
+
- (void)rightMouseDown:(NSEvent *)theEvent
{
[[self nextResponder] rightMouseDown:theEvent];
@@ -1343,6 +1362,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
[contentView setWantsBestResolutionOpenGLSurface:YES];
}
}
+
#if SDL_VIDEO_OPENGL_ES2
#if SDL_VIDEO_OPENGL_EGL
if ((window->flags & SDL_WINDOW_OPENGL) &&
@@ -1354,9 +1374,6 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
[nswindow setContentView:contentView];
[contentView release];
- /* Allow files and folders to be dragged onto the window by users */
- [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
-
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
[nswindow release];
return -1;
@@ -1864,6 +1881,17 @@ 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)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ if (accept) {
+ [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
+ } else {
+ [data->nswindow unregisterDraggedTypes];
+ }
+}
+
int
Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
{