[client] updates for new protocol and vsync disable method

This commit is contained in:
Geoffrey McRae 2017-12-12 08:08:14 +11:00
parent 818164da7f
commit 301d394f50

View File

@ -145,15 +145,15 @@ int renderThread(void * unused)
{ {
bool error = false; bool error = false;
struct KVMFRHeader header; struct KVMFRHeader header;
volatile uint64_t * dataPos = &state.shm->dataPos; volatile int32_t * updateCount = &state.shm->updateCount - 1;
while(state.running) while(state.running)
{ {
// if the next frame isn't aready available // if the next frame isn't aready available
if (header.dataPos == *dataPos) if (header.updateCount == *updateCount)
{ {
// poll until we have a new frame, or we time out // poll until we have a new frame, or we time out
while(header.dataPos == *dataPos && state.running) { while(header.updateCount == *updateCount && state.running) {
const struct timespec s = { const struct timespec s = {
.tv_sec = 0, .tv_sec = 0,
.tv_nsec = 1000 .tv_nsec = 1000
@ -174,35 +174,41 @@ int renderThread(void * unused)
// check the header's magic and version are valid // check the header's magic and version are valid
if ( if (
memcmp(header.magic, KVMFR_HEADER_MAGIC, sizeof(KVMFR_HEADER_MAGIC)) != 0 || memcmp(header.magic, KVMFR_HEADER_MAGIC, sizeof(KVMFR_HEADER_MAGIC)) != 0 ||
header.version != KVMFR_HEADER_VERSION || header.version != KVMFR_HEADER_VERSION
( ){
header.dataPos == 0 || usleep(1000);
header.width == 0 || continue;
header.height == 0 || }
header.stride == 0 ||
header.frameType >= FRAME_TYPE_MAX if(header.flags & KVMFR_HEADER_FLAG_FRAME)
)
)
{ {
if (
header.frame.type >= FRAME_TYPE_MAX ||
header.frame.width == 0 ||
header.frame.height == 0 ||
header.frame.stride == 0 ||
header.frame.dataPos == 0 ||
header.frame.dataPos > state.shmSize
){
usleep(1000); usleep(1000);
continue; continue;
} }
// setup the renderer format with the frame format details // setup the renderer format with the frame format details
LG_RendererFormat lgrFormat; LG_RendererFormat lgrFormat;
lgrFormat.width = header.width; lgrFormat.width = header.frame.width;
lgrFormat.height = header.height; lgrFormat.height = header.frame.height;
lgrFormat.stride = header.stride; lgrFormat.stride = header.frame.stride;
switch(header.frameType) switch(header.frame.type)
{ {
case FRAME_TYPE_ARGB: case FRAME_TYPE_ARGB:
lgrFormat.pitch = header.stride * 4; lgrFormat.pitch = header.frame.stride * 4;
lgrFormat.bpp = 32; lgrFormat.bpp = 32;
break; break;
case FRAME_TYPE_RGB: case FRAME_TYPE_RGB:
lgrFormat.pitch = header.stride * 3; lgrFormat.pitch = header.frame.stride * 3;
lgrFormat.bpp = 24; lgrFormat.bpp = 24;
break; break;
@ -217,7 +223,7 @@ int renderThread(void * unused)
// check the header's dataPos is sane // check the header's dataPos is sane
const size_t dataSize = lgrFormat.height * lgrFormat.pitch; const size_t dataSize = lgrFormat.height * lgrFormat.pitch;
if (header.dataPos + dataSize > state.shmSize) if (header.frame.dataPos + dataSize > state.shmSize)
{ {
DEBUG_ERROR("The guest sent an invalid dataPos"); DEBUG_ERROR("The guest sent an invalid dataPos");
break; break;
@ -286,16 +292,16 @@ int renderThread(void * unused)
} }
} }
state.srcSize.x = header.width; state.srcSize.x = header.frame.width;
state.srcSize.y = header.height; state.srcSize.y = header.frame.height;
if (params.autoResize) if (params.autoResize)
SDL_SetWindowSize(state.window, header.width, header.height); SDL_SetWindowSize(state.window, header.frame.width, header.frame.height);
updatePositionInfo(); updatePositionInfo();
} }
if (!state.lgr->render( if (!state.lgr->render(
state.lgrData, state.lgrData,
(uint8_t *)state.shm + header.dataPos, (uint8_t *)state.shm + header.frame.dataPos,
params.useMipmap params.useMipmap
)) ))
{ {
@ -303,6 +309,7 @@ int renderThread(void * unused)
break; break;
} }
} }
}
if (state.lgr) if (state.lgr)
state.lgr->deinitialize(state.lgrData); state.lgr->deinitialize(state.lgrData);
@ -477,8 +484,8 @@ int eventThread(void * arg)
x = (float)x * state.scaleX; x = (float)x * state.scaleX;
y = (float)y * state.scaleY; y = (float)y * state.scaleY;
} }
x -= state.shm->mouseX; x -= state.shm->cursor.x;
y -= state.shm->mouseY; y -= state.shm->cursor.y;
realignGuest = false; realignGuest = false;
if (!spice_mouse_motion(x, y)) if (!spice_mouse_motion(x, y))
@ -605,6 +612,9 @@ int run()
FcPatternDestroy(pat); FcPatternDestroy(pat);
} }
if (!params.vsync)
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
state.window = SDL_CreateWindow( state.window = SDL_CreateWindow(
"Looking Glass (Client)", "Looking Glass (Client)",
params.center ? SDL_WINDOWPOS_CENTERED : params.x, params.center ? SDL_WINDOWPOS_CENTERED : params.x,