Cocoa: User performSelectorOnMainLoop for render frames as well which means render frames work during modal loops

This commit is contained in:
Kovid Goyal 2019-03-21 16:51:01 +05:30
parent 0dc6ac26c3
commit fcb26e5dc7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 37 deletions

View File

@ -296,21 +296,20 @@ static GLFWbool initializeTIS(void)
@interface GLFWApplication : NSApplication @interface GLFWApplication : NSApplication
- (void)tick_callback; - (void)tick_callback;
- (void)render_frame_received:(id)displayIDAsID;
@end @end
extern void dispatchCustomEvent(NSEvent *event);
@implementation GLFWApplication @implementation GLFWApplication
- (void)sendEvent:(NSEvent *)event {
if (event.type == NSEventTypeApplicationDefined) {
dispatchCustomEvent(event);
} else [super sendEvent:event];
}
- (void)tick_callback - (void)tick_callback
{ {
_glfwDispatchTickCallback(); _glfwDispatchTickCallback();
} }
- (void)render_frame_received:(id)displayIDAsID
{
CGDirectDisplayID displayID = [(NSNumber*)displayIDAsID unsignedIntValue];
_glfwDispatchRenderFrame(displayID);
}
@end @end
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View File

@ -277,7 +277,9 @@ static CVReturn displayLinkCallback(
} }
[_glfw.ns.displayLinks.lock unlock]; [_glfw.ns.displayLinks.lock unlock];
if (notify) { if (notify) {
_glfwCocoaPostEmptyEvent(RENDER_FRAME_REQUEST_EVENT_TYPE, displayID, true); NSNumber *arg = [NSNumber numberWithUnsignedInt:displayID];
[NSApp performSelectorOnMainThread:@selector(render_frame_received:) withObject:arg waitUntilDone:NO];
[arg release];
} }
return kCVReturnSuccess; return kCVReturnSuccess;
} }

View File

@ -36,12 +36,6 @@ typedef void* id;
typedef void* CVDisplayLinkRef; typedef void* CVDisplayLinkRef;
#endif #endif
typedef enum {
EMPTY_EVENT_TYPE,
RENDER_FRAME_REQUEST_EVENT_TYPE,
} EventTypes;
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int, unsigned long); typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int, unsigned long);
typedef int (* GLFWapplicationshouldhandlereopenfun)(int); typedef int (* GLFWapplicationshouldhandlereopenfun)(int);
@ -205,3 +199,4 @@ float _glfwTransformYNS(float y);
void _glfwClearDisplayLinks(); void _glfwClearDisplayLinks();
void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start); void _glfwCocoaPostEmptyEvent(short subtype, long data1, bool at_start);
void _glfwDispatchTickCallback(); void _glfwDispatchTickCallback();
void _glfwDispatchRenderFrame(CGDirectDisplayID);

View File

@ -1741,7 +1741,7 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
[window->ns.object setAlphaValue:opacity]; [window->ns.object setAlphaValue:opacity];
} }
static inline CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) { CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) {
NSWindow *nw = w->ns.object; NSWindow *nw = w->ns.object;
NSDictionary *dict = [nw.screen deviceDescription]; NSDictionary *dict = [nw.screen deviceDescription];
NSNumber *displayIDns = [dict objectForKey:@"NSScreenNumber"]; NSNumber *displayIDns = [dict objectForKey:@"NSScreenNumber"];
@ -1750,11 +1750,7 @@ static inline CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) {
} }
void void
dispatchCustomEvent(NSEvent *event) { _glfwDispatchRenderFrame(CGDirectDisplayID displayID) {
switch(event.subtype) {
case RENDER_FRAME_REQUEST_EVENT_TYPE:
{
CGDirectDisplayID displayID = (CGDirectDisplayID)event.data1;
_GLFWwindow *w = _glfw.windowListHead; _GLFWwindow *w = _glfw.windowListHead;
while (w) { while (w) {
if (w->ns.renderFrameRequested && displayID == displayIDForWindow(w)) { if (w->ns.renderFrameRequested && displayID == displayIDForWindow(w)) {
@ -1764,15 +1760,6 @@ dispatchCustomEvent(NSEvent *event) {
w = w->next; w = w->next;
} }
} }
break;
case EMPTY_EVENT_TYPE:
break;
default:
break;
}
}
static inline void static inline void
requestRenderFrame(_GLFWwindow *w, GLFWcocoarenderframefun callback) { requestRenderFrame(_GLFWwindow *w, GLFWcocoarenderframefun callback) {