2017-10-31 16:53:06 +00:00
|
|
|
/*
|
2017-12-03 15:31:16 +00:00
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
2017-10-31 16:53:06 +00:00
|
|
|
Copyright (C) 2017 Geoffrey McRae <geoff@hostfission.com>
|
2017-12-11 17:30:47 +00:00
|
|
|
https://looking-glass.hostfission.com
|
2017-10-31 16:53:06 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2017-10-31 12:22:55 +00:00
|
|
|
#include "Service.h"
|
|
|
|
#include "IVSHMEM.h"
|
2018-10-03 14:07:34 +00:00
|
|
|
#include "TraceUtil.h"
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2017-12-14 19:11:41 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/KVMFR.h"
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2017-12-21 02:48:57 +00:00
|
|
|
#include "Util.h"
|
2017-10-31 12:21:05 +00:00
|
|
|
#include "CaptureFactory.h"
|
|
|
|
|
|
|
|
Service::Service() :
|
|
|
|
m_initialized(false),
|
2017-12-07 19:24:17 +00:00
|
|
|
m_memory(NULL),
|
2017-12-13 15:22:41 +00:00
|
|
|
m_timer(NULL),
|
2017-10-31 12:21:05 +00:00
|
|
|
m_capture(NULL),
|
2017-12-15 23:04:56 +00:00
|
|
|
m_shmHeader(NULL),
|
2017-12-15 00:30:25 +00:00
|
|
|
m_frameIndex(0),
|
|
|
|
m_cursorDataSize(0),
|
2017-12-19 13:58:42 +00:00
|
|
|
m_cursorData(NULL)
|
2017-10-31 12:21:05 +00:00
|
|
|
{
|
2017-12-16 17:50:04 +00:00
|
|
|
m_consoleSessionID = WTSGetActiveConsoleSessionId();
|
2017-10-31 12:21:05 +00:00
|
|
|
m_ivshmem = IVSHMEM::Get();
|
2019-01-11 12:58:50 +00:00
|
|
|
|
|
|
|
if (!m_ivshmem->Initialize())
|
|
|
|
throw "IVSHMEM failed to initalize";
|
|
|
|
|
|
|
|
if (m_ivshmem->GetSize() < sizeof(KVMFRHeader))
|
|
|
|
throw "Shared memory is not large enough for the KVMFRHeader";
|
|
|
|
|
|
|
|
m_memory = static_cast<uint8_t*>(m_ivshmem->GetMemory());
|
|
|
|
if (!m_memory)
|
|
|
|
throw "Failed to get IVSHMEM memory";
|
|
|
|
|
|
|
|
if (!InitPointers())
|
|
|
|
throw "Failed to initialize the shared memory pointers";
|
2017-10-31 12:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Service::~Service()
|
|
|
|
{
|
2019-01-11 12:58:50 +00:00
|
|
|
DeInitialize();
|
2017-10-31 12:21:05 +00:00
|
|
|
}
|
|
|
|
|
2019-01-11 12:58:50 +00:00
|
|
|
LRESULT Service::LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
|
2017-10-31 12:21:05 +00:00
|
|
|
{
|
2019-01-11 12:58:50 +00:00
|
|
|
if (nCode == HC_ACTION && wParam == WM_MOUSEMOVE)
|
2017-10-31 12:21:05 +00:00
|
|
|
{
|
2019-01-11 12:58:50 +00:00
|
|
|
MSLLHOOKSTRUCT *msg = (MSLLHOOKSTRUCT *)lParam;
|
|
|
|
volatile KVMFRCursor * cursor = &(m_shmHeader->cursor);
|
|
|
|
volatile char * flags = (volatile char *)&(cursor->flags);
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2019-02-07 03:42:57 +00:00
|
|
|
cursor->x = (int16_t)msg->pt.x;
|
|
|
|
cursor->y = (int16_t)msg->pt.y;
|
2019-01-11 12:58:50 +00:00
|
|
|
INTERLOCKED_OR8(flags, KVMFR_CURSOR_FLAG_POS);
|
2017-10-31 12:21:05 +00:00
|
|
|
}
|
2019-01-11 12:58:50 +00:00
|
|
|
return CallNextHookEx(m_mouseHook, nCode, wParam, lParam);
|
|
|
|
}
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2019-01-11 12:58:50 +00:00
|
|
|
bool Service::Initialize(ICapture * captureDevice)
|
|
|
|
{
|
|
|
|
if (m_initialized)
|
2017-10-31 12:21:05 +00:00
|
|
|
DeInitialize();
|
|
|
|
|
2019-01-11 12:58:50 +00:00
|
|
|
m_tryTarget = 0;
|
|
|
|
m_capture = captureDevice;
|
2017-12-28 19:10:50 +00:00
|
|
|
|
|
|
|
if (m_capture->GetMaxFrameSize() > m_frameSize)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Maximum frame size of %zu bytes excceds maximum space available", m_capture->GetMaxFrameSize());
|
|
|
|
DeInitialize();
|
2017-12-07 19:24:17 +00:00
|
|
|
return false;
|
2017-12-28 19:10:50 +00:00
|
|
|
}
|
2017-12-07 19:24:17 +00:00
|
|
|
|
2018-05-24 01:24:24 +00:00
|
|
|
// Create the cursor thread
|
2019-01-11 12:58:50 +00:00
|
|
|
m_cursorThread = CreateThread(NULL, 0, _CursorThread, NULL, 0, NULL);
|
2018-05-24 01:24:24 +00:00
|
|
|
m_cursorEvent = CreateEvent (NULL, FALSE, FALSE, L"CursorEvent");
|
2018-05-24 06:43:16 +00:00
|
|
|
InitializeCriticalSection(&m_cursorCS);
|
2018-05-24 01:24:24 +00:00
|
|
|
|
2017-12-13 10:06:03 +00:00
|
|
|
// update everything except for the hostID
|
2017-12-15 23:04:56 +00:00
|
|
|
memcpy(m_shmHeader->magic, KVMFR_HEADER_MAGIC, sizeof(KVMFR_HEADER_MAGIC));
|
2017-12-19 13:58:42 +00:00
|
|
|
m_shmHeader->version = KVMFR_HEADER_VERSION;
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2018-05-24 01:24:24 +00:00
|
|
|
// zero and tell the client we have restarted
|
2018-09-29 17:50:43 +00:00
|
|
|
ZeroMemory(&(m_shmHeader->frame ), sizeof(KVMFRFrame ));
|
|
|
|
ZeroMemory(&(m_shmHeader->cursor), sizeof(KVMFRCursor));
|
2018-05-24 01:24:24 +00:00
|
|
|
m_shmHeader->flags &= ~KVMFR_HEADER_FLAG_RESTART;
|
2017-12-13 10:06:03 +00:00
|
|
|
|
2018-07-25 17:08:52 +00:00
|
|
|
m_haveFrame = false;
|
2017-10-31 12:21:05 +00:00
|
|
|
m_initialized = true;
|
2018-10-19 10:16:08 +00:00
|
|
|
m_running = true;
|
2017-10-31 12:21:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-28 19:10:50 +00:00
|
|
|
#define ALIGN_DN(x) ((uintptr_t)(x) & ~0x7F)
|
|
|
|
#define ALIGN_UP(x) ALIGN_DN(x + 0x7F)
|
|
|
|
|
2017-12-07 19:24:17 +00:00
|
|
|
bool Service::InitPointers()
|
|
|
|
{
|
2017-12-19 13:58:42 +00:00
|
|
|
m_shmHeader = reinterpret_cast<KVMFRHeader *>(m_memory);
|
2017-12-28 19:10:50 +00:00
|
|
|
m_cursorData = (uint8_t *)ALIGN_UP(m_memory + sizeof(KVMFRHeader));
|
|
|
|
m_cursorDataSize = 1048576; // 1MB fixed for cursor size, should be more then enough
|
2018-07-25 17:08:52 +00:00
|
|
|
m_cursorOffset = m_cursorData - m_memory;
|
2017-12-28 19:10:50 +00:00
|
|
|
|
2018-07-25 17:08:52 +00:00
|
|
|
uint8_t * m_frames = (uint8_t *)ALIGN_UP(m_cursorData + m_cursorDataSize);
|
|
|
|
m_frameSize = ALIGN_DN((m_ivshmem->GetSize() - (m_frames - m_memory)) / MAX_FRAMES);
|
2017-12-07 19:24:17 +00:00
|
|
|
|
2018-01-30 10:07:46 +00:00
|
|
|
DEBUG_INFO("Total Available : %3u MB", (unsigned int)(m_ivshmem->GetSize() / 1024 / 1024));
|
|
|
|
DEBUG_INFO("Max Cursor Size : %3u MB", (unsigned int)(m_cursorDataSize / 1024 / 1024));
|
|
|
|
DEBUG_INFO("Max Frame Size : %3u MB", (unsigned int)(m_frameSize / 1024 / 1024));
|
2018-07-25 17:08:52 +00:00
|
|
|
DEBUG_INFO("Cursor : %p (0x%08x)", m_cursorData, (int)m_cursorOffset);
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_FRAMES; ++i)
|
|
|
|
{
|
|
|
|
m_frame[i] = m_frames + i * m_frameSize;
|
|
|
|
m_dataOffset[i] = m_frame[i] - m_memory;
|
|
|
|
DEBUG_INFO("Frame %d : %p (0x%08x)", i, m_frame[i], (int)m_dataOffset[i]);
|
|
|
|
}
|
2017-12-07 19:24:17 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-31 12:21:05 +00:00
|
|
|
void Service::DeInitialize()
|
|
|
|
{
|
2018-10-19 10:16:08 +00:00
|
|
|
m_running = false;
|
|
|
|
|
2018-07-25 17:08:52 +00:00
|
|
|
WaitForSingleObject(m_cursorThread, INFINITE);
|
|
|
|
CloseHandle(m_cursorThread);
|
|
|
|
CloseHandle(m_cursorEvent);
|
2017-10-31 13:51:53 +00:00
|
|
|
|
2017-12-19 13:58:42 +00:00
|
|
|
m_shmHeader = NULL;
|
|
|
|
m_cursorData = NULL;
|
|
|
|
m_cursorDataSize = 0;
|
2018-07-25 17:08:52 +00:00
|
|
|
m_cursorOffset = 0;
|
|
|
|
m_haveFrame = false;
|
2017-12-03 11:03:22 +00:00
|
|
|
|
2018-07-25 17:08:52 +00:00
|
|
|
for(int i = 0; i < MAX_FRAMES; ++i)
|
|
|
|
{
|
|
|
|
m_frame [i] = NULL;
|
|
|
|
m_dataOffset[i] = 0;
|
|
|
|
}
|
|
|
|
m_frameSize = 0;
|
2018-05-31 08:51:28 +00:00
|
|
|
|
2017-10-31 13:51:53 +00:00
|
|
|
m_ivshmem->DeInitialize();
|
|
|
|
|
2017-10-31 12:21:05 +00:00
|
|
|
if (m_capture)
|
|
|
|
{
|
|
|
|
m_capture->DeInitialize();
|
|
|
|
m_capture = NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-07 19:24:17 +00:00
|
|
|
m_memory = NULL;
|
2017-10-31 12:21:05 +00:00
|
|
|
m_initialized = false;
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
bool Service::ReInit(volatile char * flags)
|
2017-10-31 12:21:05 +00:00
|
|
|
{
|
2018-11-02 10:37:26 +00:00
|
|
|
DEBUG_INFO("ReInitialize Requested");
|
|
|
|
|
|
|
|
INTERLOCKED_OR8(flags, KVMFR_HEADER_FLAG_PAUSED);
|
|
|
|
if (WTSGetActiveConsoleSessionId() != m_consoleSessionID)
|
|
|
|
{
|
|
|
|
DEBUG_INFO("User switch detected, waiting to regain control");
|
|
|
|
while (WTSGetActiveConsoleSessionId() != m_consoleSessionID)
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!m_capture->CanInitialize())
|
|
|
|
Sleep(100);
|
|
|
|
|
|
|
|
if (!m_capture->ReInitialize())
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("ReInitialize Failed");
|
2017-10-31 12:21:05 +00:00
|
|
|
return false;
|
2018-11-02 10:37:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_capture->GetMaxFrameSize() > m_frameSize)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Maximum frame size of %zd bytes excceds maximum space available", m_capture->GetMaxFrameSize());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERLOCKED_AND8(flags, ~KVMFR_HEADER_FLAG_PAUSED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessStatus Service::Process()
|
|
|
|
{
|
|
|
|
if (!m_initialized)
|
|
|
|
return PROCESS_STATUS_ERROR;
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2018-10-03 14:07:34 +00:00
|
|
|
volatile char * flags = (volatile char *)&(m_shmHeader->flags);
|
2017-12-13 19:56:08 +00:00
|
|
|
|
2018-09-29 17:50:43 +00:00
|
|
|
// check if the client has flagged a restart
|
|
|
|
if (*flags & KVMFR_HEADER_FLAG_RESTART)
|
2017-11-15 06:28:17 +00:00
|
|
|
{
|
2018-09-29 17:50:43 +00:00
|
|
|
DEBUG_INFO("Restart Requested");
|
|
|
|
if (!m_capture->ReInitialize())
|
2017-12-13 10:06:03 +00:00
|
|
|
{
|
2018-09-29 17:50:43 +00:00
|
|
|
DEBUG_ERROR("ReInitialize Failed");
|
2018-11-02 10:37:26 +00:00
|
|
|
return PROCESS_STATUS_ERROR;
|
2017-12-13 10:06:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 17:50:43 +00:00
|
|
|
if (m_capture->GetMaxFrameSize() > m_frameSize)
|
2018-09-26 11:20:17 +00:00
|
|
|
{
|
2018-09-29 17:50:43 +00:00
|
|
|
DEBUG_ERROR("Maximum frame size of %zd bytes exceeds maximum space available", m_capture->GetMaxFrameSize());
|
2018-11-02 10:37:26 +00:00
|
|
|
return PROCESS_STATUS_ERROR;
|
2018-09-26 11:20:17 +00:00
|
|
|
}
|
2017-12-03 11:03:22 +00:00
|
|
|
|
2018-10-03 14:07:34 +00:00
|
|
|
INTERLOCKED_AND8(flags, ~(KVMFR_HEADER_FLAG_RESTART));
|
2018-09-29 17:50:43 +00:00
|
|
|
}
|
2018-09-26 11:20:17 +00:00
|
|
|
|
2018-10-09 06:48:44 +00:00
|
|
|
unsigned int status;
|
2018-11-02 10:37:26 +00:00
|
|
|
bool notify = false;
|
2018-10-09 06:48:44 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
status = m_capture->Capture();
|
|
|
|
if (status & GRAB_STATUS_ERROR)
|
2017-12-07 19:24:17 +00:00
|
|
|
{
|
2018-11-02 10:37:26 +00:00
|
|
|
DEBUG_WARN("Capture error, retrying");
|
|
|
|
return PROCESS_STATUS_RETRY;
|
|
|
|
}
|
2017-12-28 19:10:50 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
if (status & GRAB_STATUS_TIMEOUT)
|
|
|
|
{
|
|
|
|
// timeouts should not count towards a failure to capture
|
|
|
|
if (!m_haveFrame)
|
|
|
|
return PROCESS_STATUS_OK;
|
2018-05-29 08:36:37 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
notify = true;
|
|
|
|
}
|
2018-07-23 15:11:19 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
if (status & GRAB_STATUS_REINIT)
|
|
|
|
{
|
|
|
|
if (!ReInit(flags))
|
|
|
|
return PROCESS_STATUS_ERROR;
|
2017-12-07 19:24:17 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
// re-init request should not count towards a failure to capture
|
|
|
|
return PROCESS_STATUS_OK;
|
2017-12-19 13:58:42 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
if ((status & (GRAB_STATUS_OK | GRAB_STATUS_TIMEOUT)) == 0)
|
2017-12-03 11:03:22 +00:00
|
|
|
{
|
2018-11-02 10:37:26 +00:00
|
|
|
DEBUG_ERROR("Capture interface returned an unexpected result");
|
|
|
|
return PROCESS_STATUS_ERROR;
|
2017-12-03 11:03:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 06:48:44 +00:00
|
|
|
if (status & GRAB_STATUS_CURSOR)
|
|
|
|
SetEvent(m_cursorEvent);
|
2018-05-24 07:05:49 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
volatile KVMFRFrame * fi = &(m_shmHeader->frame);
|
2018-10-09 06:48:44 +00:00
|
|
|
if (status & GRAB_STATUS_FRAME)
|
2018-11-02 10:37:26 +00:00
|
|
|
{
|
|
|
|
FrameInfo frame = { 0 };
|
|
|
|
frame.buffer = m_frame[m_frameIndex];
|
|
|
|
frame.bufferSize = m_frameSize;
|
2018-09-29 17:50:43 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
GrabStatus result = m_capture->GetFrame(frame);
|
|
|
|
if (result != GRAB_STATUS_OK)
|
|
|
|
{
|
|
|
|
if (result == GRAB_STATUS_REINIT)
|
2018-10-03 14:07:34 +00:00
|
|
|
{
|
2018-11-02 10:37:26 +00:00
|
|
|
if (!ReInit(flags))
|
|
|
|
return PROCESS_STATUS_ERROR;
|
2018-09-29 17:50:43 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
// re-init request should not count towards a failure to capture
|
|
|
|
return PROCESS_STATUS_OK;
|
2018-09-29 17:50:43 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
DEBUG_INFO("GetFrame failed");
|
|
|
|
return PROCESS_STATUS_ERROR;
|
2018-09-29 17:50:43 +00:00
|
|
|
}
|
2018-11-02 10:37:26 +00:00
|
|
|
|
|
|
|
/* don't touch the frame information until the client is done with it */
|
|
|
|
while (fi->flags & KVMFR_FRAME_FLAG_UPDATE)
|
2018-09-29 17:50:43 +00:00
|
|
|
{
|
2018-11-02 10:37:26 +00:00
|
|
|
/* this generally never occurs */
|
|
|
|
Sleep(1);
|
|
|
|
if (*flags & KVMFR_HEADER_FLAG_RESTART)
|
|
|
|
break;
|
2018-09-29 17:50:43 +00:00
|
|
|
}
|
2018-07-25 17:08:52 +00:00
|
|
|
|
2018-11-02 10:37:26 +00:00
|
|
|
fi->type = m_capture->GetFrameType();
|
|
|
|
fi->width = frame.width;
|
|
|
|
fi->height = frame.height;
|
|
|
|
fi->stride = frame.stride;
|
|
|
|
fi->pitch = frame.pitch;
|
|
|
|
fi->dataPos = m_dataOffset[m_frameIndex];
|
|
|
|
|
|
|
|
if (++m_frameIndex == MAX_FRAMES)
|
|
|
|
m_frameIndex = 0;
|
|
|
|
|
|
|
|
// remember that we have a valid frame
|
|
|
|
m_haveFrame = true;
|
|
|
|
notify = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notify)
|
|
|
|
{
|
|
|
|
/* don't touch the frame inforamtion until the client is done with it */
|
|
|
|
while (fi->flags & KVMFR_FRAME_FLAG_UPDATE)
|
|
|
|
{
|
|
|
|
if (*flags & KVMFR_HEADER_FLAG_RESTART)
|
|
|
|
break;
|
|
|
|
}
|
2018-05-24 01:24:24 +00:00
|
|
|
// signal a frame update
|
|
|
|
fi->flags |= KVMFR_FRAME_FLAG_UPDATE;
|
2017-12-11 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 01:24:24 +00:00
|
|
|
// update the flags
|
2018-10-03 14:07:34 +00:00
|
|
|
INTERLOCKED_AND8(flags, KVMFR_HEADER_FLAG_RESTART);
|
2018-11-02 10:37:26 +00:00
|
|
|
return PROCESS_STATUS_OK;
|
2018-05-24 01:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD Service::CursorThread()
|
|
|
|
{
|
2018-10-19 10:16:08 +00:00
|
|
|
while(m_running)
|
2017-12-11 20:56:50 +00:00
|
|
|
{
|
2018-05-24 01:24:24 +00:00
|
|
|
if (WaitForSingleObject(m_cursorEvent, 1000) != WAIT_OBJECT_0)
|
|
|
|
continue;
|
|
|
|
|
2018-10-03 14:07:34 +00:00
|
|
|
CursorInfo ci;
|
|
|
|
while (m_capture->GetCursor(ci))
|
2017-12-13 10:45:58 +00:00
|
|
|
{
|
2018-10-03 14:07:34 +00:00
|
|
|
volatile KVMFRCursor * cursor = &(m_shmHeader->cursor);
|
|
|
|
// wait until the client is ready
|
2019-01-11 12:58:50 +00:00
|
|
|
while ((cursor->flags & ~KVMFR_CURSOR_FLAG_POS) != 0)
|
2018-10-03 14:07:34 +00:00
|
|
|
{
|
|
|
|
Sleep(1);
|
|
|
|
if (!m_capture)
|
|
|
|
return 0;
|
|
|
|
}
|
2017-12-03 11:03:22 +00:00
|
|
|
|
2019-01-11 12:58:50 +00:00
|
|
|
uint8_t flags = cursor->flags;
|
2018-05-28 00:34:24 +00:00
|
|
|
|
2018-10-03 14:07:34 +00:00
|
|
|
if (ci.hasPos)
|
|
|
|
{
|
|
|
|
cursor->x = ci.x;
|
|
|
|
cursor->y = ci.y;
|
2019-01-11 12:58:50 +00:00
|
|
|
flags |= KVMFR_CURSOR_FLAG_POS;
|
2018-10-03 14:07:34 +00:00
|
|
|
}
|
2018-05-24 01:24:24 +00:00
|
|
|
|
2018-10-19 09:14:00 +00:00
|
|
|
if (ci.hasShape)
|
2018-05-24 06:43:16 +00:00
|
|
|
{
|
2018-10-19 09:14:00 +00:00
|
|
|
if (ci.shape.pointerSize > m_cursorDataSize)
|
2018-10-03 14:07:34 +00:00
|
|
|
DEBUG_ERROR("Cursor size exceeds allocated space");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// give the client the new cursor shape
|
|
|
|
flags |= KVMFR_CURSOR_FLAG_SHAPE;
|
|
|
|
++cursor->version;
|
2018-05-24 01:24:24 +00:00
|
|
|
|
2018-10-03 14:07:34 +00:00
|
|
|
cursor->type = ci.type;
|
|
|
|
cursor->width = ci.w;
|
|
|
|
cursor->height = ci.h;
|
|
|
|
cursor->pitch = ci.pitch;
|
|
|
|
cursor->dataPos = m_cursorOffset;
|
2018-05-24 01:24:24 +00:00
|
|
|
|
2018-10-19 09:14:00 +00:00
|
|
|
memcpy(m_cursorData, ci.shape.buffer, ci.shape.bufferSize);
|
2018-10-03 14:07:34 +00:00
|
|
|
}
|
2018-05-24 06:43:16 +00:00
|
|
|
}
|
2018-05-24 01:24:24 +00:00
|
|
|
|
2018-10-09 07:28:08 +00:00
|
|
|
if (ci.visible)
|
|
|
|
flags |= KVMFR_CURSOR_FLAG_VISIBLE;
|
|
|
|
|
|
|
|
flags |= KVMFR_CURSOR_FLAG_UPDATE;
|
2018-10-03 14:07:34 +00:00
|
|
|
cursor->flags = flags;
|
2018-10-19 09:14:00 +00:00
|
|
|
m_capture->FreeCursor();
|
2018-10-03 14:07:34 +00:00
|
|
|
}
|
2018-05-24 01:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-10-31 16:53:06 +00:00
|
|
|
}
|