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
- (void)tick_callback;
- (void)render_frame_received:(id)displayIDAsID;
@end
extern void dispatchCustomEvent(NSEvent *event);
@implementation GLFWApplication
- (void)sendEvent:(NSEvent *)event {
if (event.type == NSEventTypeApplicationDefined) {
dispatchCustomEvent(event);
} else [super sendEvent:event];
}
- (void)tick_callback
{
_glfwDispatchTickCallback();
}
- (void)render_frame_received:(id)displayIDAsID
{
CGDirectDisplayID displayID = [(NSNumber*)displayIDAsID unsignedIntValue];
_glfwDispatchRenderFrame(displayID);
}
@end
//////////////////////////////////////////////////////////////////////////

View File

@ -277,7 +277,9 @@ static CVReturn displayLinkCallback(
}
[_glfw.ns.displayLinks.lock unlock];
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;
}

View File

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

View File

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