improve CPU usage

This commit is contained in:
julioverne 2020-06-23 00:26:48 -03:00
parent da7c3a4aa6
commit 1477573918
2 changed files with 22 additions and 14 deletions

View File

@ -65,6 +65,8 @@ static void VNCUpdateRunState(bool shouldStart);
static void handleVNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client); static void handleVNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client);
static void handleVNCPointer(int buttons, int x, int y, rfbClientPtr client); static void handleVNCPointer(int buttons, int x, int y, rfbClientPtr client);
static BOOL isLoopFrame;
static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size)
{ {
NSString *password = reinterpret_cast<NSString *>(screen->authPasswdData); NSString *password = reinterpret_cast<NSString *>(screen->authPasswdData);
@ -81,6 +83,7 @@ static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size)
return good; return good;
} }
static void upFrameLoop();
static IOSurfaceRef screenSurface = NULL; static IOSurfaceRef screenSurface = NULL;
static IOMobileFramebufferRef framebufferConnection = NULL; static IOMobileFramebufferRef framebufferConnection = NULL;
@ -162,7 +165,14 @@ static void VNCUpdateRunState(bool shouldStart)
if(shouldStart) { if(shouldStart) {
rfbInitServer(screen); rfbInitServer(screen);
rfbRunEventLoop(screen, -1, true); rfbRunEventLoop(screen, -1, true);
isLoopFrame = YES;
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
upFrameLoop();
});
} else { } else {
isLoopFrame = NO;
rfbShutdownServer(screen, true); rfbShutdownServer(screen, true);
} }
isVNCRunning = shouldStart; isVNCRunning = shouldStart;
@ -189,17 +199,17 @@ static void upFrameLoop()
if(size_image == 0) { if(size_image == 0) {
VNCSetup(); VNCSetup();
} }
while(isLoopFrame && CCSisEnabled) {
if(CCSisEnabled && rfbIsActive(screen) && IOSurfaceIsInUse(screenSurface)) { if(rfbIsActive(screen) && IOSurfaceIsInUse(screenSurface)) {
IOSurfaceAcceleratorTransferSurface(accelerator, screenSurface, static_buffer, NULL, NULL, NULL, NULL); IOSurfaceAcceleratorTransferSurface(accelerator, screenSurface, static_buffer, NULL, NULL, NULL, NULL);
//check if screen changed //check if screen changed
if(!(memcmp(IOSurfaceGetBaseAddress(static_buffer), "\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF", 9) == 0)) { 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); rfbMarkRectAsModified(screen, 0, 0, width, height);
} }
//sleep(1/100); //sleep(1/100);
} }
}
upFrameLoop();
} }
@ -213,9 +223,7 @@ int main(int argc, const char *argv[])
VNCSetup(); VNCSetup();
//VNCBlack(); //VNCBlack();
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
upFrameLoop();
});
[[NSRunLoop currentRunLoop] run]; [[NSRunLoop currentRunLoop] run];

BIN
screendump13.mp4 Normal file

Binary file not shown.