Merge pull request #541 from varon/malcomstill-pr-471v2

Updated Linux/KMS platform to work with recent versions of libinput / Fix for Linux/KMS rendering glitches
This commit is contained in:
Jarl Gullberg 2017-06-18 17:16:03 +02:00 committed by GitHub
commit b207829e80
4 changed files with 46 additions and 66 deletions

View file

@ -45,9 +45,12 @@ namespace OpenTK.Platform.Linux
{
internal const string lib = "libinput";
[DllImport(lib, EntryPoint = "libinput_udev_create_for_seat", CallingConvention = CallingConvention.Cdecl)]
[DllImport(lib, EntryPoint = "libinput_udev_create_context", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreateContext(InputInterface @interface,
IntPtr user_data, IntPtr udev, string seat_id);
IntPtr user_data, IntPtr udev);
[DllImport(lib, EntryPoint = "libinput_udev_assign_seat", CallingConvention = CallingConvention.Cdecl)]
public static extern int AssignSeat(IntPtr libinput, string seat_id);
[DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyContext(IntPtr libinput);
@ -192,31 +195,6 @@ namespace OpenTK.Platform.Linux
HorizontalScroll = 1
}
struct Fixed24
{
internal readonly int Value;
public static implicit operator double(Fixed24 n)
{
long l = ((1023L + 44L) << 52) + (1L << 51) + n.Value;
unsafe
{
double d = *(double*)&l;
return d - (3L << 43);
}
}
public static implicit operator float(Fixed24 n)
{
return (float)(double)n;
}
public static explicit operator int(Fixed24 n)
{
return n.Value >> 8;
}
}
[StructLayout(LayoutKind.Sequential)]
class InputInterface
{
@ -275,14 +253,14 @@ namespace OpenTK.Platform.Linux
public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } }
public uint ButtonCount { get { return GetButtonCount(@event); } }
public ButtonState ButtonState { get { return GetButtonState(@event); } }
public PointerAxis Axis { get { return GetAxis(@event); } }
public Fixed24 AxisValue { get { return GetAxisValue(@event); } }
public Fixed24 DeltaX { get { return GetDX(@event); } }
public Fixed24 DeltaY { get { return GetDY(@event); } }
public Fixed24 X { get { return GetAbsX(@event); } }
public Fixed24 Y { get { return GetAbsY(@event); } }
public Fixed24 TransformedX(int width) { return GetAbsXTransformed(@event, width); }
public Fixed24 TransformedY(int height) { return GetAbsYTransformed(@event, height); }
public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; }
public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); }
public double DeltaX { get { return GetDX(@event); } }
public double DeltaY { get { return GetDY(@event); } }
public double X { get { return GetAbsX(@event); } }
public double Y { get { return GetAbsY(@event); } }
public double TransformedX(int width) { return GetAbsXTransformed(@event, width); }
public double TransformedY(int height) { return GetAbsYTransformed(@event, height); }
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_time", CallingConvention = CallingConvention.Cdecl)]
static extern uint GetTime(IntPtr @event);
@ -302,29 +280,29 @@ namespace OpenTK.Platform.Linux
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button_state", CallingConvention = CallingConvention.Cdecl)]
static extern ButtonState GetButtonState(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis", CallingConvention = CallingConvention.Cdecl)]
static extern PointerAxis GetAxis(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_has_axis", CallingConvention = CallingConvention.Cdecl)]
static extern int HasAxis(IntPtr @event, PointerAxis axis);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis_value", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAxisValue(IntPtr @event);
static extern double GetAxisValue(IntPtr @event, PointerAxis axis);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetDX(IntPtr @event);
static extern double GetDX(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dy", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetDY(IntPtr @event);
static extern double GetDY(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsX(IntPtr @event);
static extern double GetAbsX(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsY(IntPtr @event);
static extern double GetAbsY(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x_transformed", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsXTransformed(IntPtr @event, int width);
static extern double GetAbsXTransformed(IntPtr @event, int width);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y_transformed", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsYTransformed(IntPtr @event, int height);
static extern double GetAbsYTransformed(IntPtr @event, int height);
}
}

View file

@ -67,9 +67,6 @@ namespace OpenTK.Platform.Linux
{
base.SwapBuffers();
bo_next = LockSurface();
int fb = GetFramebuffer(bo_next);
if (is_flip_queued)
{
// Todo: if we don't wait for the page flip,
@ -84,6 +81,8 @@ namespace OpenTK.Platform.Linux
}
}
bo_next = LockSurface();
int fb = GetFramebuffer(bo_next);
QueueFlip(fb);
}

View file

@ -314,7 +314,7 @@ namespace OpenTK.Platform.Linux
}
Debug.Print("[Input] Udev.New() = {0:x}", udev);
input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev, "seat0");
input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev);
if (input_context == IntPtr.Zero)
{
Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev);
@ -323,6 +323,16 @@ namespace OpenTK.Platform.Linux
}
Debug.Print("[Input] LibInput.CreateContext({0:x}) = {1:x}", udev, input_context);
string seat_id = "seat0";
int seat_assignment = LibInput.AssignSeat(input_context, seat_id);
if (seat_assignment == -1)
{
Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1} failed.", input_context, seat_id);
Interlocked.Increment(ref exit);
return;
}
Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1}", input_context, seat_id);
fd = LibInput.GetFD(input_context);
if (fd < 0)
{
@ -475,21 +485,13 @@ namespace OpenTK.Platform.Linux
{
mouse.State.SetIsConnected(true);
double value = e.AxisValue;
PointerAxis axis = e.Axis;
switch (axis)
if (e.HasAxis(PointerAxis.HorizontalScroll))
{
case PointerAxis.HorizontalScroll:
mouse.State.SetScrollRelative((float)value, 0);
break;
case PointerAxis.VerticalScroll:
mouse.State.SetScrollRelative(0, (float)value);
break;
default:
Debug.Print("[Input] Unknown scroll axis {0}.", axis);
break;
mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0);
}
if (e.HasAxis(PointerAxis.VerticalScroll))
{
mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll));
}
}
}
@ -508,7 +510,7 @@ namespace OpenTK.Platform.Linux
void HandlePointerMotion(MouseDevice mouse, PointerEvent e)
{
Vector2 delta = new Vector2((float)e.X, (float)e.Y);
Vector2 delta = new Vector2((float)e.DeltaX, (float)e.DeltaY);
if (mouse != null)
{
mouse.State.SetIsConnected(true);
@ -526,12 +528,12 @@ namespace OpenTK.Platform.Linux
if (mouse != null)
{
mouse.State.SetIsConnected(true);
mouse.State.Position = new Vector2(e.X, e.Y);
mouse.State.Position = new Vector2((float)e.X, (float)e.Y);
}
CursorPosition = new Vector2(
e.TransformedX(bounds.Width),
e.TransformedY(bounds.Height));
(float)e.TransformedX(bounds.Width),
(float)e.TransformedY(bounds.Height));
UpdateCursor();
}

View file

@ -366,6 +366,7 @@ namespace OpenTK.Platform.Linux
if (disposing)
{
Debug.Print("[KMS] Destroying window {0}.", window.Handle);
Drm.SetCursor(window.FD, window.DisplayDevice.Id, 0, 0, 0, 0, 0);
window.Dispose();
Gbm.DestroySurface(window.Handle);
}