From b942085e6c635c68dc0cd7bccfc134621c0f948c Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 10 Nov 2020 23:29:04 +1100 Subject: [PATCH] [host] don't allocate LGMP_Q_POINTER_LEN cursor shape buffers There is no need to allocate a buffer for each message as the client is only required to show the latest version of the cursor. Whie the logic should prevent cursor corruption, it's not guaranteed, however this is not a problem as this can only happen if the client is lagging behind and as such when it gets another update message it will re-read the now new shape anyway. --- host/src/app.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/host/src/app.c b/host/src/app.c index b5891983..790f5991 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -40,6 +40,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #define CONFIG_FILE "looking-glass-host.ini" +#define POINTER_SHAPE_BUFFERS 3 #define ALIGN_DN(x) ((uintptr_t)(x) & ~0x7F) #define ALIGN_UP(x) ALIGN_DN(x + 0x7F) @@ -73,7 +74,7 @@ struct app PLGMPHost lgmp; PLGMPHostQueue pointerQueue; - PLGMPMemory pointerMemory[LGMP_Q_POINTER_LEN]; + PLGMPMemory pointerMemory[POINTER_SHAPE_BUFFERS]; LG_Lock pointerLock; CapturePointer pointerInfo; PLGMPMemory pointerShape; @@ -285,14 +286,6 @@ static bool captureRestart() bool captureGetPointerBuffer(void ** data, uint32_t * size) { - // spin until there is room - while(lgmpHostQueuePending(app.pointerQueue) == LGMP_Q_POINTER_LEN) - { - usleep(1); - if (app.state == APP_STATE_RUNNING) - return false; - } - PLGMPMemory mem = app.pointerMemory[app.pointerIndex]; *data = ((uint8_t*)lgmpHostMemPtr(mem)) + sizeof(KVMFRCursor); *size = MAX_POINTER_SIZE - sizeof(KVMFRCursor); @@ -318,7 +311,7 @@ static void sendPointer(bool newClient) else mem = app.pointerMemory[app.pointerIndex]; - if (++app.pointerIndex == LGMP_Q_POINTER_LEN) + if (++app.pointerIndex == POINTER_SHAPE_BUFFERS) app.pointerIndex = 0; uint32_t flags = 0; @@ -489,7 +482,7 @@ int app_main(int argc, char * argv[]) goto fail; } - for(int i = 0; i < LGMP_Q_POINTER_LEN; ++i) + for(int i = 0; i < POINTER_SHAPE_BUFFERS; ++i) { if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerMemory[i])) != LGMP_OK) {