[host] implemented variable cursor buffer size

This commit is contained in:
Geoffrey McRae 2017-12-15 11:30:25 +11:00
parent 8ae9f8464b
commit 0948dda12f
2 changed files with 114 additions and 66 deletions

View File

@ -41,7 +41,11 @@ Service::Service() :
m_timer(NULL), m_timer(NULL),
m_capture(NULL), m_capture(NULL),
m_header(NULL), m_header(NULL),
m_frameIndex(0) m_frameIndex(0),
m_cursorDataSize(0),
m_cursorData(NULL),
m_haveShape(false),
m_shapePending(false)
{ {
m_ivshmem = IVSHMEM::Get(); m_ivshmem = IVSHMEM::Get();
} }
@ -130,6 +134,16 @@ void Service::DeInitialize()
m_timer = NULL; m_timer = NULL;
} }
m_haveShape = false;
m_shapePending = false;
if (m_cursorData)
{
delete[] m_cursorData;
m_cursorDataSize = 0;
m_cursorData = NULL;
}
m_header = NULL; m_header = NULL;
m_frame[0] = NULL; m_frame[0] = NULL;
m_frame[1] = NULL; m_frame[1] = NULL;
@ -194,6 +208,12 @@ bool Service::Process()
bool ok = false; bool ok = false;
bool cursorOnly = false; bool cursorOnly = false;
if (m_shapePending)
{
ok = true;
cursorOnly = true;
}
else
for(int i = 0; i < 2; ++i) for(int i = 0; i < 2; ++i)
{ {
// capture a frame of data // capture a frame of data
@ -248,52 +268,77 @@ bool Service::Process()
m_frameIndex = 0; m_frameIndex = 0;
} }
if (frame.cursor.hasPos) if (frame.cursor.hasPos || (m_cursor.hasPos && restart))
{ {
// tell the host where the cursor is if (!restart)
updateFlags |= KVMFR_HEADER_FLAG_CURSOR; {
m_header->cursor.flags |= KVMFR_CURSOR_FLAG_POS; // remember the last state for client restart
if (frame.cursor.visible) m_cursor.hasPos = true;
m_header->cursor.flags |= KVMFR_CURSOR_FLAG_VISIBLE; m_cursor.visible = frame.cursor.visible;
m_header->cursor.x = frame.cursor.x;
m_header->cursor.y = frame.cursor.y;
// update our local copy for client restarts
m_cursor.flags = m_header->cursor.flags;
m_cursor.x = frame.cursor.x; m_cursor.x = frame.cursor.x;
m_cursor.y = frame.cursor.y; m_cursor.y = frame.cursor.y;
} }
if (frame.cursor.hasShape) // tell the host where the cursor is
updateFlags |= KVMFR_HEADER_FLAG_CURSOR;
m_header->cursor.flags |= KVMFR_CURSOR_FLAG_POS;
if (m_cursor.visible)
m_header->cursor.flags |= KVMFR_CURSOR_FLAG_VISIBLE;
m_header->cursor.x = m_cursor.x;
m_header->cursor.y = m_cursor.y;
}
if (frame.cursor.hasShape || m_shapePending || (m_cursor.hasShape && restart))
{
if (!m_shapePending)
{
if (frame.cursor.dataSize > m_frameSize)
{
DEBUG_ERROR("Cursor size exceeds frame size! This should never happen unless your shared memory is WAY too small");
return false;
}
// take a copy of the shape information for client restarts or pending shape changes
m_cursor.hasShape = frame.cursor.hasShape;
m_cursor.type = frame.cursor.type;
m_cursor.w = frame.cursor.w;
m_cursor.h = frame.cursor.h;
m_cursor.pitch = frame.cursor.pitch;
m_cursor.dataSize = frame.cursor.dataSize;
memcpy(&m_cursor, &frame.cursor, sizeof(CursorInfo));
if (m_cursorDataSize < frame.cursor.dataSize)
{
delete[] m_cursorData;
m_cursorData = new uint8_t[frame.cursor.dataSize];
m_cursorDataSize = frame.cursor.dataSize;
}
memcpy(m_cursorData, frame.cursor.shape, frame.cursor.dataSize);
m_haveShape = true;
}
// we can't send a frame with the cursor shape as we need the buffer location
// flag it to send on the next packet
if (updateFlags & KVMFR_HEADER_FLAG_FRAME)
m_shapePending = true;
else
{ {
// give the host the new cursor shape // give the host the new cursor shape
updateFlags |= KVMFR_HEADER_FLAG_CURSOR; updateFlags |= KVMFR_HEADER_FLAG_CURSOR;
m_header->cursor.flags |= KVMFR_CURSOR_FLAG_SHAPE; m_header->cursor.flags |= KVMFR_CURSOR_FLAG_SHAPE;
m_header->cursor.type = frame.cursor.type; if (m_cursor.visible)
m_header->cursor.w = frame.cursor.w; m_header->cursor.flags |= KVMFR_CURSOR_FLAG_VISIBLE;
m_header->cursor.h = frame.cursor.h;
m_header->cursor.pitch = frame.cursor.pitch;
if (frame.cursor.dataSize > KVMFR_CURSOR_BUFFER)
{
DEBUG_ERROR("Cursor shape size exceeds buffer size");
return false;
}
memcpy(m_header->cursor.shape, frame.cursor.shape, frame.cursor.dataSize);
// take a copy of the information for client restarts m_header->cursor.type = m_cursor.type;
uint8_t f = m_cursor.flags; m_header->cursor.w = m_cursor.w;
memcpy(&m_cursor, &m_header->cursor, sizeof(KVMFRCursor)); m_header->cursor.h = m_cursor.h;
m_cursor.flags = f | m_header->cursor.flags; m_header->cursor.pitch = m_cursor.pitch;
m_haveShape = true; m_header->cursor.dataPos = m_dataOffset[m_frameIndex];
} memcpy(m_frame[m_frameIndex], m_cursorData, m_cursor.dataSize);
else m_shapePending = false;
{
// if we already have a shape and the client restarted send it to them if (++m_frameIndex == 2)
if (restart && m_haveShape) m_frameIndex = 0;
{
updateFlags |= KVMFR_HEADER_FLAG_CURSOR;
m_cursor.flags |= KVMFR_CURSOR_FLAG_SHAPE;
memcpy(&m_header->cursor, &m_cursor, sizeof(KVMFRCursor));
} }
} }

View File

@ -60,6 +60,9 @@ private:
uint64_t m_dataOffset[2]; uint64_t m_dataOffset[2];
int m_frameIndex; int m_frameIndex;
KVMFRCursor m_cursor; CursorInfo m_cursor;
size_t m_cursorDataSize;
uint8_t * m_cursorData;
bool m_haveShape; bool m_haveShape;
bool m_shapePending;
}; };