hid: Rewrite shared memory management (#2257)

* hid: Rewrite shared memory management

This entirely rewrite our ancient (and original) HID shared memory
interface to be more usable and accurate.

HID update logics were updated to reflect those changes but should work
still the same way it previously did.

This need heavy testing just in case to avoid possible regressions.

* Silence warnings

* Address gdkchan's comments

* Address Ac_K's comments

* Address one missing nit
This commit is contained in:
Mary 2021-05-02 22:01:30 +02:00 committed by GitHub
parent 0e9823d7e6
commit 3443023a08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 1395 additions and 624 deletions

View file

@ -1,37 +1,35 @@
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;
namespace Ryujinx.HLE.HOS.Services.Hid
{
public class MouseDevice : BaseDevice
{
public MouseDevice(Switch device, bool active) : base(device, active) { }
public void Update(int mouseX, int mouseY, int buttons = 0, int scrollX = 0, int scrollY = 0)
public void Update(int mouseX, int mouseY, uint buttons = 0, int scrollX = 0, int scrollY = 0)
{
ref ShMemMouse mouse = ref _device.Hid.SharedMemory.Mouse;
ref RingLifo<MouseState> lifo = ref _device.Hid.SharedMemory.Mouse;
int currentIndex = UpdateEntriesHeader(ref mouse.Header, out int previousIndex);
if (!Active)
ref MouseState previousEntry = ref lifo.GetCurrentEntryRef();
MouseState newState = new MouseState()
{
return;
SamplingNumber = previousEntry.SamplingNumber + 1,
};
if (Active)
{
newState.Buttons = (MouseButton)buttons;
newState.X = mouseX;
newState.Y = mouseY;
newState.DeltaX = mouseX - previousEntry.DeltaX;
newState.DeltaY = mouseY - previousEntry.DeltaY;
newState.WheelDeltaX = scrollX;
newState.WheelDeltaY = scrollY;
}
ref MouseState currentEntry = ref mouse.Entries[currentIndex];
MouseState previousEntry = mouse.Entries[previousIndex];
currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
currentEntry.SampleTimestamp2 = previousEntry.SampleTimestamp2 + 1;
currentEntry.Buttons = (ulong)buttons;
currentEntry.Position = new MousePosition
{
X = mouseX,
Y = mouseY,
VelocityX = mouseX - previousEntry.Position.X,
VelocityY = mouseY - previousEntry.Position.Y,
ScrollVelocityX = scrollX,
ScrollVelocityY = scrollY
};
lifo.Write(ref newState);
}
}
}