From 0ca760fad6a60af69d942913dcadd2202aa816fa Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 29 Jan 2020 23:22:49 +1100 Subject: [PATCH] [c-host] revert locking series, this needs more thought Revert "[c-host] make pointer post function thread safe" This reverts commit 3feed7ba074059bf8987470c822b5e1feeef3ee4. Revert "[c-hots] fix incorrect unlock timing" This reverts commit 57f1f2d1fe350dd7defd5a8ca655216f65441a95. Revert "[c-host] increase the queue length and remove debug output" This reverts commit b0f9f15a6083d726acb6ae5f158c316bbdc5fbd7. Revert "[c-host] dxgi: use low level mouse input by default" This reverts commit dc4d820666e396a7e8daccd9014aabe3159fc151. Revert "[c-host] nvfbc: no need for a cursor position event with LGMP" This reverts commit e30b54ddb2fd7e0ec6ba50bf5dbe325d97fbc220. --- VERSION | 2 +- .../platform/Windows/capture/DXGI/src/dxgi.c | 75 +++------------ .../Windows/capture/NVFBC/src/nvfbc.c | 91 +++++++++---------- c-host/src/app.c | 12 +-- 4 files changed, 59 insertions(+), 121 deletions(-) diff --git a/VERSION b/VERSION index 71dc472f..31c8b6fc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-141-g939bb07603+1 \ No newline at end of file +B1-140-gcc2c49644d+1 \ No newline at end of file diff --git a/c-host/platform/Windows/capture/DXGI/src/dxgi.c b/c-host/platform/Windows/capture/DXGI/src/dxgi.c index d4b9ab39..d1c9404c 100644 --- a/c-host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/c-host/platform/Windows/capture/DXGI/src/dxgi.c @@ -25,8 +25,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/locking.h" #include "common/event.h" -#include "windows/mousehook.h" - #include #include #include @@ -84,9 +82,6 @@ struct iface unsigned int stride; CaptureFormat format; - LG_Lock pointerLock; - bool decouplePointer; - int hotspotX , hotspotY; int lastPointerX, lastPointerY; bool lastPointerVisible; }; @@ -101,27 +96,6 @@ static CaptureResult dxgi_releaseFrame(); // implementation -static void on_mouseMove(int x, int y) -{ - LG_LOCK(this->pointerLock); - - x -= this->hotspotX; - y -= this->hotspotY; - - this->lastPointerX = x; - this->lastPointerY = y; - - CapturePointer pointer = - { - .positionUpdate = true, - .visible = this->lastPointerVisible, - .x = x, - .y = y - }; - LG_UNLOCK(this->pointerLock); - this->postPointerBufferFn(pointer); -} - static const char * dxgi_getName() { return "DXGI"; @@ -159,14 +133,6 @@ static void dxgi_initOptions() .type = OPTION_TYPE_BOOL, .value.x_bool = false }, - { - .module = "dxgi", - .name = "decouplePointer", - .description = "Use a low level hook to obtain cursor position information", - .type = OPTION_TYPE_BOOL, - .value.x_bool = true - }, - {0} }; @@ -195,18 +161,10 @@ static bool dxgi_create(CaptureGetPointerBuffer getPointerBufferFn, CapturePostP if (this->maxTextures <= 0) this->maxTextures = 1; - this->useAcquireLock = option_get_bool("dxgi", "useAcquireLock" ); - this->decouplePointer = option_get_bool("dxgi", "decouplePointer"); - + this->useAcquireLock = option_get_bool("dxgi", "useAcquireLock"); this->texture = calloc(sizeof(struct Texture), this->maxTextures); this->getPointerBufferFn = getPointerBufferFn; this->postPointerBufferFn = postPointerBufferFn; - - LG_LOCK_INIT(this->pointerLock); - - if (this->decouplePointer) - mouseHook_install(on_mouseMove); - return true; } @@ -571,8 +529,6 @@ static bool dxgi_deinit() { assert(this); - mouseHook_remove(); - for(int i = 0; i < this->maxTextures; ++i) { this->texture[i].state = TEXTURE_STATE_UNUSED; @@ -756,20 +712,22 @@ static CaptureResult dxgi_capture() frameInfo.PointerPosition.Visible != this->lastPointerVisible ) { - LG_LOCK(this->pointerLock); - /* the pointer position is invalid if the pointer is not visible */ - if (!this->decouplePointer && frameInfo.PointerPosition.Visible) + if (frameInfo.PointerPosition.Visible) { pointer.positionUpdate = true; - this->lastPointerX = frameInfo.PointerPosition.Position.x; - this->lastPointerY = frameInfo.PointerPosition.Position.y; + pointer.x = + this->lastPointerX = + frameInfo.PointerPosition.Position.x; + pointer.y = + this->lastPointerY = + frameInfo.PointerPosition.Position.y; } - this->lastPointerVisible = frameInfo.PointerPosition.Visible; + pointer.visible = + this->lastPointerVisible = + frameInfo.PointerPosition.Visible; postPointer = true; - - LG_UNLOCK(this->pointerLock); } } @@ -800,12 +758,6 @@ static CaptureResult dxgi_capture() return CAPTURE_RESULT_ERROR; } - // needed in decouple mode - LG_LOCK(this->pointerLock); - this->hotspotX = shapeInfo.HotSpot.x; - this->hotspotY = shapeInfo.HotSpot.y; - LG_UNLOCK(this->pointerLock); - pointer.shapeUpdate = true; pointer.width = shapeInfo.Width; pointer.height = shapeInfo.Height; @@ -816,12 +768,7 @@ static CaptureResult dxgi_capture() // post back the pointer information if (postPointer) - { - LG_LOCK(this->pointerLock); - pointer.visible = this->lastPointerVisible; - LG_UNLOCK(this->pointerLock); this->postPointerBufferFn(pointer); - } return CAPTURE_RESULT_OK; } diff --git a/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c b/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c index 88fbcc81..886434be 100644 --- a/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -20,17 +20,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "interface/capture.h" #include "interface/platform.h" #include "common/windebug.h" +#include "windows/mousehook.h" #include "common/option.h" #include "common/framebuffer.h" #include "common/event.h" #include "common/thread.h" -#include "common/locking.h" #include #include #include -#include "windows/mousehook.h" - #include #include "wrapper.h" @@ -53,9 +51,8 @@ struct iface NvFBCFrameGrabInfo grabInfo; LGEvent * frameEvent; - LGEvent * cursorEvent; + LGEvent * cursorEvents[2]; - LG_Lock cursorLock; int mouseX, mouseY, mouseHotX, mouseHotY; bool mouseVisible; }; @@ -81,20 +78,9 @@ static void getDesktopSize(unsigned int * width, unsigned int * height) static void on_mouseMove(int x, int y) { - LG_LOCK(this->cursorLock); this->mouseX = x; this->mouseY = y; - - CapturePointer pointer = - { - .positionUpdate = true, - .visible = this->mouseVisible, - .x = this->mouseX - this->mouseHotX, - .y = this->mouseY - this->mouseHotY - }; - - LG_UNLOCK(this->cursorLock); - this->postPointerBufferFn(pointer); + lgSignalEvent(this->cursorEvents[0]); } static const char * nvfbc_getName() @@ -108,7 +94,7 @@ static void nvfbc_initOptions() { { .module = "nvfbc", - .name = "decouplePointer", + .name = "decoupleCursor", .description = "Capture the cursor seperately", .type = OPTION_TYPE_BOOL, .value.x_bool = true @@ -164,12 +150,10 @@ static bool nvfbc_create( return false; } - this->seperateCursor = option_get_bool("nvfbc", "decouplePointer"); + this->seperateCursor = option_get_bool("nvfbc", "decoupleCursor"); this->getPointerBufferFn = getPointerBufferFn; this->postPointerBufferFn = postPointerBufferFn; - LG_LOCK_INIT(this->cursorLock); - return true; } @@ -195,10 +179,11 @@ static bool nvfbc_init() return false; } + this->cursorEvents[0] = lgCreateEvent(true, 10); mouseHook_install(on_mouseMove); if (this->seperateCursor) - this->cursorEvent = lgWrapEvent(event); + this->cursorEvents[1] = lgWrapEvent(event); DEBUG_INFO("Cursor mode : %s", this->seperateCursor ? "decoupled" : "integrated"); @@ -216,6 +201,7 @@ static bool nvfbc_init() static void nvfbc_stop() { this->stop = true; + lgSignalEvent(this->cursorEvents[0]); lgSignalEvent(this->frameEvent); if (this->pointerThread) @@ -228,6 +214,13 @@ static void nvfbc_stop() static bool nvfbc_deinit() { mouseHook_remove(); + + if (this->cursorEvents[0]) + { + lgFreeEvent(this->cursorEvents[0]); + this->cursorEvents[0] = NULL; + } + return true; } @@ -238,7 +231,6 @@ static void nvfbc_free() if (this->frameEvent) lgFreeEvent(this->frameEvent); - LG_LOCK_FREE(this->cursorLock); free(this); this = NULL; NvFBCFree(); @@ -331,40 +323,47 @@ static int pointerThread(void * unused) { while(!this->stop) { - if (!lgWaitEvent(this->cursorEvent, 1000)) + LGEvent * events[2]; + memcpy(&events, &this->cursorEvents, sizeof(LGEvent *) * 2); + if (!lgWaitEvents(events, this->seperateCursor ? 2 : 1, false, 1000)) continue; if (this->stop) break; CaptureResult result; - - void * data; - uint32_t size; - if (!this->getPointerBufferFn(&data, &size)) - { - DEBUG_WARN("failed to get a pointer buffer"); - continue; - } - CapturePointer pointer = { 0 }; - result = NvFBCToSysGetCursor(this->nvfbc, &pointer, data, size); - if (result != CAPTURE_RESULT_OK) + + if (this->seperateCursor && events[1]) { - DEBUG_WARN("NvFBCToSysGetCursor failed"); - continue; + void * data; + uint32_t size; + if (!this->getPointerBufferFn(&data, &size)) + { + DEBUG_WARN("failed to get a pointer buffer"); + continue; + } + + result = NvFBCToSysGetCursor(this->nvfbc, &pointer, data, size); + if (result != CAPTURE_RESULT_OK) + { + DEBUG_WARN("NvFBCToSysGetCursor failed"); + continue; + } + + this->mouseVisible = pointer.visible; + this->mouseHotX = pointer.x; + this->mouseHotY = pointer.y; } - LG_LOCK(this->cursorLock); - this->mouseVisible = pointer.visible; - this->mouseHotX = pointer.x; - this->mouseHotY = pointer.y; + if (events[0]) + { + pointer.positionUpdate = true; + pointer.visible = this->mouseVisible; + pointer.x = this->mouseX - this->mouseHotX; + pointer.y = this->mouseY - this->mouseHotY; + } - pointer.positionUpdate = true; - pointer.x = this->mouseX - this->mouseHotX; - pointer.y = this->mouseY - this->mouseHotY; - - LG_UNLOCK(this->cursorLock); this->postPointerBufferFn(pointer); } diff --git a/c-host/src/app.c b/c-host/src/app.c index 0ef04c56..a9338cd6 100644 --- a/c-host/src/app.c +++ b/c-host/src/app.c @@ -41,7 +41,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #define ALIGN_UP(x) ALIGN_DN(x + 0x7F) #define LGMP_Q_FRAME_LEN 2 -#define LGMP_Q_POINTER_LEN 40 +#define LGMP_Q_POINTER_LEN 20 static const struct LGMPQueueConfig FRAME_QUEUE_CONFIG = { @@ -63,7 +63,6 @@ struct app { PLGMPHost lgmp; - LG_Lock pointerPostLock; PLGMPHostQueue pointerQueue; PLGMPMemory pointerMemory[LGMP_Q_POINTER_LEN]; PLGMPMemory pointerShape; @@ -289,6 +288,7 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size) // spin until there is room while(lgmpHostQueuePending(app.pointerQueue) == LGMP_Q_POINTER_LEN) { + DEBUG_INFO("pending"); if (!app.running) return false; } @@ -301,8 +301,6 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size) void capturePostPointerBuffer(CapturePointer pointer) { - LG_LOCK(app.pointerPostLock); - PLGMPMemory mem; const bool newClient = lgmpHostQueueNewSubs(app.pointerQueue) > 0; @@ -353,7 +351,6 @@ void capturePostPointerBuffer(CapturePointer pointer) default: DEBUG_ERROR("Invalid pointer type"); - LG_UNLOCK(app.pointerPostLock); return; } @@ -363,8 +360,6 @@ void capturePostPointerBuffer(CapturePointer pointer) if ((pointer.shapeUpdate || newClient) && app.pointerShapeValid) flags |= CURSOR_FLAG_SHAPE; - LG_UNLOCK(app.pointerPostLock); - LGMP_STATUS status; while ((status = lgmpHostQueuePost(app.pointerQueue, flags, mem)) != LGMP_OK) { @@ -422,8 +417,6 @@ int app_main(int argc, char * argv[]) return -1; } - LG_LOCK_INIT(app.pointerPostLock); - int exitcode = 0; DEBUG_INFO("IVSHMEM Size : %u MiB", shmDev.size / 1048576); DEBUG_INFO("IVSHMEM Address : 0x%" PRIXPTR, (uintptr_t)shmDev.mem); @@ -562,7 +555,6 @@ fail: lgmpHostFree(&app.lgmp); ivshmemClose(&shmDev); - LG_LOCK_FREE(app.pointerPostLock); return exitcode; }