From ff0a859ceb6f6f0a41e5b6100bf60e7b23904374 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 30 Jan 2021 19:12:42 -0500 Subject: [PATCH] [host] nvfbc: avoid recreating mouse hook and 1x1 window The mouse hook code is very fragile, and we would like to avoid unhooking and re-hooking as much as possible. After this commit, this is done only once, and the hook and 1x1 window is only destroyed upon exit. This, of course, comes with the downside of the slight performance penalty if the guest machine is used directly while the host is running and the client is not running. --- .../Windows/capture/NVFBC/src/nvfbc.c | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index 4c3947da..562bfdd3 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -61,6 +61,9 @@ struct iface int mouseX, mouseY, mouseHotX, mouseHotY; bool mouseVisible, hasMousePosition; + + bool mouseHookCreated; + bool forceCompositionCreated; }; static struct iface * this = NULL; @@ -188,12 +191,21 @@ static bool nvfbc_init(void) } this->cursorEvents[0] = lgCreateEvent(true, 10); - mouseHook_install(on_mouseMove); if (this->seperateCursor) this->cursorEvents[1] = lgWrapEvent(event); - dwmForceComposition(); + if (!this->mouseHookCreated) + { + mouseHook_install(on_mouseMove); + this->mouseHookCreated = true; + } + + if (!this->forceCompositionCreated) + { + dwmForceComposition(); + this->forceCompositionCreated = true; + } DEBUG_INFO("Cursor mode : %s", this->seperateCursor ? "decoupled" : "integrated"); @@ -226,9 +238,6 @@ static void nvfbc_stop(void) static bool nvfbc_deinit(void) { - mouseHook_remove(); - dwmUnforceComposition(); - if (this->cursorEvents[0]) { lgFreeEvent(this->cursorEvents[0]); @@ -249,6 +258,12 @@ static void nvfbc_free(void) if (this->frameEvent) lgFreeEvent(this->frameEvent); + if (this->mouseHookCreated) + mouseHook_remove(); + + if (this->forceCompositionCreated) + dwmUnforceComposition(); + free(this); this = NULL; NvFBCFree();