Merge pull request #17922 from warmenhoven/warmenhoven/pr/macos-run
macOS: use CFRunLoopObserver for running runloop
This commit is contained in:
commit
8cfdfebb03
|
@ -96,6 +96,56 @@ void cocoa_file_load_with_detect_core(const char *filename);
|
|||
@end
|
||||
#endif
|
||||
|
||||
static CFRunLoopObserverRef iterate_observer;
|
||||
|
||||
static void rarch_draw_observer(CFRunLoopObserverRef observer,
|
||||
CFRunLoopActivity activity, void *info)
|
||||
{
|
||||
uint32_t runloop_flags;
|
||||
int ret = runloop_iterate();
|
||||
|
||||
if (ret == -1)
|
||||
{
|
||||
#ifdef HAVE_QT
|
||||
application->quit();
|
||||
#endif
|
||||
main_exit(NULL);
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
task_queue_check();
|
||||
|
||||
#ifdef HAVE_MIST
|
||||
steam_poll();
|
||||
#endif
|
||||
|
||||
runloop_flags = runloop_get_flags();
|
||||
if (!(runloop_flags & RUNLOOP_FLAG_IDLE))
|
||||
CFRunLoopWakeUp(CFRunLoopGetMain());
|
||||
}
|
||||
|
||||
void rarch_start_draw_observer(void)
|
||||
{
|
||||
if (iterate_observer && CFRunLoopObserverIsValid(iterate_observer))
|
||||
return;
|
||||
|
||||
if (iterate_observer != NULL)
|
||||
CFRelease(iterate_observer);
|
||||
iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting,
|
||||
true, 0, rarch_draw_observer, 0);
|
||||
CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes);
|
||||
}
|
||||
|
||||
void rarch_stop_draw_observer(void)
|
||||
{
|
||||
if (!iterate_observer || !CFRunLoopObserverIsValid(iterate_observer))
|
||||
return;
|
||||
CFRunLoopObserverInvalidate(iterate_observer);
|
||||
CFRelease(iterate_observer);
|
||||
iterate_observer = NULL;
|
||||
}
|
||||
|
||||
@implementation CocoaView
|
||||
|
||||
#if defined(OSX)
|
||||
|
|
|
@ -642,7 +642,13 @@ static ui_application_t ui_application_cocoa = {
|
|||
[self setupMainWindow];
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QT
|
||||
/* I think the draw observer should be absolutely fine for qt but I'm not testing it;
|
||||
* whoever does test it and confirm it works can just delete this */
|
||||
[self performSelectorOnMainThread:@selector(rarch_main) withObject:nil waitUntilDone:NO];
|
||||
#else
|
||||
rarch_start_draw_observer();
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma mark - ApplePlatform
|
||||
|
@ -788,6 +794,7 @@ static ui_application_t ui_application_cocoa = {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QT
|
||||
- (void) rarch_main
|
||||
{
|
||||
for (;;)
|
||||
|
@ -822,6 +829,7 @@ static ui_application_t ui_application_cocoa = {
|
|||
|
||||
main_exit(NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification { }
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification
|
||||
|
@ -839,6 +847,8 @@ static ui_application_t ui_application_cocoa = {
|
|||
|
||||
command_event(CMD_EVENT_QUIT, NULL);
|
||||
|
||||
rarch_stop_draw_observer();
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,6 @@ id<ApplePlatform> apple_platform;
|
|||
#else
|
||||
static id apple_platform;
|
||||
#endif
|
||||
static CFRunLoopObserverRef iterate_observer;
|
||||
|
||||
static void ui_companion_cocoatouch_event_command(
|
||||
void *data, enum event_command cmd) { }
|
||||
|
@ -148,49 +147,6 @@ static uintptr_t ui_companion_cocoatouch_get_app_icon_texture(const char *icon)
|
|||
return [textures[iconName] unsignedLongValue];
|
||||
}
|
||||
|
||||
static void rarch_draw_observer(CFRunLoopObserverRef observer,
|
||||
CFRunLoopActivity activity, void *info)
|
||||
{
|
||||
uint32_t runloop_flags;
|
||||
int ret = runloop_iterate();
|
||||
|
||||
if (ret == -1)
|
||||
{
|
||||
ui_companion_cocoatouch_event_command(
|
||||
NULL, CMD_EVENT_MENU_SAVE_CURRENT_CONFIG);
|
||||
main_exit(NULL);
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
task_queue_check();
|
||||
|
||||
runloop_flags = runloop_get_flags();
|
||||
if (!(runloop_flags & RUNLOOP_FLAG_IDLE))
|
||||
CFRunLoopWakeUp(CFRunLoopGetMain());
|
||||
}
|
||||
|
||||
void rarch_start_draw_observer(void)
|
||||
{
|
||||
if (iterate_observer && CFRunLoopObserverIsValid(iterate_observer))
|
||||
return;
|
||||
|
||||
if (iterate_observer != NULL)
|
||||
CFRelease(iterate_observer);
|
||||
iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting,
|
||||
true, 0, rarch_draw_observer, 0);
|
||||
CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes);
|
||||
}
|
||||
|
||||
void rarch_stop_draw_observer(void)
|
||||
{
|
||||
if (!iterate_observer || !CFRunLoopObserverIsValid(iterate_observer))
|
||||
return;
|
||||
CFRunLoopObserverInvalidate(iterate_observer);
|
||||
CFRelease(iterate_observer);
|
||||
iterate_observer = NULL;
|
||||
}
|
||||
|
||||
void get_ios_version(int *major, int *minor)
|
||||
{
|
||||
static int savedMajor, savedMinor;
|
||||
|
|
Loading…
Reference in New Issue