[c-host] update NvFBC to use new capture interface

This commit is contained in:
Geoffrey McRae 2020-01-11 21:51:59 +11:00
parent e554635e48
commit 0eafa7de5d
2 changed files with 69 additions and 32 deletions

View File

@ -1 +1 @@
B1-80-g5e915dd1ff+1 B1-81-ge554635e48+1

View File

@ -24,6 +24,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "common/option.h" #include "common/option.h"
#include "common/framebuffer.h" #include "common/framebuffer.h"
#include "common/event.h" #include "common/event.h"
#include "common/thread.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
@ -36,9 +37,11 @@ struct iface
bool stop; bool stop;
NvFBCHandle nvfbc; NvFBCHandle nvfbc;
bool seperateCursor; bool seperateCursor;
void * pointerShape; CaptureGetPointerBuffer getPointerBufferFn;
unsigned int pointerSize; CapturePostPointerBuffer postPointerBufferFn;
LGThread * pointerThread;
unsigned int maxWidth, maxHeight; unsigned int maxWidth, maxHeight;
unsigned int width , height; unsigned int width , height;
@ -56,6 +59,7 @@ struct iface
static struct iface * this = NULL; static struct iface * this = NULL;
static void nvfbc_free(); static void nvfbc_free();
static int pointerThread(void * unused);
static void getDesktopSize(unsigned int * width, unsigned int * height) static void getDesktopSize(unsigned int * width, unsigned int * height)
{ {
@ -148,11 +152,13 @@ static bool nvfbc_create()
return true; return true;
} }
static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize) static bool nvfbc_init(
CaptureGetPointerBuffer getPointerBufferFn,
CapturePostPointerBuffer postPointerBufferFn)
{ {
this->stop = false; this->stop = false;
this->pointerShape = pointerShape; this->getPointerBufferFn = getPointerBufferFn;
this->pointerSize = pointerSize; this->postPointerBufferFn = postPointerBufferFn;
getDesktopSize(&this->width, &this->height); getDesktopSize(&this->width, &this->height);
lgResetEvent(this->frameEvent); lgResetEvent(this->frameEvent);
@ -183,6 +189,13 @@ static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize)
DEBUG_INFO("Cursor mode : %s", this->seperateCursor ? "decoupled" : "integrated"); DEBUG_INFO("Cursor mode : %s", this->seperateCursor ? "decoupled" : "integrated");
Sleep(100); Sleep(100);
if (!lgCreateThread("NvFBCPointer", pointerThread, NULL, &this->pointerThread))
{
DEBUG_ERROR("Failed to create the NvFBCPointer thread");
return false;
}
return true; return true;
} }
@ -191,6 +204,12 @@ static void nvfbc_stop()
this->stop = true; this->stop = true;
lgSignalEvent(this->cursorEvents[0]); lgSignalEvent(this->cursorEvents[0]);
lgSignalEvent(this->frameEvent); lgSignalEvent(this->frameEvent);
if (this->pointerThread)
{
lgJoinThread(this->pointerThread, NULL);
this->pointerThread = NULL;
}
} }
static bool nvfbc_deinit() static bool nvfbc_deinit()
@ -280,32 +299,51 @@ static CaptureResult nvfbc_getFrame(FrameBuffer frame)
return CAPTURE_RESULT_OK; return CAPTURE_RESULT_OK;
} }
static CaptureResult nvfbc_getPointer(CapturePointer * pointer) static int pointerThread(void * unused)
{ {
LGEvent * events[2]; while(!this->stop)
memcpy(&events, &this->cursorEvents, sizeof(LGEvent *) * 2);
if (!lgWaitEvents(events, this->seperateCursor ? 2 : 1, false, 1000))
return CAPTURE_RESULT_TIMEOUT;
if (this->stop)
return CAPTURE_RESULT_REINIT;
CaptureResult result;
pointer->shapeUpdate = false;
if (this->seperateCursor && events[1])
{ {
result = NvFBCToSysGetCursor(this->nvfbc, pointer, this->pointerShape, this->pointerSize); LGEvent * events[2];
this->mouseVisible = pointer->visible; memcpy(&events, &this->cursorEvents, sizeof(LGEvent *) * 2);
this->mouseHotX = pointer->x; if (!lgWaitEvents(events, this->seperateCursor ? 2 : 1, false, 1000))
this->mouseHotY = pointer->y; continue;
if (result != CAPTURE_RESULT_OK)
return result; if (this->stop)
break;
CaptureResult result;
CapturePointer pointer = { 0 };
pointer.shapeUpdate = false;
if (this->seperateCursor && events[1])
{
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;
}
pointer.visible = this->mouseVisible;
pointer.x = this->mouseX - this->mouseHotX;
pointer.y = this->mouseY - this->mouseHotY;
this->postPointerBufferFn(pointer);
} }
pointer->visible = this->mouseVisible; return 0;
pointer->x = this->mouseX - this->mouseHotX;
pointer->y = this->mouseY - this->mouseHotY;
return CAPTURE_RESULT_OK;
} }
struct CaptureInterface Capture_NVFBC = struct CaptureInterface Capture_NVFBC =
@ -321,6 +359,5 @@ struct CaptureInterface Capture_NVFBC =
.getMaxFrameSize = nvfbc_getMaxFrameSize, .getMaxFrameSize = nvfbc_getMaxFrameSize,
.capture = nvfbc_capture, .capture = nvfbc_capture,
.waitFrame = nvfbc_waitFrame, .waitFrame = nvfbc_waitFrame,
.getFrame = nvfbc_getFrame, .getFrame = nvfbc_getFrame
.getPointer = nvfbc_getPointer
}; };