Merge pull request #17922 from warmenhoven/warmenhoven/pr/macos-run

macOS: use CFRunLoopObserver for running runloop
This commit is contained in:
LibretroAdmin 2025-05-21 10:16:22 +02:00 committed by GitHub
commit 8cfdfebb03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 44 deletions

View File

@ -96,6 +96,56 @@ void cocoa_file_load_with_detect_core(const char *filename);
@end @end
#endif #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 @implementation CocoaView
#if defined(OSX) #if defined(OSX)

View File

@ -642,7 +642,13 @@ static ui_application_t ui_application_cocoa = {
[self setupMainWindow]; [self setupMainWindow];
#endif #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]; [self performSelectorOnMainThread:@selector(rarch_main) withObject:nil waitUntilDone:NO];
#else
rarch_start_draw_observer();
#endif
} }
#pragma mark - ApplePlatform #pragma mark - ApplePlatform
@ -788,6 +794,7 @@ static ui_application_t ui_application_cocoa = {
} }
#endif #endif
#ifdef HAVE_QT
- (void) rarch_main - (void) rarch_main
{ {
for (;;) for (;;)
@ -822,6 +829,7 @@ static ui_application_t ui_application_cocoa = {
main_exit(NULL); main_exit(NULL);
} }
#endif
- (void)applicationDidBecomeActive:(NSNotification *)notification { } - (void)applicationDidBecomeActive:(NSNotification *)notification { }
- (void)applicationWillResignActive:(NSNotification *)notification - (void)applicationWillResignActive:(NSNotification *)notification
@ -839,6 +847,8 @@ static ui_application_t ui_application_cocoa = {
command_event(CMD_EVENT_QUIT, NULL); command_event(CMD_EVENT_QUIT, NULL);
rarch_stop_draw_observer();
return reply; return reply;
} }

View File

@ -62,7 +62,6 @@ id<ApplePlatform> apple_platform;
#else #else
static id apple_platform; static id apple_platform;
#endif #endif
static CFRunLoopObserverRef iterate_observer;
static void ui_companion_cocoatouch_event_command( static void ui_companion_cocoatouch_event_command(
void *data, enum event_command cmd) { } 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]; 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) void get_ios_version(int *major, int *minor)
{ {
static int savedMajor, savedMinor; static int savedMajor, savedMinor;