2014-06-23 20:22:04 +00:00
|
|
|
|
#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;
|
|
|
|
|
|
2014-07-21 13:03:24 +00:00
|
|
|
|
#pragma warning disable 0649 // field is never assigned
|
|
|
|
|
|
2014-06-23 20:22:04 +00:00
|
|
|
|
namespace OpenTK.Platform.Linux
|
|
|
|
|
{
|
2014-06-26 13:40:00 +00:00
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
|
|
|
delegate void VBlankCallback(int fd,
|
|
|
|
|
int sequence,
|
|
|
|
|
int tv_sec,
|
|
|
|
|
int tv_usec,
|
|
|
|
|
IntPtr user_data);
|
|
|
|
|
|
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
|
|
|
delegate void PageFlipCallback(int fd,
|
|
|
|
|
int sequence,
|
|
|
|
|
int tv_sec,
|
|
|
|
|
int tv_usec,
|
|
|
|
|
IntPtr user_data);
|
|
|
|
|
|
2014-06-23 20:22:04 +00:00
|
|
|
|
class Drm
|
|
|
|
|
{
|
|
|
|
|
const string lib = "libdrm";
|
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
[DllImport(lib, EntryPoint = "drmHandleEvent", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int HandleEvent(int fd, ref EventContext evctx);
|
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeAddFB", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int ModeAddFB(int fd, int width, int height, byte depth,
|
|
|
|
|
byte bpp, int pitch, int bo_handle,
|
|
|
|
|
out int buf_id);
|
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeRmFB", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int ModeRmFB(int fd, int bufferId);
|
|
|
|
|
|
2014-06-26 19:46:04 +00:00
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeFreeCrtc", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void ModeFreeCrtc(IntPtr ptr);
|
|
|
|
|
|
2014-06-24 17:27:38 +00:00
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeGetCrtc", CallingConvention = CallingConvention.Cdecl)]
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public static extern IntPtr ModeGetCrtc(int fd, int crtcId);
|
2014-06-24 17:27:38 +00:00
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeFreeConnector", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void ModeFreeConnector(IntPtr ptr);
|
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeFreeEncoder", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void ModeFreeEncoder(IntPtr ptr);
|
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeGetConnector", CallingConvention = CallingConvention.Cdecl)]
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public static extern IntPtr ModeGetConnector(int fd, int connector_id);
|
2014-06-24 17:27:38 +00:00
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeGetEncoder", CallingConvention = CallingConvention.Cdecl)]
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public static extern IntPtr ModeGetEncoder(int fd, int encoder_id);
|
2014-06-24 17:27:38 +00:00
|
|
|
|
|
2014-06-23 20:22:04 +00:00
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeGetResources", CallingConvention = CallingConvention.Cdecl)]
|
2014-06-24 17:27:38 +00:00
|
|
|
|
public static extern IntPtr ModeGetResources(int fd);
|
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
[DllImport(lib, EntryPoint = "drmModePageFlip", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int ModePageFlip(int fd, int crtc_id, int fb_id,
|
|
|
|
|
PageFlipFlags flags, IntPtr user_data);
|
|
|
|
|
|
2014-06-24 17:27:38 +00:00
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeSetCrtc", CallingConvention = CallingConvention.Cdecl)]
|
2014-06-26 13:40:00 +00:00
|
|
|
|
unsafe public static extern int ModeSetCrtc(int fd, int crtcId, int bufferId,
|
|
|
|
|
int x, int y, int* connectors, int count, ModeInfo* mode);
|
2014-07-17 07:25:16 +00:00
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeSetCursor2", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int SetCursor(int fd, int crtcId, int bo_handle, int width, int height, int hot_x, int hot_y);
|
|
|
|
|
|
|
|
|
|
[DllImport(lib, EntryPoint = "drmModeMoveCursor", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int MoveCursor(int fd, int crtcId, int x, int y);
|
|
|
|
|
|
2014-06-24 17:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
enum ModeConnection
|
2014-06-24 17:27:38 +00:00
|
|
|
|
{
|
|
|
|
|
Connected = 1,
|
|
|
|
|
Disconnected = 2,
|
|
|
|
|
Unknown = 3
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
enum ModeSubPixel
|
2014-06-24 17:27:38 +00:00
|
|
|
|
{
|
|
|
|
|
Unknown = 1,
|
|
|
|
|
HorizontalRgb = 2,
|
|
|
|
|
HorizontalBgr = 3,
|
|
|
|
|
VerticalRgb = 4,
|
|
|
|
|
VerticalBgr = 5,
|
|
|
|
|
None = 6
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
enum PageFlipFlags
|
|
|
|
|
{
|
|
|
|
|
FlipEvent = 0x01,
|
|
|
|
|
FlipAsync = 0x02,
|
|
|
|
|
FlipFlags = FlipEvent | FlipAsync
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
struct EventContext
|
|
|
|
|
{
|
|
|
|
|
public int version;
|
|
|
|
|
public IntPtr vblank_handler;
|
|
|
|
|
public IntPtr page_flip_handler;
|
|
|
|
|
|
|
|
|
|
public static readonly int Version = 2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 17:27:38 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
unsafe struct ModeConnector
|
|
|
|
|
{
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int connector_id;
|
|
|
|
|
public int encoder_id;
|
|
|
|
|
public int connector_type;
|
|
|
|
|
public int connector_type_id;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
public ModeConnection connection;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int mmWidth, mmHeight;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
public ModeSubPixel subpixel;
|
|
|
|
|
|
|
|
|
|
public int count_modes;
|
|
|
|
|
public ModeInfo* modes;
|
|
|
|
|
|
|
|
|
|
public int count_props;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int *props;
|
|
|
|
|
public long *prop_values;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
|
|
|
|
|
public int count_encoders;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int *encoders;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ModeCrtc
|
|
|
|
|
{
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int crtc_id;
|
|
|
|
|
public int buffer_id;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int x, y;
|
|
|
|
|
public int width, height;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
public int mode_valid;
|
|
|
|
|
public ModeInfo mode;
|
|
|
|
|
|
|
|
|
|
public int gamma_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ModeEncoder
|
|
|
|
|
{
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int encoder_id;
|
|
|
|
|
public int encoder_type;
|
|
|
|
|
public int crtc_id;
|
|
|
|
|
public int possible_crtcs;
|
|
|
|
|
public int possible_clones;
|
2014-06-24 17:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
unsafe struct ModeInfo
|
|
|
|
|
{
|
|
|
|
|
public uint clock;
|
|
|
|
|
public ushort hdisplay, hsync_start, hsync_end, htotal, hskew;
|
|
|
|
|
public ushort vdisplay, vsync_start, vsync_end, vtotal, vscan;
|
|
|
|
|
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int vrefresh; // refresh rate * 1000
|
2014-06-24 17:27:38 +00:00
|
|
|
|
|
|
|
|
|
public uint flags;
|
|
|
|
|
public uint type;
|
|
|
|
|
public fixed sbyte name[32];
|
2014-06-23 20:22:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 17:27:38 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
unsafe struct ModeRes
|
2014-06-23 20:22:04 +00:00
|
|
|
|
{
|
|
|
|
|
public int count_fbs;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int* fbs;
|
2014-06-23 20:22:04 +00:00
|
|
|
|
public int count_crtcs;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int* crtcs;
|
2014-06-23 20:22:04 +00:00
|
|
|
|
public int count_connectors;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int* connectors;
|
2014-06-23 20:22:04 +00:00
|
|
|
|
public int count_encoders;
|
2014-06-26 13:40:00 +00:00
|
|
|
|
public int* encoders;
|
2014-06-23 20:22:04 +00:00
|
|
|
|
public int min_width, max_width;
|
|
|
|
|
public int min_height, max_height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|