[KMS] Initial implementation

This commit is contained in:
thefiddler 2014-06-23 22:22:04 +02:00
parent c1c6b4269b
commit c3451530a6
6 changed files with 499 additions and 0 deletions

View file

@ -806,6 +806,11 @@
<Compile Include="Platform\X11\XI2Input.cs" />
<Compile Include="Platform\X11\XI2MouseKeyboard.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSFloat.cs" />
<Compile Include="Platform\Linux\Bindings\Drm.cs" />
<Compile Include="Platform\Linux\LinuxFactory.cs" />
<Compile Include="Platform\Linux\LinuxNativeWindow.cs" />
<Compile Include="Platform\Linux\Bindings\Linux.cs" />
<Compile Include="Platform\Linux\Bindings\Gbm.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@ -836,4 +841,8 @@
</MonoDevelop>
</ProjectExtensions>
<ItemGroup />
<ItemGroup>
<Folder Include="Platform\Linux\" />
<Folder Include="Platform\Linux\Bindings\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,57 @@
#region License
//
// Drm.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.Linux
{
class Drm
{
const string lib = "libdrm";
[DllImport(lib, EntryPoint = "drmModeGetResources", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ModeGetResources(int fd);
}
struct ModeRes
{
public int count_fbs;
public IntPtr fbs; //uint*
public int count_crtcs;
public IntPtr crtcs; //uint*
public int count_connectors;
public IntPtr connectors; //uint*
public int count_encoders;
public IntPtr encoders; //uint*
public int min_width, max_width;
public int min_height, max_height;
}
}

View file

@ -0,0 +1,52 @@
#region License
//
// Gbm.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.Linux
{
class Gbm
{
const string lib = "gbm";
[DllImport(lib, EntryPoint = "gbm_create_device", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreateDevice(int fd);
}
struct GbmDevice
{
public int id;
public int fd;
public IntPtr name;
public int refcount;
public Stat stat;
}
}

View file

@ -0,0 +1,68 @@
#region License
//
// Linux.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.Linux
{
class Linux
{
[DllImport("glib", EntryPoint = "open", CallingConvention = CallingConvention.Cdecl)]
public static extern int Open(string pathname, OpenFlags flags);
}
[Flags]
enum OpenFlags
{
ReadOnly = 0,
WriteOnly = 1,
ReadWrite = 2,
CloseOnExec = 4096
}
[StructLayout(LayoutKind.Sequential)]
struct Stat
{
public IntPtr dev; /* ID of device containing file */
public IntPtr ino; /* inode number */
public IntPtr mode; /* protection */
public IntPtr nlink; /* number of hard links */
public IntPtr uid; /* user ID of owner */
public IntPtr gid; /* group ID of owner */
public IntPtr rdev; /* device ID (if special file) */
public IntPtr size; /* total size, in bytes */
public IntPtr blksize; /* blocksize for file system I/O */
public IntPtr blocks; /* number of 512B blocks allocated */
public IntPtr atime; /* time of last access */
public IntPtr mtime; /* time of last modification */
public IntPtr ctime; /* time of last status change */
}
}

View file

@ -0,0 +1,117 @@
#region License
//
// LinuxFactory.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK.Graphics;
using OpenTK.Input;
namespace OpenTK.Platform.Linux
{
// Linux KMS platform
class LinuxFactory : PlatformFactoryBase
{
int fd;
GbmDevice device;
IntPtr display;
public LinuxFactory()
{
// Todo: support multi-GPU systems
string gpu = "/dev/dri/card0";
fd = Linux.Open(gpu, OpenFlags.ReadOnly | OpenFlags.CloseOnExec);
if (fd < 0)
{
throw new NotSupportedException("No KMS-capable GPU available");
}
Debug.Print("GPU {0} opened as fd:{1}", gpu, fd);
IntPtr dev = Gbm.CreateDevice(fd);
if (dev == IntPtr.Zero)
{
throw new NotSupportedException("Failed to create GBM device");
}
device = (GbmDevice)Marshal.PtrToStructure(dev, typeof(GbmDevice));
Debug.Print("GBM {0:x} '{1}' created successfully",
dev, Marshal.PtrToStringAnsi(device.name));
display = Egl.Egl.GetDisplay(dev);
if (display == IntPtr.Zero)
{
throw new NotSupportedException("Failed to create EGL display");
}
Debug.Print("EGL display {0:x} created successfully", display);
int major, minor;
if (!Egl.Egl.Initialize(display, out major, out minor))
{
int error = Egl.Egl.GetError();
throw new NotSupportedException("Failed to initialize EGL display. Error code: " + error);
}
Debug.Print("EGL {0}.{1} initialized successfully on display {2:x}", major, minor, display);
}
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
{
return new LinuxNativeWindow(x, y, width, height, title, mode, options, device);
}
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
{
throw new NotImplementedException();
}
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
{
throw new NotImplementedException();
}
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
{
throw new NotImplementedException();
}
public override IKeyboardDriver2 CreateKeyboardDriver()
{
throw new NotImplementedException();
}
public override IMouseDriver2 CreateMouseDriver()
{
throw new NotImplementedException();
}
public override IJoystickDriver2 CreateJoystickDriver()
{
throw new NotImplementedException();
}
}
}

View file

@ -0,0 +1,196 @@
#region License
//
// LinuxNativeWindow.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
namespace OpenTK.Platform.Linux
{
class LinuxNativeWindow : NativeWindowBase
{
#region INativeWindow Members
public override void Close()
{
throw new NotImplementedException();
}
public override System.Drawing.Point PointToClient(System.Drawing.Point point)
{
throw new NotImplementedException();
}
public override System.Drawing.Point PointToScreen(System.Drawing.Point point)
{
throw new NotImplementedException();
}
protected override void Dispose(bool disposing)
{
throw new NotImplementedException();
}
public override System.Drawing.Icon Icon
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override string Title
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override bool Focused
{
get
{
throw new NotImplementedException();
}
}
public override bool Visible
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override bool Exists
{
get
{
throw new NotImplementedException();
}
}
public override IWindowInfo WindowInfo
{
get
{
throw new NotImplementedException();
}
}
public override WindowState WindowState
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override WindowBorder WindowBorder
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override System.Drawing.Rectangle Bounds
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override System.Drawing.Size ClientSize
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override bool CursorVisible
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override MouseCursor Cursor
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endregion
}
}