Commit Graph

297 Commits

Author SHA1 Message Date
Quantum
be1306f91a [common] debug: add DEBUG_ASSERT macro
This, unlike the standard assert macro, is guaranteed to print the failed
assertion to our log file, and tests the assertion even with NDEBUG defined
so we can more easily catch failures in production binaries without crashing
the program.

The motivation of this is how MinGW handles assertion failures: it creates a
dialog window that the headless user will not be able to see, and blocks the
program from being restarted by the service. Since the failed assertion is
displayed in the dialog, it doesn't print anything to the log, making it
impossible to diagnose issues.
2021-08-14 12:19:07 +10:00
Quantum
e5d252290d [common] array: add ALIGN_PAD macro for common logic
ALIGN_PAD(x, a) returns x rounded up to the nearest multiple of a.
2021-08-14 08:05:29 +10:00
Quantum
717b90366b [common] ivshmem: use correct page alignment logic
Before, if the size is exactly the multiple of the page size, an extra padding
page is added for no reason. This commit fixes the logic and also uses the
page size obtained dynamically.
2021-08-13 20:24:15 +10:00
Quantum
e945955d13 [common] rects: add rectsRejectContained function
This function will remove rectangles in a list that are entirely contained
in another rectangle in the same list.
2021-08-13 20:21:27 +10:00
Quantum
604b44d6d8 [common] rects: add rectsMergeOverlapping helper function
This is based on the client's util_mergeOverlappingRects.
2021-08-11 19:01:52 +10:00
Quantum
9f4afcd944 [common] crash: use DEBUG_WINERROR on windows 2021-08-11 02:41:33 +10:00
Geoffrey McRae
e41cbf5f32 [common] option: option_get_float should return a float 2021-08-10 01:36:12 +10:00
Geoffrey McRae
88eada3494 [common] option: add support for float option types 2021-08-10 01:09:40 +10:00
Geoffrey McRae
92de467edc [client] egl: add ffx_cas post process filter 2021-08-09 23:12:58 +10:00
Quantum
87a21f5f5e [host] windows: use DEBUG_WINERROR for CallNtPowerInformation
We need to use the function RtlNtStatusToDosError to convert NTSTATUS to
Windows error codes.
2021-08-09 17:07:25 +10:00
Geoffrey McRae
30ad28ffd1 [common] CountedBuffer: cosmetics 2021-08-09 14:07:39 +10:00
Geoffrey McRae
69f6532b8d [common] ringbuffer: allow reverse iteration 2021-08-09 14:06:32 +10:00
Quantum
0462cee9db [common] rects: implement routine to copy rectangles from framebuffer 2021-08-08 08:30:11 +10:00
Quantum
cab95c5eed [common] rects: refactor rect buffer copy code to common module
This also fixes a bug of accidentally multiplying the stride by 4 when
the stride is already in bytes and not pixels.
2021-08-08 08:30:11 +10:00
Quantum
4205e49786 [common] appstrings: add blurb for quantum 2021-08-07 08:54:56 +10:00
Quantum
2f8ebc29e8 [common] open: implement opening URLs in browser
This is currently only implemented for Linux.

On Windows, ShellExecute should be used, but that should be done when it's
actually needed so it could be tested.
2021-08-05 22:43:46 +10:00
Geoffrey McRae
95bbd67dea [common] add new KVMFR structs and fields for feature support 2021-08-05 22:19:11 +10:00
Quantum
51b9cd4e5a [all] copyright: use unicode copyright sign ©
This is done for consistency with the license strings in appstrings.c.
2021-08-04 21:16:35 +10:00
Geoffrey McRae
1885e2093b [client] imgui: added missed files from the last commit 2021-08-04 10:29:48 +10:00
Geoffrey McRae
d2c36b8449 [client] overlay: add new configuration overlay [wip] 2021-08-04 10:27:47 +10:00
Geoffrey McRae
4b4a75475a [client] egl: fix out by one error with letterbox rendering
This replaces the scaled `destRect` with a version that uses doubles
correcting the rounding error that is causing a failure to properly
clear the black bar areas.
2021-08-03 22:27:46 +10:00
Geoffrey McRae
90b90e667a [common] event: lgResetEvent should return the last state of the event 2021-08-01 17:14:58 +10:00
Geoffrey McRae
a094fb8104 [common] events/linux: fix failure to call pthread_cond_broadcast 2021-08-01 17:13:31 +10:00
Quantum
3369536cb8 [common] paths: add library to manage platform-specific paths
This abstracts away stuff like XDG base directory specification.
Currently, this is implemented for Linux only.
2021-07-31 21:11:09 +10:00
Quantum
1104bd821b [common] option: make options case insensitive
It is not obvious that [DXGI] and [dxgi] are different sections in the ini file,
and only the latter works. We should just eliminate the difference.
2021-07-31 15:00:49 +10:00
Quantum
aff3bff8b0 [common] framebuffer: fix copy when source and dest pitch differs
We used to increment the source buffer index by width * bpp, not by pitch.
This is incorrect and the root cause behind #670.

This is a regression that appeared in 196050bd23.
2021-07-29 10:18:35 +10:00
Quantum
2ea84cd07e [common] ivshmem: use consistent device numbering on Windows
We now enumerate all IVSHMEM devices, sort them based on PCI bus, slot,
and function numbers, then index from the resulting order. This should
be consistent across boots.

To help the user identify the correct IVSHMEM device, we also print the
list of IVSHMEM devices on startup.
2021-07-29 10:17:33 +10:00
Quantum
996b9e7e7b [common] time: fully implement all functionality for windows
We implement nanotime by converting QueryPerformanceTimer output with
floating point arithmetic. This is necessary to preserve precision on
platforms where each tick is not an integer number of nanoseconds.

Furthermore, struct timespec is included C11 and appears to be supported
on Windows, so we no longer need to #ifdef it out.
2021-07-29 10:16:52 +10:00
Geoffrey McRae
5f5f497cbd [host/common] windows: provide delayExecution via nsleep
This change moves this platform specific sleep to `common` as the OS
agnostic `nsleep` function.

Ref PR #661
2021-07-26 16:36:56 +10:00
Geoffrey McRae
b39f38350f [common] kvmfr: add a new frameSerial field to the KVMFRFrame struct
This new field is used so that when a new client connects an already
connected client can identify any repeated frame that is sent and ignore
it.
2021-07-25 13:46:48 +10:00
Quantum
3cf0257f34 [host] windows: do not complain about failed timer destruction at exit
When our window is destroyed, our timers are also destroyed. This causes our
attempt at destruction to fail. Instead, set MessageHWND to NULL in the
WM_DESTROY handler and don't try destroying the timers if the window is gone.
2021-07-23 15:52:45 +10:00
Quantum
26f16a3734 [common] windows: declare WINVER and _WIN32_WINNT
This is done for consistency with the Windows-specific portions of the host.
2021-07-20 12:45:29 +10:00
Quantum
2bb0602ebb [common] windebug: remove custom-rolled Windows 8 detector
Just use <versionhelpers.h> from Windows SDK.
2021-07-20 11:34:57 +10:00
Geoffrey McRae
2038517861 [common] linux: review and fix event logic, events should not be counted 2021-07-19 13:19:59 +10:00
Geoffrey McRae
2736e37e4a [common] timer: fix timespec parameters when interval >= 1000 2021-07-19 10:58:10 +10:00
Geoffrey McRae
45e1b5bce0 [common] ringbuffer: add pre value overwrite callback
This allows us to set a callback to read a value out before it's about
to be overwritten which can be useful for things like calculating a
running average.
2021-07-18 20:42:29 +10:00
Quantum
ad974cfa0a [common] dpi: remove no longer used library 2021-07-18 10:50:57 +10:00
Quantum
e1fae8927f [common] kvmfr: remove mouseScalingPercent which is no longer used
This used to contain DPI information, but is no longer used.
2021-07-18 10:50:57 +10:00
Tudor Brindus
92706caddc [common]: move array length into a common helper
Since it is more generally useful, and less cryptic this way.
2021-07-18 10:41:50 +10:00
Quantum
ef2da1902e [common] framebuffer: allow custom framebuffer write implementations
This is helpful for only copying damaged areas.
2021-07-18 10:41:50 +10:00
Quantum
69b20aee05 [common] kvmfr: add damage rectangles to the protocol
Co-Authored-By: Tudor Brindus <me@tbrindus.ca>
2021-07-18 10:41:50 +10:00
Geoffrey McRae
23f9855768 [common] ringbuffer: add forEach iterator 2021-07-17 21:09:51 +10:00
Geoffrey McRae
41403286d1 [common] ringbuffer: add getLength method 2021-07-17 21:09:51 +10:00
Geoffrey McRae
94ae9a95d7 [common] added new ringbuffer helper for metrics collection 2021-07-17 21:09:51 +10:00
Geoffrey McRae
041b95507d [host] windows/nvfbc/common: strip out broken "enhanced" event logic
This so called "enhanced" event logic is completely flawed and can never
work correctly, better to strip it out and put our faith in windows to
handle the events for us.

And yes, I am fully aware I wrote the utter trash in the first place :)
2021-07-09 10:22:03 +10:00
Geoffrey McRae
bfb47a0ae4 [common] windows: update event fast path to use atomics
Due to a failure to understand atomics when this code was originally
written it has a critical flaw with the fast path where an event could
be signalled when it should not be. This change set corrects this issue
by using atomic operations.
2021-07-09 04:50:14 +10:00
Geoffrey McRae
0acce0737f [common] debug: output to stdout and reset the the color at the end 2021-07-08 07:18:06 +10:00
Geoffrey McRae
54d0dc351b [common] debug: remove missed debug_print forward 2021-07-07 23:08:47 +10:00
Geoffrey McRae
1effd5fddc [common] debug: add color support to debug messages
People often miss the warnings about invalid arguments in their command
line, this last minute patch attempts to address this by making
warnings, errors, fixme's and fatal errors stand out if stdout is a TTY.
2021-07-07 23:05:46 +10:00
Quantum
d385b49f5f [common] runningavg: avoid integer overflows
We receive values as int64_t, but when we compute the sum, we store it as
int. This doesn't make sense as we eventually cast it to double when
computing the average. We should instead store the sum as int64_t.
2021-06-28 14:47:19 +10:00
Geoffrey McRae
d36c4f0e83 [host] kvmfr: allow the frame size to exceed the available memory
This change allows the host to still transmit a frame that is truncated
if the IVSHMEM size is too small to allow for a full frame.
2021-06-12 18:44:28 +10:00
Geoffrey McRae
d20e4d1de5 [common] framebuffer: make use of framebuffer_wait 2021-06-08 16:10:34 +10:00
Geoffrey McRae
e87d2f1a20 [common] framebuffer: add additional profiling support 2021-06-08 16:08:44 +10:00
Geoffrey McRae
4a75cc3bcf [common] framebuffer: simplify the remaining calculation
The pitches match so there is no need for the added complexity of this
calculation.
2021-06-08 15:14:54 +10:00
Geoffrey McRae
196050bd23 [common] framebuffer: improve client framebuffer read performance
Extensive profiling reveals that the glibc memcpy performs up to 2x
faster then the existing SIMD implementation that was in use here. This
patch also will copy large 1MB chunks if the pitch of the source and
destination match further increasing throughput.
2021-06-08 15:08:13 +10:00
Quantum
7300d00f66 [common] option: handle ini lines without trailing newline
Before, if the last line of an ini file has no trailing \n, it is ignored.
This commit changes the parser to process such lines.
2021-06-07 18:22:19 +10:00
Geoffrey McRae
21d86dd31d [common] option: prevent ascii filter from eating newlines 2021-06-07 11:29:17 +10:00
Geoffrey McRae
44bff58aa8 [common] option: ignore non-typeable ascii characters
Under windows text editors like to default to saving in UTF8 with a byte
order mask prefix preventing proper parsing of any option that is on the
first line of the file. Since the configuration file is only intended to
be plain ascii this change ignores all non-ascii characters solving this
issue.
2021-06-07 11:25:35 +10:00
Quantum
62c7fc2588 [common] runningavg: refresh copyright notice 2021-06-06 13:36:55 +10:00
Geoffrey McRae
f02d61d665 [host] dxgi: sleep until it's close to time to map
This change adds an average function to time how long it takes the GPU
to copy and map the texture, and then uses this average to sleep for 80%
of this average lowering CPU usage and potentially decreasing lock
contention.
2021-06-06 12:26:36 +10:00
Quantum
24d0aa0c18 [all] normalize copyright on all source files 2021-06-06 11:53:05 +10:00
Quantum
f9a9953071 [client] egl: use new util_hasGLExt helper to check extensions
We previously used strstr, which can be prone to false positives when
the name of one extension is a substring of another extension.

This commit creates the helper function util_hasGLExt, which asserts
that the substring found in extension list is bounded by either spaces
or the beginning/end of the string.
2021-05-19 15:58:54 +10:00
Jonathan Rubenstein
c6d7fb8dd0 [common] option: Reformat help and support rST tables
Corners of table have '+' added, and adds new command line flag --rst-help,
which adds some extra formatting to the make it an rST compliant table for the
in-line docs.
2021-05-06 22:32:36 +10:00
Quantum
fc7dd7dbb7 [common] cmake: correctly link static libbfd.a
When linking against libbfd.so, just passing libbfd.so to the compiler is
sufficient. When linking against the static version libbfd.a, however,
we must additionally link against libiberty.a and libz.a.

This commit adds a CMake helper to find the correct libraries that need
to be passed to link against libbfd correctly.
2021-03-03 16:37:34 +11:00
Quantum
b00c25a822 [common] crash: fix Linux compilation with -DENABLE_BACKTRACE=NO
Essentially, debug.h defines printTrace as an empty macro when the macro
ENABLE_BACKTRACE is not defined, breaking the compilation of crash.c.

Fixed by defining a private macro for debug.h only to avoid clashing.
2021-03-03 16:36:50 +11:00
Quantum
5ad70ccc41 [common] crash/linux: generate core dump when handling SIGSEGV
Calling abort() instead of exit() will generate a core dump, allowing gdb
to be used when the client crashes. This is desirable for the following
reasons:

1. gdb can be used to inspect the call stack with far more detail than the
   our quick stack trace code, and also allows the access to the heap.
2. Our SIGSEGV handler is unable to use debug symbols for shared libraries,
   making it impossible to debug bugs involving drivers and similar.
2021-02-27 13:34:03 +11:00
Geoffrey McRae
6358f35cb7 [common] detect clang and disable warnings for unknown-warning-option
Clang doesn't know the warning option `format-truncation`, which GCC
falsely triggers on when calling vsnprintf. Further to this, GCC doesn't
understand the warning group `unknown-warning-option`, as such we must
disable these warnings in the cmake.
2021-02-22 01:54:46 +11:00
Geoffrey McRae
99fc650550 [common] fix gcc format-truncation false positive 2021-02-22 01:39:28 +11:00
Quantum
5649d1ad95 [client] wayland: split Wayland display server into modules
The Wayland display server is getting unwieldy due to the sheer size.
To make it easier to edit in the future, I split it into many components
based on logical boundaries.
2021-02-21 10:31:49 +11:00
Quantum
db16efe68b [common] add a reference counted buffer type
This allows buffers to be shared between different asynchronous operations.
Once all users no longer need the buffer, it will be freed.

The motivation for this is being able to stream Wayland clipboard data
asynchronously to multiple clients. The buffer should only be freed after
the clipboard has changed and all ongoing transfer completes.
2021-02-21 10:31:49 +11:00
Quantum
e01666b6ad [client] wayland: implement epoll registration mechanism
This will be used to register async clipboard I/O callbacks later.
2021-02-21 10:31:49 +11:00
Quantum
62b27760ea [common] ivshmem: do not create dmabuf for simple mmap
It used to be the case that you need to create dmabuf for kvmfr devices
to be able to mmap them. But after #457, this is no longer needed.

Directly mmaping the kvmfr device has the advantage of avoiding the
creation of a dmabuf, which has cost (e.g. the list of pages, the
scatterlist, etc.).
2021-02-21 10:31:48 +11:00
Quantum
8e98f863b6 [host] windows: detect whether screensaver is disabled in the guest
This will allow us to add an option to disable the screensaver on the client
when an application in the guest requests it. This behaviour may be useful
when the guest is doing media playback.
2021-02-21 10:31:48 +11:00
Geoffrey McRae
ca5c3938e4 [client] all: move all SDL specific code into displayservers/sdl 2021-02-21 10:31:48 +11:00
Geoffrey McRae
dbb18a6ecb [client] x11/sdl: get the border dimensions from the backend 2021-02-21 10:31:48 +11:00
Geoffrey McRae
bf583290a4 [client/common] restructure project in prep for full SDL removal 2021-02-21 10:31:46 +11:00
Geoffrey McRae
6f1c19b3b0 [all] improve backtrace and debugging support 2021-02-21 10:30:57 +11:00
Quantum
7e15ec5e66 [common] windows: implement crash handler for stack traces
This commit uses the DbgHelp library which is shipped with Windows to
generate stack traces with function names and line number information.
It takes advantage of the pdb file generated by cv2pdb that is now
installed with looking-glass-host.exe.
2021-01-27 07:56:12 +11:00
Geoffrey McRae
4c1893fe20 [all] fix numerous memory leaks at application shutdown 2021-01-24 21:47:53 +11:00
Geoffrey McRae
428b498cca [common] fix invalid read from unaligned addresses (fixes #410) 2021-01-20 23:18:46 +11:00
Geoffrey McRae
14cc57071c [host] remove the remainder of the YUV420 support 2021-01-18 13:55:44 +11:00
Geoffrey McRae
f5587b6b6b [host] all: pass back the desktop rotation to the client 2021-01-18 13:53:29 +11:00
Geoffrey McRae
27a38294ea [client] major restructure of platform specific code 2021-01-16 20:41:13 +11:00
Quantum
afa277f8ee [common] ivshmem/linux: add stubs for ivshmemInit and ivshmemFree
These two functions were added in 9ff1859dc1
for Windows, but were never used on Linux.

Adding stubs will allow the host to compile on Linux.
These should be fixed later.
2021-01-15 08:49:30 +11:00
Tudor Brindus
a46a3a2668 [all] use explicit void parameter lists
This makes it a compile-time error to call a function that semantically
takes no parameters with a nonzero number of arguments.

Previously, such code would still compile, but risk blowing up the stack
if a compiler chose to use something other than caller-cleanup calling
conventions.
2021-01-14 17:29:37 +11:00
Geoffrey McRae
f85b6418b8 [common] linux: stop event signals accumulating after they are serviced 2021-01-08 01:18:02 +11:00
Quantum
7e4d323427 get display DPI info to scale mouse movement 2021-01-05 09:03:29 +11:00
Geoffrey McRae
0badf2a84c [all] move defines for LGMP_QUEUE_*_LEN into KVMFR.h 2020-10-30 18:48:41 +11:00
Geoffrey McRae
6799d518a5 [client] common: added spin timeout to framebuffer wait 2020-10-30 03:27:28 +11:00
Geoffrey McRae
4f9544d61d [client] egl: added DMA texture support for direct upload
Note: This only works with the KVMFR kernel module in a VM->VM
configuration. If this causes issues it can be disabled with the new
option `app:allowDMA`
2020-10-30 02:36:45 +11:00
Geoffrey McRae
5522e93fb9 [common] linux: added helpers for ivshmem DMA usage 2020-10-30 02:36:45 +11:00
Geoffrey McRae
0efe7dc63c [common] linux: added support for kvmfr dmabuf 2020-10-30 02:36:45 +11:00
Geoffrey McRae
a70858aea0 [client] reworked frame timing waits for better responsiveness 2020-10-26 18:09:45 +11:00
Geoffrey McRae
9ff1859dc1 [host] windows: check the ivshmem device exists in the service 2020-10-19 02:49:15 +11:00
Geoffrey McRae
58ba76a27f [client] seperate frame setup and data events 2020-10-12 19:43:29 +11:00
Geoffrey McRae
b2961c7939 [all] added new format version field to frame header 2020-10-12 18:52:37 +11:00
Geoffrey McRae
6650e58a4a [common] linux: print reason for failure to open the shm file/device 2020-10-12 17:48:31 +11:00
Geoffrey McRae
9c6bd888fd [host/client] added experimental RGBA16 float support (EGL only) 2020-10-11 19:22:31 +11:00
Geoffrey McRae
e6c88a4af3 [all] be smarter about getting the git version 2020-10-09 02:17:20 +11:00
Geoffrey McRae
7e362050f7 [all] update KVMFR to provide cursor hotspot information
This commit bumps the KVMFR protocol version as it adds additional
hotspot x & y fields to the KVMFRCursor struct. This corrects the issue
of invalid alignment of the local mouse when the shape has an offset
such as the 'I' beam.
2020-08-20 13:51:01 +10:00