From b60375e6eafd880c4ea080566d6480a58478f544 Mon Sep 17 00:00:00 2001 From: julioverne Date: Mon, 29 Jun 2020 23:42:04 -0300 Subject: [PATCH] 0.0.3d Custom Resolution, less CPU usage --- screendump/en.plist | 16 --- screendump/layout/DEBIAN/control | 2 +- .../Preferences/screendump/Preferences.plist | Bin 427 -> 2140 bytes screendump/main.mm | 109 ++++++++++++++---- screendumpLowFrame/en.plist | 17 --- screendumpLowFrame/layout/DEBIAN/control | 1 - 6 files changed, 90 insertions(+), 55 deletions(-) diff --git a/screendump/en.plist b/screendump/en.plist index fe27d27..40a0e8d 100644 --- a/screendump/en.plist +++ b/screendump/en.plist @@ -20,10 +20,6 @@ com.apple.private.hid.client.service-protected - com.apple.private.hid.manager.client - - com.apple.private.hid.client.admin - com.apple.private.IOSurface.protected-access com.apple.QuartzCore.displayable-context @@ -36,8 +32,6 @@ com.apple.private.allow-explicit-graphics-priority - com.apple.private.xpc.launchd.app-server - com.apple.CommCenter.fine-grained spi @@ -46,15 +40,5 @@ com.apple.private.security.disk-device-access - com.apple.private.touch.eeprom.access - - com.apple.security.exception.iokit-user-client-class - RootDomainUserClient - com.apple.private.ioaccelmemoryinfo - - com.apple.gpumemd.client - - com.apple.backboardd.virtualDisplay - \ No newline at end of file diff --git a/screendump/layout/DEBIAN/control b/screendump/layout/DEBIAN/control index f03b118..29a2d3c 100644 --- a/screendump/layout/DEBIAN/control +++ b/screendump/layout/DEBIAN/control @@ -7,6 +7,6 @@ Description: VNC for ios Maintainer: Julio Author: julioverne, Sharat M R Section: Tweaks -Version: 0.0.3a +Version: 0.0.3d Depiction: http://julioverne.github.io/description.html?id=com.julioverne.screendump13 Icon: file:///Library/PreferenceLoader/Preferences/screendump/ScreenDump@2x.png diff --git a/screendump/layout/Library/PreferenceLoader/Preferences/screendump/Preferences.plist b/screendump/layout/Library/PreferenceLoader/Preferences/screendump/Preferences.plist index 9ea694e2f71dd21eb7fed38540733ed8f45650b2..9869565d0a7c4e50cbd7443cb8fa14705ba12747 100644 GIT binary patch literal 2140 zcmeHI!EW0y3_T}bq4^%GyA6YzVs)~%K#&=;i(*GrW)h*YWJvVf{QczENz}v%vcuZT zZid81zV}F4(amci$!{=LXmuTY4zB_NitAjc<#q6weII=ZZpOpt)8t2-{Ys{!l)@rO z9&cw4F$qSLek)4}luohTtwE|7m{wV&tT#Fo6{@|T`E1vqJFY`E}-D9?OJ))aed_4REbqBDm literal 427 zcmaKlKTZNc6o=pHqM#y+pa^JULuCT=+96_L%$kLOKp@NP14fpa&CG0&%GSa=SXg)x zFM!d)3wR9|#Mt?o-}nCI>v=Afs#u(9E2|qdWJ*kHRN+{@>7ljtaHLAmb!)EOL$^u^ zXHC<(q-<0QrcFr%B6Iw)*Rd9O7GU0EgXhid^h^(JMO&s-5#0CY=k*FQ6t?>j(?dpl zCz0IUOYJut?AyMpq&326*Dy>j)fHE?Pl>H4XZ7X2Yh(!@=Lwf%E(ge{FY|x;wrN=t zs>pERDKoq0qSG#wEGm~x*C_n+U+@I>Q6M8I^JHkV0XmWQm~MpPiA?q&)isiV0f{fL z>`+z3J2f}80)uHwIpM--`~rj_3JFNV5#-<)if{twP=g!jz%2;4hX;6sCwPHZn87D} YX=yE^<+M}n0v5HR{UjVNa~az8H$b|9N&o-= diff --git a/screendump/main.mm b/screendump/main.mm index 7c04e1d..c39aec4 100644 --- a/screendump/main.mm +++ b/screendump/main.mm @@ -19,6 +19,9 @@ static size_t bits_per_sample = 8; static size_t size_image; +static size_t prefferH; +static size_t prefferW; + static CFTypeRef (*$GSSystemCopyCapability)(CFStringRef); static CFTypeRef (*$GSSystemGetCapability)(CFStringRef); static BOOL (*$MGGetBoolAnswer)(CFStringRef); @@ -83,10 +86,15 @@ static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) return good; } -static void upFrameLoop(); static IOSurfaceRef screenSurface = NULL; static IOMobileFramebufferRef framebufferConnection = NULL; +@interface FrameUpdater : NSObject +@property (nonatomic, retain) NSTimer* myTimer; +- (void)startFrameLoop; +- (void)stopFrameLoop; +@end + static void VNCSetup() { if(!screenSurface) { @@ -100,8 +108,8 @@ static void VNCSetup() //width = size.width/2; //height = size.height/2; - width = IOSurfaceGetWidth(screenSurface) / 2; - height = IOSurfaceGetHeight(screenSurface) / 2; + width = prefferW==0?IOSurfaceGetWidth(screenSurface):prefferW; + height = prefferW==0?IOSurfaceGetHeight(screenSurface):prefferH; size_image = IOSurfaceGetAllocSize(screenSurface); bytesPerRow = IOSurfaceGetBytesPerRow(screenSurface); @@ -149,11 +157,15 @@ static void VNCSettings(bool shouldStart, NSString* password) VNCUpdateRunState(CCSisEnabled); } + + static void VNCUpdateRunState(bool shouldStart) { if(screen == NULL) { return; } + + if(CCSPassword && CCSPassword.length) { screen->authPasswdData = (void *) CCSPassword; } else { @@ -167,12 +179,14 @@ static void VNCUpdateRunState(bool shouldStart) rfbRunEventLoop(screen, -1, true); isLoopFrame = YES; - dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ - upFrameLoop(); - }); + + [[FrameUpdater shared] startFrameLoop]; } else { isLoopFrame = NO; + + [[FrameUpdater shared] stopFrameLoop]; + rfbShutdownServer(screen, true); } isVNCRunning = shouldStart; @@ -188,36 +202,91 @@ static void loadPrefs(void) defaults = (NSDictionary *)CFPreferencesCopyMultiple(keyList, appID, CFSTR("mobile"), kCFPreferencesAnyHost)?:@{}; CFRelease(keyList); } + + prefferH = [[defaults objectForKey:@"height"]?:@(0) intValue]; + prefferW = [[defaults objectForKey:@"width"]?:@(0) intValue]; + BOOL isEnabled = [[defaults objectForKey:@"CCSisEnabled"]?:@NO boolValue]; NSString *password = [defaults objectForKey:@"CCSPassword"]; VNCSettings(isEnabled, password); } } -static void upFrameLoop() + +static uint32_t oldSeed; + +@implementation FrameUpdater +{ + NSOperationQueue *q; +} +@synthesize myTimer; ++ (id)shared +{ + static __strong FrameUpdater* initFrame; + if(!initFrame) { + initFrame = [[[self class] alloc] init]; + } + return initFrame; +} +- (id)init +{ + self = [super init]; + + q = [[NSOperationQueue alloc] init]; + + return self; +} +- (void)_upFrameLoop +{ + if(isLoopFrame && CCSisEnabled) { + //check if screen changed + uint32_t newSeed = IOSurfaceGetSeed(screenSurface); + + if(oldSeed != newSeed && rfbIsActive(screen)) { + oldSeed = newSeed; + [q addOperationWithBlock: ^{ + IOSurfaceAcceleratorTransferSurface(accelerator, screenSurface, static_buffer, NULL, NULL, NULL, NULL); + rfbMarkRectAsModified(screen, 0, 0, width, height); + }]; + } + } else { + [self stopFrameLoop]; + } +} +- (void)stopFrameLoop +{ + if(myTimer && [myTimer isValid]) { + dispatch_async(dispatch_get_main_queue(), ^(void){ + [myTimer invalidate]; + }); + } +} +- (void)startFrameLoop { if(size_image == 0) { VNCSetup(); } - while(isLoopFrame && CCSisEnabled) { - if(rfbIsActive(screen) && IOSurfaceIsInUse(screenSurface)) { - IOSurfaceAcceleratorTransferSurface(accelerator, screenSurface, static_buffer, NULL, NULL, NULL, NULL); - //check if screen changed - void * buffBytes = IOSurfaceGetBaseAddress(static_buffer); - if(buffBytes && !(memcmp(buffBytes, "\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF", 9) == 0)) { - rfbMarkRectAsModified(screen, 0, 0, width, height); - } - //sleep(1/100); - } - } + [self stopFrameLoop]; + dispatch_async(dispatch_get_main_queue(), ^(void){ + myTimer = [NSTimer scheduledTimerWithTimeInterval:1/400 target:self selector:@selector(_upFrameLoop) userInfo:nil repeats:YES]; + }); } +-(void)dealloc +{ + [self stopFrameLoop]; +} +@end - +static void restartServer() +{ + exit(0); +} int main(int argc, const char *argv[]) { CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("com.cosmosgenius.screendump/preferences.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); - + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)restartServer, CFSTR("com.cosmosgenius.screendump/restart"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); + loadPrefs(); VNCSetup(); diff --git a/screendumpLowFrame/en.plist b/screendumpLowFrame/en.plist index 6033ad2..40a0e8d 100644 --- a/screendumpLowFrame/en.plist +++ b/screendumpLowFrame/en.plist @@ -20,10 +20,6 @@ com.apple.private.hid.client.service-protected - com.apple.private.hid.manager.client - - com.apple.private.hid.client.admin - com.apple.private.IOSurface.protected-access com.apple.QuartzCore.displayable-context @@ -36,9 +32,6 @@ com.apple.private.allow-explicit-graphics-priority - com.apple.private.xpc.launchd.app-server - - com.apple.CommCenter.fine-grained spi @@ -47,15 +40,5 @@ com.apple.private.security.disk-device-access - com.apple.private.touch.eeprom.access - - com.apple.security.exception.iokit-user-client-class - RootDomainUserClient - com.apple.private.ioaccelmemoryinfo - - com.apple.gpumemd.client - - com.apple.backboardd.virtualDisplay - \ No newline at end of file diff --git a/screendumpLowFrame/layout/DEBIAN/control b/screendumpLowFrame/layout/DEBIAN/control index 050732b..3e5b82a 100644 --- a/screendumpLowFrame/layout/DEBIAN/control +++ b/screendumpLowFrame/layout/DEBIAN/control @@ -7,4 +7,3 @@ Maintainer: Sharat M R Author: Sharat M R Section: Tweaks Version: 0.0.3 -Installed-Size: 3100