From 22f3e44ad9d69f48b7cc4aeb5b80ddd02e143c3f Mon Sep 17 00:00:00 2001 From: Levent Duivel Date: Sun, 10 Nov 2024 03:39:37 +0500 Subject: [PATCH] Revert "cursor ai garbage tuning" This reverts commit b88f0b7151df44e838e8616c59a5182e5267751d. --- screendump/FrameUpdater.m | 69 ++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/screendump/FrameUpdater.m b/screendump/FrameUpdater.m index f8686d0..8498585 100644 --- a/screendump/FrameUpdater.m +++ b/screendump/FrameUpdater.m @@ -1,6 +1,4 @@ #import "FrameUpdater.h" -#import -#import @implementation FrameUpdater { @@ -9,7 +7,6 @@ BOOL _updatingFrames; uint32_t _lastUpdatedSeed; NSTimer* _updateFrameTimer; - CADisplayLink *_displayLink; // Shared from ScreenDumpVNC IOSurfaceRef _screenSurface; @@ -39,47 +36,39 @@ -(void)_updateFrame { - [_q addOperationWithBlock: ^{ - if (!_updatingFrames) { - [self stopFrameLoop]; - return; - } - // Check if screen changed - uint32_t currentFrameSeed = IOSurfaceGetSeed(_screenSurface); - - // Only proceed if the screen has changed and the VNC is active - if (_lastUpdatedSeed != currentFrameSeed && rfbIsActive(_rfbScreenInfo)) { - _lastUpdatedSeed = currentFrameSeed; - - // Optimize the transfer by checking if the accelerator is available - if (_accelerator) { - IOSurfaceAcceleratorTransferSurface(_accelerator, _screenSurface, _staticBuffer, NULL, NULL, NULL, NULL); - } - - // Mark the entire screen as modified only if necessary - if (_width > 0 && _height > 0) { - rfbMarkRectAsModified(_rfbScreenInfo, 0, 0, _width, _height); - } - } - }]; -} + if (!_updatingFrames) { + [self stopFrameLoop]; + return; + } --(void)startFrameLoop { - [self stopFrameLoop]; - _updatingFrames = YES; - - dispatch_async(dispatch_get_main_queue(), ^(void){ - _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_updateFrame)]; - [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; - }); + // check if screen changed + uint32_t currentFrameSeed = IOSurfaceGetSeed(_screenSurface); + + if (_lastUpdatedSeed != currentFrameSeed && rfbIsActive(_rfbScreenInfo)) { + _lastUpdatedSeed = currentFrameSeed; + [_q addOperationWithBlock: ^{ + IOSurfaceAcceleratorTransferSurface(_accelerator, _screenSurface, _staticBuffer, NULL, NULL, NULL, NULL); + rfbMarkRectAsModified(_rfbScreenInfo, 0, 0, _width, _height); + }]; + } } -(void)stopFrameLoop { - if (_displayLink) { - [_displayLink invalidate]; - _displayLink = nil; - } - _updatingFrames = NO; + if (_updateFrameTimer == nil || ![_updateFrameTimer isValid]) return; + + dispatch_async(dispatch_get_main_queue(), ^(void){ + [_updateFrameTimer invalidate]; + _updatingFrames = NO; + }); +} + +-(void)startFrameLoop { + // if (size_image == 0) VNCSetup(); + [self stopFrameLoop]; + _updatingFrames = YES; + dispatch_async(dispatch_get_main_queue(), ^(void){ + _updateFrameTimer = [NSTimer scheduledTimerWithTimeInterval:1/400 target:self selector:@selector(_updateFrame) userInfo:nil repeats:YES]; + }); } -(void)dealloc {