Skip to content

Commit b38369e

Browse files
authored
iOS/tvOS: don't use draw observer unless fast forwarding (#18362)
1 parent 91aedbe commit b38369e

4 files changed

Lines changed: 50 additions & 12 deletions

File tree

menu/menu_defines.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ enum menu_state_flags
5050
MENU_ST_FLAG_SCREENSAVER_SUPPORTED = (1 << 10),
5151
MENU_ST_FLAG_SCREENSAVER_ACTIVE = (1 << 11),
5252
MENU_ST_FLAG_PENDING_RELOAD_CORE = (1 << 12),
53-
MENU_ST_FLAG_PENDING_STARTUP_PAGE = (1 << 13)
53+
MENU_ST_FLAG_PENDING_STARTUP_PAGE = (1 << 13),
54+
MENU_ST_FLAG_BLOCK_ALL_INPUT = (1 << 14)
5455
};
5556

5657
enum menu_scroll_mode

menu/menu_driver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5318,6 +5318,10 @@ unsigned menu_event(
53185318
RETRO_DEVICE_ID_JOYPAD_Y
53195319
};
53205320

5321+
/* Check if all menu input is blocked */
5322+
if (menu_st->flags & MENU_ST_FLAG_BLOCK_ALL_INPUT)
5323+
return MENU_ACTION_NOOP;
5324+
53215325
ok_old = ok_current;
53225326

53235327
/* Get pointer (mouse + touchscreen) input

ui/drivers/cocoa/cocoa_common.m

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ static void rarch_draw_observer(CFRunLoopObserverRef observer,
120120
#endif
121121

122122
runloop_flags = runloop_get_flags();
123-
if (!(runloop_flags & RUNLOOP_FLAG_IDLE))
123+
if (runloop_flags & RUNLOOP_FLAG_FASTMOTION)
124124
CFRunLoopWakeUp(CFRunLoopGetMain());
125+
#if TARGET_OS_IPHONE
126+
else
127+
rarch_stop_draw_observer();
128+
#endif
125129
}
126130

127131
void rarch_start_draw_observer(void)
@@ -173,8 +177,12 @@ -(void)step:(CADisplayLink*)target API_AVAILABLE(macos(14.0), ios(3.1), tvos(3.1
173177
}
174178

175179
uint32_t runloop_flags = runloop_get_flags();
176-
if (!(runloop_flags & RUNLOOP_FLAG_IDLE))
180+
if (runloop_flags & RUNLOOP_FLAG_FASTMOTION)
181+
{
182+
/* Fast-forward: observer handles all iterations */
183+
rarch_start_draw_observer();
177184
CFRunLoopWakeUp(CFRunLoopGetMain());
185+
}
178186
#endif
179187
}
180188
#endif
@@ -195,14 +203,22 @@ + (CocoaView*)get
195203
* the display server will set the exact rate when needed */
196204
[view.displayLink setPreferredFrameRateRange:CAFrameRateRangeMake(60, 120, 120)];
197205
}
206+
else
207+
{
208+
/* iOS 9-14: Use preferredFramesPerSecond as fallback */
209+
view.displayLink.preferredFramesPerSecond = 120;
210+
}
211+
#else
212+
/* Building with SDK < iOS 15: Use preferredFramesPerSecond */
213+
view.displayLink.preferredFramesPerSecond = 120;
198214
#endif
199-
[view.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
215+
[view.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
200216
#elif defined(OSX) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000
201217
if (@available(macOS 14.0, *))
202218
{
203219
view.displayLink = [view displayLinkWithTarget:view selector:@selector(step:)];
204220
view.displayLink.preferredFrameRateRange = CAFrameRateRangeMake(60, 120, 120);
205-
[view.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
221+
[view.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
206222
}
207223
#endif
208224
}
@@ -757,22 +773,26 @@ - (void)webServerDidCompleteBonjourRegistration:(GCDWebServer*)server
757773
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Welcome to RetroArch" message:[NSString stringWithFormat:@"To transfer files from your computer, go to one of these addresses on your web browser:\n\n%@",servers] preferredStyle:UIAlertControllerStyleAlert];
758774
[alert addAction:[UIAlertAction actionWithTitle:@"OK"
759775
style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
760-
rarch_start_draw_observer();
776+
struct menu_state *menu_st = menu_state_get_ptr();
777+
menu_st->flags &= ~MENU_ST_FLAG_BLOCK_ALL_INPUT;;
761778
}]];
762779
[alert addAction:[UIAlertAction actionWithTitle:@"Don't Show Again"
763780
style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
764-
rarch_start_draw_observer();
781+
struct menu_state *menu_st = menu_state_get_ptr();
782+
menu_st->flags &= ~MENU_ST_FLAG_BLOCK_ALL_INPUT;
765783
configuration_set_bool(settings, settings->bools.gcdwebserver_alert, false);
766784
}]];
767785
#if TARGET_OS_IOS
768786
[alert addAction:[UIAlertAction actionWithTitle:@"Stop Server" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
769787
[[WebServer sharedInstance] webUploader].delegate = nil;
770788
[[WebServer sharedInstance] stopServers];
771-
rarch_start_draw_observer();
789+
struct menu_state *menu_st = menu_state_get_ptr();
790+
menu_st->flags &= ~MENU_ST_FLAG_BLOCK_ALL_INPUT;;
772791
}]];
773792
#endif
774793
[self presentViewController:alert animated:YES completion:^{
775-
rarch_stop_draw_observer();
794+
struct menu_state *menu_st = menu_state_get_ptr();
795+
menu_st->flags |= MENU_ST_FLAG_BLOCK_ALL_INPUT;
776796
}];
777797
});
778798
#endif

ui/drivers/ui_cocoatouch.m

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,6 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
860860
appicon_setting->values = options;
861861
}
862862

863-
rarch_start_draw_observer();
864-
865863
#if TARGET_OS_TV
866864
update_topshelf();
867865
#endif
@@ -928,6 +926,14 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
928926
#endif
929927
rarch_stop_draw_observer();
930928
command_event(CMD_EVENT_SAVE_FILES, NULL);
929+
930+
/* Clear any stuck or stale touches when backgrounding */
931+
cocoa_input_data_t *apple = (cocoa_input_data_t*)input_state_get_ptr()->current_data;
932+
if (apple)
933+
{
934+
apple->touch_count = 0;
935+
memset(apple->touches, 0, sizeof(apple->touches));
936+
}
931937
}
932938

933939
- (void)applicationWillTerminate:(UIApplication *)application
@@ -940,11 +946,18 @@ - (void)applicationWillResignActive:(UIApplication *)application
940946
{
941947
self.bgDate = [NSDate date];
942948
rarch_stop_draw_observer();
949+
950+
/* Clear any stuck or stale touches when losing focus */
951+
cocoa_input_data_t *apple = (cocoa_input_data_t*)input_state_get_ptr()->current_data;
952+
if (apple)
953+
{
954+
apple->touch_count = 0;
955+
memset(apple->touches, 0, sizeof(apple->touches));
956+
}
943957
}
944958

945959
- (void)applicationDidBecomeActive:(UIApplication *)application
946960
{
947-
rarch_start_draw_observer();
948961
NSError *error;
949962
settings_t *settings = config_get_ptr();
950963
bool ui_companion_start_on_boot = settings->bools.ui_companion_start_on_boot;

0 commit comments

Comments
 (0)