[client/common] restructure project in prep for full SDL removal

This commit is contained in:
Geoffrey McRae
2021-01-25 19:58:36 +11:00
parent 6f1c19b3b0
commit bf583290a4
42 changed files with 1668 additions and 1822 deletions

View File

@@ -1,6 +1,6 @@
/*
Looking Glass - KVM FrameRelay (KVMFR)
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -16,9 +16,17 @@ 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
*/
#ifndef _H_LG_COMMON_KVMFR_
#define _H_LG_COMMON_KVMFR_
#pragma once
#include <stdint.h>
#include "types.h"
#define KVMFR_MAGIC "KVMFR---"
#define KVMFR_VERSION 8
#define LGMP_Q_POINTER 1
#define LGMP_Q_FRAME 2
@@ -26,47 +34,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#define LGMP_Q_FRAME_LEN 2
#define LGMP_Q_POINTER_LEN 20
typedef enum FrameType
{
FRAME_TYPE_INVALID ,
FRAME_TYPE_BGRA , // BGRA interleaved: B,G,R,A 32bpp
FRAME_TYPE_RGBA , // RGBA interleaved: R,G,B,A 32bpp
FRAME_TYPE_RGBA10 , // RGBA interleaved: R,G,B,A 10,10,10,2 bpp
FRAME_TYPE_RGBA16F , // RGBA interleaved: R,G,B,A 16,16,16,16 bpp float
FRAME_TYPE_MAX , // sentinel value
}
FrameType;
typedef enum FrameRotation
{
FRAME_ROT_0,
FRAME_ROT_90,
FRAME_ROT_180,
FRAME_ROT_270
}
FrameRotation;
extern const char * FrameTypeStr[FRAME_TYPE_MAX];
enum
{
CURSOR_FLAG_POSITION = 0x1,
CURSOR_FLAG_VISIBLE = 0x2,
CURSOR_FLAG_SHAPE = 0x4
};
typedef uint32_t KVMFRCursorFlags;
typedef enum CursorType
{
CURSOR_TYPE_COLOR ,
CURSOR_TYPE_MONOCHROME ,
CURSOR_TYPE_MASKED_COLOR
}
CursorType;
#define KVMFR_MAGIC "KVMFR---"
#define KVMFR_VERSION 8
typedef struct KVMFR
{
char magic[8];
@@ -99,3 +75,5 @@ typedef struct KVMFRFrame
uint32_t mouseScalePercent; // movement scale factor of the mouse (relates to DPI of display, 100 = no scale)
}
KVMFRFrame;
#endif

View File

@@ -1,6 +1,6 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,7 +17,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_COMMON_CRASH_
#define _H_LG_COMMON_CRASH_
#include <stdbool.h>
bool installCrashHandler(const char * exe);
void cleanupCrashHandler(void);
#endif

View File

@@ -17,6 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_COMMON_DEBUG_
#define _H_LG_COMMON_DEBUG_
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
@@ -82,3 +85,5 @@ void printBacktrace(void);
#else
#define DEBUG_PROTO(fmt, ...) do {} while(0)
#endif
#endif

View File

@@ -17,9 +17,14 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_COMMON_DPI_
#define _H_LG_COMMON_DPI_
#include <windows.h>
// At 100% scaling, Windows reports 96 DPI.
#define DPI_100_PERCENT 96
UINT monitor_dpi(HMONITOR hMonitor);
#endif

View File

@@ -1,6 +1,6 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2020 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#ifndef _H_LG_COMMON_EVENT_
#define _H_LG_COMMON_EVENT_
#include <stdbool.h>
#include <time.h>
@@ -40,3 +41,5 @@ LGEvent * lgWrapEvent(void * handle);
// Posix specific, not implmented/possible in windows
bool lgWaitEventAbs(LGEvent * handle, struct timespec * ts);
bool lgWaitEventNS (LGEvent * handle, unsigned int timeout);
#endif

View File

@@ -1,6 +1,6 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#ifndef _H_LG_COMMON_FRAMEBUFFER_
#define _H_LG_COMMON_FRAMEBUFFER_
#include <stdlib.h>
#include <stdbool.h>
@@ -58,3 +59,5 @@ void framebuffer_prepare(FrameBuffer * frame);
* Write data from the src buffer into the KVMFRFrame
*/
bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size);
#endif

View File

@@ -1,6 +1,6 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2020 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#ifndef _H_LG_COMMON_IVSHMEM_
#define _H_LG_COMMON_IVSHMEM_
#include <stdbool.h>
#include <stdint.h>
@@ -41,3 +42,5 @@ void ivshmemFree(struct IVSHMEM * dev);
/* Linux KVMFR support only for now (VM->VM) */
bool ivshmemHasDMA (struct IVSHMEM * dev);
int ivshmemGetDMABuf(struct IVSHMEM * dev, uint64_t offset, uint64_t size);
#endif

View File

@@ -1,6 +1,6 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -16,7 +16,9 @@ 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
*/
#pragma once
#ifndef _H_LG_COMMON_LOCKING_
#define _H_LG_COMMON_LOCKING_
#include "time.h"
@@ -38,3 +40,5 @@ typedef atomic_flag LG_Lock;
LG_LOCK(lock) \
x \
LG_UNLOCK(lock)
#endif

View File

@@ -1,135 +0,0 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
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
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <tmmintrin.h>
#include <immintrin.h>
#include "debug.h"
#if defined(NATIVE_MEMCPY)
#define memcpySSE memcpy
#elif defined(_MSC_VER)
extern "C" void * memcpySSE(void *dst, const void * src, size_t length);
#elif (defined(__GNUC__) || defined(__GNUG__)) && defined(__i386__)
inline static void * memcpySSE(void *dst, const void * src, size_t length)
{
if (length == 0 || dst == src)
return;
// copies under 1MB are faster with the inlined memcpy
// tell the dev to use that instead
if (length < 1048576)
{
static bool smallBufferWarn = false;
if (!smallBufferWarn)
{
DEBUG_WARN("Do not use memcpySSE for copies under 1MB in size!");
smallBufferWarn = true;
}
memcpy(dst, src, length);
return;
}
const void * end = dst + (length & ~0x7F);
const size_t off = (7 - ((length & 0x7F) >> 4)) * 9;
__asm__ __volatile__ (
"cmp %[dst],%[end] \n\t"
"je Remain_%= \n\t"
// perform SIMD block copy
"loop_%=: \n\t"
"movaps 0x00(%[src]),%%xmm0 \n\t"
"movaps 0x10(%[src]),%%xmm1 \n\t"
"movaps 0x20(%[src]),%%xmm2 \n\t"
"movaps 0x30(%[src]),%%xmm3 \n\t"
"movaps 0x40(%[src]),%%xmm4 \n\t"
"movaps 0x50(%[src]),%%xmm5 \n\t"
"movaps 0x60(%[src]),%%xmm6 \n\t"
"movaps 0x70(%[src]),%%xmm7 \n\t"
"movntdq %%xmm0 ,0x00(%[dst]) \n\t"
"movntdq %%xmm1 ,0x10(%[dst]) \n\t"
"movntdq %%xmm2 ,0x20(%[dst]) \n\t"
"movntdq %%xmm3 ,0x30(%[dst]) \n\t"
"movntdq %%xmm4 ,0x40(%[dst]) \n\t"
"movntdq %%xmm5 ,0x50(%[dst]) \n\t"
"movntdq %%xmm6 ,0x60(%[dst]) \n\t"
"movntdq %%xmm7 ,0x70(%[dst]) \n\t"
"add $0x80,%[dst] \n\t"
"add $0x80,%[src] \n\t"
"cmp %[dst],%[end] \n\t"
"jne loop_%= \n\t"
"Remain_%=: \n\t"
// copy any remaining 16 byte blocks
"call GetPC_%=\n\t"
"Offset_%=:\n\t"
"add $(BlockTable_%= - Offset_%=), %%eax \n\t"
"add %[off],%%eax \n\t"
"jmp *%%eax \n\t"
"GetPC_%=:\n\t"
"mov (%%esp), %%eax \n\t"
"ret \n\t"
"BlockTable_%=:\n\t"
"movaps 0x60(%[src]),%%xmm6 \n\t"
"movntdq %%xmm6 ,0x60(%[dst]) \n\t"
"movaps 0x50(%[src]),%%xmm5 \n\t"
"movntdq %%xmm5 ,0x50(%[dst]) \n\t"
"movaps 0x40(%[src]),%%xmm4 \n\t"
"movntdq %%xmm4 ,0x40(%[dst]) \n\t"
"movaps 0x30(%[src]),%%xmm3 \n\t"
"movntdq %%xmm3 ,0x30(%[dst]) \n\t"
"movaps 0x20(%[src]),%%xmm2 \n\t"
"movntdq %%xmm2 ,0x20(%[dst]) \n\t"
"movaps 0x10(%[src]),%%xmm1 \n\t"
"movntdq %%xmm1 ,0x10(%[dst]) \n\t"
"movaps 0x00(%[src]),%%xmm0 \n\t"
"movntdq %%xmm0 ,0x00(%[dst]) \n\t"
"nop\n\t"
"nop\n\t"
: [dst]"+r" (dst),
[src]"+r" (src)
: [off]"r" (off),
[end]"r" (end)
: "eax",
"xmm0",
"xmm1",
"xmm2",
"xmm3",
"xmm4",
"xmm5",
"xmm6",
"xmm7",
"memory"
);
//copy any remaining bytes
memcpy(dst, src, length & 0xF);
}
#else
#define memcpySSE memcpy
#endif

View File

@@ -17,6 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_COMMON_OPTION_
#define _H_COMMON_OPTION_
#include <stdbool.h>
#include "common/stringlist.h"
@@ -53,7 +56,7 @@ struct Option
char * (*toString )(struct Option * opt);
StringList (*getValues)(struct Option * opt);
void (*printHelp)();
void (*printHelp)(void);
// internal use only
bool failed_set;
@@ -75,10 +78,12 @@ bool option_parse(int argc, char * argv[]);
bool option_load(const char * filename);
// called by the main application to validate the option values
bool option_validate();
bool option_validate(void);
// print out the options, help, and their current values
void option_print();
void option_print(void);
// final cleanup
void option_free();
void option_free(void);
#endif

View File

@@ -17,6 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_COMMON_STRINGLIST_
#define _H_LG_COMMON_STRINGLIST_
#include <stdbool.h>
typedef struct StringList * StringList;
@@ -25,4 +28,6 @@ StringList stringlist_new (bool owns_strings);
void stringlist_free (StringList * sl);
int stringlist_push (StringList sl, char * str);
unsigned int stringlist_count(StringList sl);
char * stringlist_at (StringList sl, unsigned int index);
char * stringlist_at (StringList sl, unsigned int index);
#endif

View File

@@ -1,6 +1,6 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,6 +17,11 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_COMMON_STRINGUTILS
#define _H_LG_COMMON_STRINGUTILS
// sprintf but with buffer allocation
int alloc_sprintf(char ** str, const char * format, ...)
__attribute__ ((format (printf, 2, 3)));
__attribute__ ((format (printf, 2, 3)));
#endif

View File

@@ -1,6 +1,6 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,5 +17,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_COMMON_SYSUTILS
#define _H_LG_COMMON_SYSUTILS
// returns the page size
long sysinfo_getPageSize();
#endif

View File

@@ -1,6 +1,6 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2020 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,12 +17,16 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#ifndef _H_LG_COMMON_THREAD_
#define _H_LG_COMMON_THREAD_
#include <stdbool.h>
typedef struct LGThread LGThread;
typedef int (*LGThreadFunction)(void * opaque);
bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, LGThread ** handle);
bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque,
LGThread ** handle);
bool lgJoinThread (LGThread * handle, int * resultCode);
#endif

View File

@@ -0,0 +1,58 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
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
*/
#ifndef _LG_TYPES_H_
#define _LG_TYPES_H_
struct DoublePoint
{
double x, y;
};
typedef enum FrameType
{
FRAME_TYPE_INVALID ,
FRAME_TYPE_BGRA , // BGRA interleaved: B,G,R,A 32bpp
FRAME_TYPE_RGBA , // RGBA interleaved: R,G,B,A 32bpp
FRAME_TYPE_RGBA10 , // RGBA interleaved: R,G,B,A 10,10,10,2 bpp
FRAME_TYPE_RGBA16F , // RGBA interleaved: R,G,B,A 16,16,16,16 bpp float
FRAME_TYPE_MAX , // sentinel value
}
FrameType;
typedef enum FrameRotation
{
FRAME_ROT_0,
FRAME_ROT_90,
FRAME_ROT_180,
FRAME_ROT_270
}
FrameRotation;
extern const char * FrameTypeStr[FRAME_TYPE_MAX];
typedef enum CursorType
{
CURSOR_TYPE_COLOR ,
CURSOR_TYPE_MONOCHROME ,
CURSOR_TYPE_MASKED_COLOR
}
CursorType;
#endif

View File

@@ -1 +1,25 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
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
*/
#ifndef _H_LG_COMMON_VERSION_
#define _H_LG_COMMON_VERSION_
extern char * BUILD_VERSION;
#endif

View File

@@ -1,6 +1,6 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2020 Geoffrey McRae <geoff@hostfission.com>
Copyright (C) 2017-2021 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
@@ -17,7 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#ifndef _H_LG_COMMON_WINDEBUG_
#define _H_LG_COMMON_WINDEBUG_
#include "debug.h"
#include <windows.h>
@@ -35,4 +36,6 @@ bool IsWindows8();
#ifdef __cplusplus
}
#endif
#endif
#endif