[c-host] nvfbc: expose option to disable cursor decoupling

This commit is contained in:
Geoffrey McRae 2019-05-23 15:12:28 +10:00
parent afe072adf1
commit 1b031582a4
2 changed files with 38 additions and 10 deletions

View File

@ -1 +1 @@
a12-213-g09d4fea9e2+1 a12-214-gafe072adf1+1

View File

@ -22,6 +22,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "windows/platform.h" #include "windows/platform.h"
#include "windows/debug.h" #include "windows/debug.h"
#include "windows/mousehook.h" #include "windows/mousehook.h"
#include "common/option.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
@ -34,6 +35,7 @@ struct iface
bool stop; bool stop;
NvFBCHandle nvfbc; NvFBCHandle nvfbc;
bool seperateCursor;
void * pointerShape; void * pointerShape;
unsigned int pointerSize; unsigned int pointerSize;
unsigned int maxWidth, maxHeight; unsigned int maxWidth, maxHeight;
@ -72,7 +74,7 @@ static void on_mouseMove(int x, int y)
{ {
this->mouseX = x; this->mouseX = x;
this->mouseY = y; this->mouseY = y;
os_signalEvent(this->cursorEvents[1]); os_signalEvent(this->cursorEvents[0]);
} }
static const char * nvfbc_getName() static const char * nvfbc_getName()
@ -80,6 +82,23 @@ static const char * nvfbc_getName()
return "NVFBC (NVidia Frame Buffer Capture)"; return "NVFBC (NVidia Frame Buffer Capture)";
}; };
static void nvfbc_initOptions()
{
struct Option options[] =
{
{
.module = "nvfbc",
.name = "decoupleCursor",
.description = "Capture the cursor seperately",
.type = OPTION_TYPE_BOOL,
.value.x_bool = true
},
{0}
};
option_register(options);
}
static bool nvfbc_create() static bool nvfbc_create()
{ {
if (!NvFBCInit()) if (!NvFBCInit())
@ -123,24 +142,27 @@ static bool nvfbc_create()
return false; return false;
} }
this->seperateCursor = option_get_bool("nvfbc", "decoupleCursor");
return true; return true;
} }
static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize) static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize)
{ {
this->stop = false; this->stop = false;
this->pointerShape = pointerShape; this->pointerShape = pointerShape;
this->pointerSize = pointerSize; this->pointerSize = pointerSize;
getDesktopSize(&this->width, &this->height); getDesktopSize(&this->width, &this->height);
os_resetEvent(this->frameEvent); os_resetEvent(this->frameEvent);
HANDLE event; HANDLE event;
if (!NvFBCToSysSetup( if (!NvFBCToSysSetup(
this->nvfbc, this->nvfbc,
BUFFER_FMT_ARGB, BUFFER_FMT_ARGB,
false, !this->seperateCursor,
true, this->seperateCursor,
false, false,
0, 0,
(void **)&this->frameBuffer, (void **)&this->frameBuffer,
@ -151,10 +173,14 @@ static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize)
return false; return false;
} }
this->cursorEvents[0] = os_wrapEvent(event); this->cursorEvents[0] = os_createEvent(true);
this->cursorEvents[1] = os_createEvent(true);
mouseHook_install(on_mouseMove); mouseHook_install(on_mouseMove);
if (this->seperateCursor)
this->cursorEvents[1] = os_wrapEvent(event);
DEBUG_INFO("Cursor mode : %s", this->seperateCursor ? "decoupled" : "integrated");
Sleep(100); Sleep(100);
return true; return true;
} }
@ -162,7 +188,7 @@ static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize)
static void nvfbc_stop() static void nvfbc_stop()
{ {
this->stop = true; this->stop = true;
os_signalEvent(this->cursorEvents[1]); os_signalEvent(this->cursorEvents[0]);
os_signalEvent(this->frameEvent); os_signalEvent(this->frameEvent);
} }
@ -251,7 +277,7 @@ static CaptureResult nvfbc_getPointer(CapturePointer * pointer)
{ {
osEventHandle * events[2]; osEventHandle * events[2];
memcpy(&events, &this->cursorEvents, sizeof(osEventHandle *) * 2); memcpy(&events, &this->cursorEvents, sizeof(osEventHandle *) * 2);
if (!os_waitEvents(events, 2, false, TIMEOUT_INFINITE)) if (!os_waitEvents(events, this->seperateCursor ? 2 : 1, false, TIMEOUT_INFINITE))
{ {
DEBUG_ERROR("Failed to wait on the cursor events"); DEBUG_ERROR("Failed to wait on the cursor events");
return CAPTURE_RESULT_ERROR; return CAPTURE_RESULT_ERROR;
@ -262,7 +288,7 @@ static CaptureResult nvfbc_getPointer(CapturePointer * pointer)
CaptureResult result; CaptureResult result;
pointer->shapeUpdate = false; pointer->shapeUpdate = false;
if (events[0]) if (this->seperateCursor && events[1])
{ {
result = NvFBCToSysGetCursor(this->nvfbc, pointer, this->pointerShape, this->pointerSize); result = NvFBCToSysGetCursor(this->nvfbc, pointer, this->pointerShape, this->pointerSize);
this->mouseVisible = pointer->visible; this->mouseVisible = pointer->visible;
@ -281,6 +307,8 @@ static CaptureResult nvfbc_getPointer(CapturePointer * pointer)
struct CaptureInterface Capture_NVFBC = struct CaptureInterface Capture_NVFBC =
{ {
.getName = nvfbc_getName, .getName = nvfbc_getName,
.initOptions = nvfbc_initOptions,
.create = nvfbc_create, .create = nvfbc_create,
.init = nvfbc_init, .init = nvfbc_init,
.stop = nvfbc_stop, .stop = nvfbc_stop,