Switch frame loop from dispatch timer to CADisplayLink at 30fps

Replace the high-priority dispatch timer with CADisplayLink for frame
updates, reducing target framerate from 60 to 30 fps. This simplifies
the frame loop implementation while providing better system integration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Mousen
2025-12-10 05:11:23 +05:00
parent 508111c923
commit c8ba31e8c6

View File

@@ -7,7 +7,6 @@
NSOperationQueue *_q; NSOperationQueue *_q;
BOOL _updatingFrames; BOOL _updatingFrames;
CADisplayLink *_displayLink; CADisplayLink *_displayLink;
dispatch_source_t _timer;
// Shared from ScreenDumpVNC // Shared from ScreenDumpVNC
IOSurfaceRef _screenSurface; IOSurfaceRef _screenSurface;
@@ -142,11 +141,6 @@
-(void)stopFrameLoop { -(void)stopFrameLoop {
_updatingFrames = NO; _updatingFrames = NO;
if (_timer) {
dispatch_source_cancel(_timer);
_timer = nil;
}
if (_displayLink) { if (_displayLink) {
dispatch_async(dispatch_get_main_queue(), ^(void){ dispatch_async(dispatch_get_main_queue(), ^(void){
[_displayLink invalidate]; [_displayLink invalidate];
@@ -159,23 +153,11 @@
[self stopFrameLoop]; [self stopFrameLoop];
_updatingFrames = YES; _updatingFrames = YES;
// Use high-priority dispatch timer instead of CADisplayLink dispatch_async(dispatch_get_main_queue(), ^{
// CADisplayLink may be throttled for daemon processes _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_updateFrame)];
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class( _displayLink.preferredFramesPerSecond = 30;
DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0); [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
dispatch_queue_t timerQueue = dispatch_queue_create("com.mousen.screendump.frametimer", attr);
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, DISPATCH_TIMER_STRICT, timerQueue);
// 60 FPS = ~16.67ms interval
uint64_t interval = NSEC_PER_SEC / 60;
dispatch_source_set_timer(_timer, dispatch_time(DISPATCH_TIME_NOW, 0), interval, 0);
dispatch_source_set_event_handler(_timer, ^{
[self _updateFrame];
}); });
dispatch_resume(_timer);
} }
-(void)dealloc { -(void)dealloc {