From 667ab981ba310e8ef2d6aa54118eb133339a7180 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 25 May 2020 14:37:02 +1000 Subject: [PATCH] [host] send the latest cusror information when a new client connects --- VERSION | 2 +- host/src/app.c | 72 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index 950d8e41..9b61845a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B2-rc2-0-gd579705b10+1 \ No newline at end of file +B2-rc2-1-gbc7871f630+1 \ No newline at end of file diff --git a/host/src/app.c b/host/src/app.c index acd20027..67729765 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -66,6 +66,8 @@ struct app PLGMPHostQueue pointerQueue; PLGMPMemory pointerMemory[LGMP_Q_POINTER_LEN]; + LG_Lock pointerLock; + CapturePointer pointerInfo; PLGMPMemory pointerShape; bool pointerShapeValid; unsigned int pointerIndex; @@ -279,7 +281,7 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size) // spin until there is room while(lgmpHostQueuePending(app.pointerQueue) == LGMP_Q_POINTER_LEN) { - DEBUG_INFO("pending"); + usleep(1); if (!app.running) return false; } @@ -290,14 +292,13 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size) return true; } -void capturePostPointerBuffer(CapturePointer pointer) +static void sendPointer(bool newClient) { PLGMPMemory mem; - const bool newClient = lgmpHostQueueNewSubs(app.pointerQueue) > 0; - if (pointer.shapeUpdate || newClient) + if (app.pointerInfo.shapeUpdate || newClient) { - if (pointer.shapeUpdate) + if (app.pointerInfo.shapeUpdate) { // swap the latest shape buffer out of rotation PLGMPMemory tmp = app.pointerShape; @@ -309,32 +310,31 @@ void capturePostPointerBuffer(CapturePointer pointer) mem = app.pointerShape; } else - { mem = app.pointerMemory[app.pointerIndex]; - if (++app.pointerIndex == LGMP_Q_POINTER_LEN) - app.pointerIndex = 0; - } + + if (++app.pointerIndex == LGMP_Q_POINTER_LEN) + app.pointerIndex = 0; uint32_t flags = 0; KVMFRCursor *cursor = lgmpHostMemPtr(mem); - if (pointer.positionUpdate) + if (app.pointerInfo.positionUpdate || newClient) { flags |= CURSOR_FLAG_POSITION; - cursor->x = pointer.x; - cursor->y = pointer.y; + cursor->x = app.pointerInfo.x; + cursor->y = app.pointerInfo.y; } - if (pointer.visible) + if (app.pointerInfo.visible) flags |= CURSOR_FLAG_VISIBLE; - if (pointer.shapeUpdate) + if (app.pointerInfo.shapeUpdate) { // remember which slot has the latest shape - cursor->width = pointer.width; - cursor->height = pointer.height; - cursor->pitch = pointer.pitch; - switch(pointer.format) + cursor->width = app.pointerInfo.width; + cursor->height = app.pointerInfo.height; + cursor->pitch = app.pointerInfo.pitch; + switch(app.pointerInfo.format) { case CAPTURE_FMT_COLOR : cursor->type = CURSOR_TYPE_COLOR ; break; case CAPTURE_FMT_MONO : cursor->type = CURSOR_TYPE_MONOCHROME ; break; @@ -348,7 +348,7 @@ void capturePostPointerBuffer(CapturePointer pointer) app.pointerShapeValid = true; } - if ((pointer.shapeUpdate || newClient) && app.pointerShapeValid) + if ((app.pointerInfo.shapeUpdate || newClient) && app.pointerShapeValid) flags |= CURSOR_FLAG_SHAPE; LGMP_STATUS status; @@ -361,10 +361,31 @@ void capturePostPointerBuffer(CapturePointer pointer) } DEBUG_ERROR("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status)); - return; + break; } } +void capturePostPointerBuffer(CapturePointer pointer) +{ + LG_LOCK(app.pointerLock); + + int x = app.pointerInfo.x; + int y = app.pointerInfo.y; + + memcpy(&app.pointerInfo, &pointer, sizeof(CapturePointer)); + + /* if there was not a position update, restore the x & y */ + if (!pointer.positionUpdate) + { + app.pointerInfo.x = x; + app.pointerInfo.y = y; + } + + sendPointer(false); + + LG_UNLOCK(app.pointerLock); +} + // this is called from the platform specific startup routine int app_main(int argc, char * argv[]) { @@ -498,6 +519,8 @@ int app_main(int argc, char * argv[]) app.iface = iface; + LG_LOCK_INIT(app.pointerLock); + if (!captureStart()) { exitcode = -1; @@ -513,6 +536,13 @@ int app_main(int argc, char * argv[]) } app.reinit = false; + if (lgmpHostQueueNewSubs(app.pointerQueue) > 0) + { + LG_LOCK(app.pointerLock); + sendPointer(true); + LG_UNLOCK(app.pointerLock); + } + switch(iface->capture()) { case CAPTURE_RESULT_OK: @@ -541,6 +571,8 @@ finish: stopThreads(); exit: + LG_LOCK_FREE(app.pointerLock); + iface->deinit(); iface->free(); fail: