<Compile Include="src\Extensions.cs" />
<Compile Include="src\Microsoft.Build.CommonTypes.cs" />
<Compile Include="src\CrowIDEdrm.cs" />
- <Compile Include="src\Application.cs" />
<Compile Include="src\Signal.cs" />
- <Compile Include="src\Bindings\Evdev.cs" />
- <Compile Include="src\Bindings\LibInput.cs" />
- <Compile Include="src\Bindings\Udev.cs" />
- <Compile Include="src\DRIControler.cs" />
- <Compile Include="src\BlittableValueType.cs">
- <SubType>Code</SubType>
+ <Compile Include="..\testDrm\src\Linux\Bindings\Udev.cs">
+ <Link>src\Bindings\Udev.cs</Link>
+ </Compile>
+ <Compile Include="..\testDrm\src\Application.cs">
+ <Link>src\Application.cs</Link>
+ </Compile>
+ <Compile Include="..\testDrm\src\BlittableValueType.cs">
+ <Link>src\BlittableValueType.cs</Link>
+ </Compile>
+ <Compile Include="..\testDrm\src\Linux\Bindings\EvdevClass.cs">
+ <Link>src\Bindings\EvdevClass.cs</Link>
+ </Compile>
+ <Compile Include="..\testDrm\src\Linux\Bindings\LibInput.cs">
+ <Link>src\Bindings\LibInput.cs</Link>
+ </Compile>
+ <Compile Include="..\testDrm\src\Linux\DRIControler.cs">
+ <Link>src\DRIControler.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="ui\" />
<Folder Include="src\" />
<Folder Include="images\" />
+ <Folder Include="src\Bindings\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ui\imlEditor.crow" />
+++ /dev/null
-//
-// DrmKms.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-using Linux;
-using Linux.VT;
-using System.Text;
-
-namespace Crow
-{
- public class Application : IDisposable
- {
- public enum RunState {
- ActivateRequest,
- DesactivateRequest,
- Paused,
- Running,
- }
- #if MEASURE_TIME
- public List<PerformanceMeasure> PerfMeasures;
- protected PerformanceMeasure glDrawMeasure = new PerformanceMeasure("OpenGL Draw", 10);
- #endif
-
- public bool Running = true;
- public volatile RunState CurrentState = RunState.Running;
-
- protected Interface CrowInterface;
- protected DRI.DRIControler gpu;
- protected Cairo.GLSurface cairoSurf { get { return gpu?.CairoSurf; }}
-
- protected bool mouseIsInInterface = false;
-
- protected volatile int ifaceSleep = 1, updateSleep = 0;
-
- void interfaceThread()
- {
- while (CrowInterface.ClientRectangle.Size.Width == 0)
- Thread.Sleep (5);
-
- while (true) {
- if (CurrentState == RunState.Running) {
- CrowInterface.Update ();
- Thread.Sleep (ifaceSleep);
- } else
- Thread.Sleep (1000);
- }
- }
-
- int previousVT = -1, appVT = -1;
-
- public Application(){
- if (Kernel.signal (Signal.SIGUSR1, switch_request_handle) < 0)
- throw new Exception ("signal handler registation failed");
-// if (Kernel.signal (Signal.SIGUSR2, switch_request_handle) < 0)
-// throw new Exception ("signal handler registation failed");
- if (Kernel.signal (Signal.SIGINT, sigint_handler) < 0)
- throw new Exception ("SIGINT handler registation failed");
-
- using (VTControler master = new VTControler ()) {
- previousVT = master.CurrentVT;
- appVT = master.FirstAvailableVT;
-
- master.SwitchTo (appVT);
-
- try {
- master.KDMode = KDMode.GRAPHICS;
-// VT.vt_mode vtm = master.VTMode;
-// vtm.mode = VT.SwitchMode.PROCESS;
-// master.VTMode = vtm;
- } catch (Exception ex) {
- Console.WriteLine (ex.ToString ());
- }
- }
-
- initDri ();
-
- initCrow ();
-
- initInput ();
-
- MouseX = gpu.Width / 2;
- MouseY = gpu.Height / 2;
-
- initCursor ();
- }
-
- #region CROW
- public GraphicObject Load (string path){
- return CrowInterface.LoadInterface (path);
- }
-
- void initCrow () {
- CrowInterface = new Interface ();
-
- Thread t = new Thread (interfaceThread);
- t.Name = "Interface";
- t.IsBackground = true;
- t.Start ();
-
- CrowInterface.ProcessResize (new Size (gpu.Width, gpu.Height));
- CrowInterface.MouseCursorChanged += CrowInterface_MouseCursorChanged;
-
- #if MEASURE_TIME
- PerfMeasures = new List<PerformanceMeasure> (
- new PerformanceMeasure[] {
- this.CrowInterface.updateMeasure,
- this.CrowInterface.layoutingMeasure,
- this.CrowInterface.clippingMeasure,
- this.CrowInterface.drawingMeasure,
- this.glDrawMeasure
- }
- );
- #endif
- }
- void CrowInterface_MouseCursorChanged (object sender, MouseCursorChangedEventArgs e)
- {
- gpu.updateCursor (e.NewCursor);
- }
- #endregion
-
- void initDri(){
- gpu = new DRI.DRIControler();
- //cairoSurf = gpu.CairoSurf;
- }
- void initCursor(){
- gpu.updateCursor (XCursor.Default);
- gpu.moveCursor ((uint)MouseX - 8, (uint)MouseY - 4);
- }
-
- void switch_request_handle (Signal s){
- Console.WriteLine ("****** switch request catched: " + s.ToString());
- using (VTControler master = new VTControler ()) {
- Libc.write (master.fd, Encoding.ASCII.GetBytes ("this is a test string"));
- master.AcknoledgeSwitchRequest ();
- }
- }
- void sigint_handler (Signal s){
- Console.WriteLine ("{0}: SIGINT catched");
- Running = false;
- }
-
- public virtual void Run ()
- {
- int cpt = 0;
- while(Running){
- switch (CurrentState) {
- case RunState.ActivateRequest:
- activate ();
- continue;
- case RunState.DesactivateRequest:
- desactivate ();
- continue;
- case RunState.Paused:
- Thread.Sleep (1000);
- continue;
- }
-
- uiDraw ();
-
- #if MEASURE_TIME
- if (cpt%10==0){
- foreach (PerformanceMeasure m in PerfMeasures)
- m.NotifyChanges();
- }
- #endif
-
- cpt++;
- Thread.Sleep (updateSleep);
- }
- }
- protected virtual void uiDraw (){
-// #if MEASURE_TIME
-// glDrawMeasure.StartCycle();
-// #endif
-
- bool update = false;
-
- if (updateMousePos) {
- lock (Sync) {
- updateMousePos = false;
- gpu.moveCursor ((uint)MouseX - 8, (uint)MouseY - 4);
- }
- }
-
- if (Monitor.TryEnter (CrowInterface.RenderMutex)) {
- if (CrowInterface.IsDirty) {
- CrowInterface.IsDirty = false;
- update = true;
- Rectangle r = CrowInterface.DirtyRect;
- using (Cairo.Context ctx = new Cairo.Context (cairoSurf)) {
- using (Cairo.Surface d = new Cairo.ImageSurface (CrowInterface.dirtyBmp, Cairo.Format.ARGB32,
- r.Width, r.Height, r.Width * 4)) {
- ctx.SetSourceSurface (d, 0, 0);
- ctx.Operator = Cairo.Operator.Source;
- ctx.Paint ();
- }
- }
- }
- Monitor.Exit (CrowInterface.RenderMutex);
- }
-
-// if (!update)
-// return;
-// update = false;
-
-
-
-
- cairoSurf.Flush ();
- cairoSurf.SwapBuffers ();
-
- //gpu.UpdateWithPageFlip ();
- gpu.Update();
-
-// #if MEASURE_TIME
-// glDrawMeasure.StopCycle ();
-// #endif
- }
-
- #region INPUT
- Thread input_thread;
- long exit;
-
- static readonly object Sync = new object();
- static readonly Crow.Key[] KeyMap = Evdev.KeyMap;
- static long DeviceFDCount;
-
- IntPtr udev;
- IntPtr input_context;
-
- int input_fd = 0;
-
- InputInterface input_interface = new InputInterface(
- OpenRestricted, CloseRestricted);
- static CloseRestrictedCallback CloseRestricted = CloseRestrictedHandler;
- static void CloseRestrictedHandler(int fd, IntPtr data)
- {
- Debug.Print("[Input] Closing fd {0}", fd);
- int ret = Libc.close(fd);
-
- if (ret < 0)
- {
- Debug.Print("[Input] Failed to close fd {0}. Error: {1}", fd, ret);
- }
- else
- {
- Interlocked.Decrement(ref DeviceFDCount);
- }
- }
-
- static OpenRestrictedCallback OpenRestricted = OpenRestrictedHandler;
- static int OpenRestrictedHandler(IntPtr path, int flags, IntPtr data)
- {
- int fd = Libc.open(path, (OpenFlags)flags);
- Debug.Print("[Input] Opening '{0}' with flags {1}. fd:{2}",
- Marshal.PtrToStringAnsi(path), (OpenFlags)flags, fd);
-
- if (fd >= 0)
- {
- Interlocked.Increment(ref DeviceFDCount);
- }
-
- return fd;
- }
-
- void initInput (){
- Semaphore ready = new Semaphore(0, 1);
- input_thread = new Thread (InputThreadLoop);
- input_thread.Name = "input_thread";
- input_thread.IsBackground = true;
- input_thread.Start(ready);
- }
-
- void InputThreadLoop(object semaphore)
- {
- Debug.Print("[Input] Running on thread {0}", Thread.CurrentThread.ManagedThreadId);
- Setup();
-
- // Inform the parent thread that initialization has completed successfully
- (semaphore as Semaphore).Release();
- Debug.Print("[Input] Released main thread.", input_context);
-
- // Use a blocking poll for input messages, in order to reduce CPU usage
- PollFD poll_fd = new PollFD();
- poll_fd.fd = input_fd;
- poll_fd.events = PollFlags.In;
- Debug.Print("[Input] Created PollFD({0}, {1})", poll_fd.fd, poll_fd.events);
-
- Debug.Print("[Input] Entering input loop.", poll_fd.fd, poll_fd.events);
- while (Interlocked.Read(ref exit) == 0)
- {
- if (CurrentState != RunState.Running) {
- Thread.Sleep (1000);
- continue;
- }
- //drmTimeOut.Restart ();
-
- int ret = Libc.poll(ref poll_fd, 1, -1);
- ErrorNumber error = (ErrorNumber)Marshal.GetLastWin32Error();
- bool is_error =
- ret < 0 && !(error == ErrorNumber.Again || error == ErrorNumber.Interrupted) ||
- (poll_fd.revents & (PollFlags.Hup | PollFlags.Error | PollFlags.Invalid)) != 0;
-
- if (ret > 0 && (poll_fd.revents & (PollFlags.In | PollFlags.Pri)) != 0)
- ProcessEvents(input_context);
-
- if (is_error)
- {
- Debug.Print("[Input] Exiting input loop {0} due to poll error [ret:{1} events:{2}]. Error: {3}.",
- input_thread.ManagedThreadId, ret, poll_fd.revents, error);
- Interlocked.Increment(ref exit);
- }
- }
- Debug.Print("[Input] Exited input loop.", poll_fd.fd, poll_fd.events);
- }
-
- void Setup()
- {
- // Todo: add static path fallback when udev is not installed.
- udev = Udev.New();
- if (udev == IntPtr.Zero)
- {
- Debug.Print("[Input] Udev.New() failed.");
- Interlocked.Increment(ref exit);
- return;
- }
- Debug.Print("[Input] Udev.New() = {0:x}", udev);
-
- input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev);
- if (input_context == IntPtr.Zero)
- {
- Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev);
- Interlocked.Increment(ref exit);
- return;
- }
- 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);
-
- input_fd = LibInput.GetFD(input_context);
- if (input_fd < 0)
- {
- Debug.Print("[Input] LibInput.GetFD({0:x}) failed.", input_context);
- Interlocked.Increment(ref exit);
- return;
- }
- Debug.Print("[Input] LibInput.GetFD({0:x}) = {1}.", input_context, input_fd);
-
- ProcessEvents(input_context);
- LibInput.Resume(input_context);
- Debug.Print("[Input] LibInput.Resume({0:x})", input_context);
-
- if (Interlocked.Read(ref DeviceFDCount) <= 0)
- {
- Debug.Print("[Error] Failed to open any input devices.");
- Debug.Print("[Error] Ensure that you have access to '/dev/input/event*'.");
- Interlocked.Increment(ref exit);
- }
- }
-
- void ProcessEvents(IntPtr input_context)
- {
- // Process all events in the event queue
- while (true)
- {
- // Data available
- int ret = LibInput.Dispatch(input_context);
- if (ret != 0)
- {
- Debug.Print("[Input] LibInput.Dispatch({0:x}) failed. Error: {1}",
- input_context, ret);
- break;
- }
-
- IntPtr pevent = LibInput.GetEvent(input_context);
- if (pevent == IntPtr.Zero)
- {
- break;
- }
-
- IntPtr device = LibInput.GetDevice(pevent);
- InputEventType type = LibInput.GetEventType(pevent);
-
- lock (Sync)
- {
- switch (type)
- {
- // case InputEventType.DeviceAdded:
- // HandleDeviceAdded(input_context, device);
- // break;
- //
- // case InputEventType.DeviceRemoved:
- // HandleDeviceRemoved(input_context, device);
- // break;
- //
- case InputEventType.KeyboardKey:
- //run = false;
- handleKeyboard(LibInput.GetKeyboardEvent(pevent));
- break;
- //
- case InputEventType.PointerAxis:
- handlePointerAxis(LibInput.GetPointerEvent(pevent));
- break;
-
- case InputEventType.PointerButton:
- handlePointerButton (LibInput.GetPointerEvent(pevent));
- break;
-
- case InputEventType.PointerMotion:
- handlePointerMotion (LibInput.GetPointerEvent(pevent));
- break;
-
-// case InputEventType.PointerMotionAbsolute:
-// handlePointerMotionAbsolute(LibInput.GetPointerEvent(pevent));
-// break;
- }
- }
-
- LibInput.DestroyEvent(pevent);
- }
- }
- int MouseX = 0, MouseY = 0;
- volatile bool updateMousePos = true;
-
- int roundDelta (double d){
- return d > 0 ? (int)Math.Ceiling(d) : (int)Math.Floor (d);
- }
- void handlePointerAxis(PointerEvent e){
-// if (e.HasAxis(PointerAxis.HorizontalScroll))
-// {
-// CrowInterface.ProcessMouseWheelChanged ((float)e.AxisValue (PointerAxis.HorizontalScroll));
-// }
- if (e.HasAxis(PointerAxis.VerticalScroll))
- {
- CrowInterface.ProcessMouseWheelChanged ((float)-e.AxisValue (PointerAxis.VerticalScroll));
- }
- }
- void handlePointerMotion(PointerEvent e)
- {
- MouseX += roundDelta (e.DeltaX);
- MouseY += roundDelta (e.DeltaY);
-
- Rectangle bounds = CrowInterface.ClientRectangle;
- if (MouseX < bounds.Left)
- MouseX = bounds.Left;
- else if (MouseX > bounds.Right)
- MouseX = bounds.Right;
-
- if (MouseY < bounds.Top)
- MouseY = bounds.Top;
- else if (MouseY > bounds.Bottom)
- MouseY = bounds.Bottom;
-
- CrowInterface.ProcessMouseMove (MouseX, MouseY);
-
- updateMousePos = true;
- }
- void handlePointerButton (PointerEvent e)
- {
- int but = 0;
- switch (e.Button) {
- case EvdevButton.LEFT:
- but = 0;
- break;
- case EvdevButton.MIDDLE:
- but = 1;
- break;
- case EvdevButton.RIGHT:
- but = 2;
- break;
- }
- if (e.ButtonState == global::Linux.ButtonState.Pressed)
- CrowInterface.ProcessMouseButtonDown (but);
- else
- CrowInterface.ProcessMouseButtonUp (but);
- }
-
- KeyModifiers curModifiers = KeyModifiers.None;
-
- void handleKeyboard(KeyboardEvent e)
- {
- int key = (int)Evdev.KeyMap [e.Key];
- Key k = (Key)key;
- if (e.KeyState == KeyState.Pressed) {
- CrowInterface.ProcessKeyDown (key);
- switch (k) {
- case Key.ShiftLeft:
- case Key.ShiftRight:
- curModifiers |= KeyModifiers.Shift;
- break;
- case Key.ControlLeft:
- case Key.ControlRight:
- curModifiers |= KeyModifiers.Control;
- break;
- case Key.AltLeft:
- curModifiers |= KeyModifiers.Alt;
- break;
- case Key.AltRight:
- curModifiers |= KeyModifiers.AltGr;
- break;
- }
- }else {
- CrowInterface.ProcessKeyUp (key);
- switch (k) {
- case Key.ShiftLeft:
- case Key.ShiftRight:
- curModifiers &= ~KeyModifiers.Shift;
- break;
- case Key.ControlLeft:
- case Key.ControlRight:
- curModifiers &= ~KeyModifiers.Control;
- break;
- case Key.AltLeft:
- curModifiers &= ~KeyModifiers.Alt;
- break;
- case Key.AltRight:
- curModifiers &= ~KeyModifiers.AltGr;
- break;
- }
-// if (!keymap.ContainsKey (curModifiers)) {
-// Console.WriteLine ("keymap not found for: " + curModifiers + " " + (int)curModifiers);
-// return;
-// }
- // string tmp = keymap [curModifiers] [e.Key];
- // if (string.IsNullOrEmpty (tmp))
- // return;
- // if (char.IsControl (tmp[0]))
- // return;
- // CrowInterface.ProcessKeyPress (tmp [0]);
- }
- }
-
- #endregion
-
-
-
- void desactivate () {
- CurrentState = RunState.Paused;
-
- //cairoSurf = null;
- gpu.Dispose ();
- gpu = null;
- }
- void activate (){
- initDri();
- initCursor ();
-
- CurrentState = RunState.Running;
- }
-
- #region IDisposable implementation
- ~Application(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (gpu != null)
- gpu.Dispose ();
- gpu = null;
-
- using (VTControler master = new VTControler ()) {
- // try {
- // master.KDMode = VT.KDMode.TEXT;
- // } catch (Exception ex) {
- // Console.WriteLine (ex.ToString ());
- // }
- master.SwitchTo (previousVT);
- }
-
- }
- #endregion
- }
-}
-
+++ /dev/null
-#region License
-//
-// Evdev.cs
-//
-// Author:
-// Stefanos A. <stapostol@gmail.com>
-//
-// Copyright (c) 2006-2014
-//
-// 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.
-//
-using Linux;
-using Crow;
-
-
-#endregion
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace Linux
-{
- // Bindings for linux/input.h
- class Evdev
- {
- public const int KeyCount = 0x300;
- public const int AxisCount = 0x40;
- public const int EventCount = (int)EvdevType.CNT;
-
- #region KeyMap
-
- public static readonly Key[] KeyMap = new Key[]
- {
- // 0-7
- Key.Unknown,
- Key.Escape,
- Key.Number1,
- Key.Number2,
- Key.Number3,
- Key.Number4,
- Key.Number5,
- Key.Number6,
- // 8-15
- Key.Number7,
- Key.Number8,
- Key.Number9,
- Key.Number0,
- Key.Minus,
- Key.Plus,
- Key.BackSpace,
- Key.Tab,
- // 16-23
- Key.Q,
- Key.W,
- Key.E,
- Key.R,
- Key.T,
- Key.Y,
- Key.U,
- Key.I,
- // 24-31
- Key.O,
- Key.P,
- Key.BracketLeft,
- Key.BracketRight,
- Key.Enter,
- Key.ControlLeft,
- Key.A,
- Key.S,
- // 32-39
- Key.D,
- Key.F,
- Key.G,
- Key.H,
- Key.J,
- Key.K,
- Key.L,
- Key.Semicolon,
- // 40-47
- Key.Quote,
- Key.Tilde,
- Key.ShiftLeft,
- Key.BackSlash, //Key.Execute,
- Key.Z,
- Key.X,
- Key.C,
- Key.V, //Key.Help,
- // 48-55
- Key.B,
- Key.N,
- Key.M,
- Key.Comma,
- Key.Period,
- Key.Slash,
- Key.ShiftRight,
- Key.KeypadMultiply,
- // 56-63
- Key.AltLeft,
- Key.Space,
- Key.CapsLock,
- Key.F1,
- Key.F2,
- Key.F3,
- Key.F4,
- Key.F5,
- // 64-71
- Key.F6,
- Key.F7,
- Key.F8,
- Key.F9,
- Key.F10,
- Key.NumLock,
- Key.ScrollLock,
- Key.Keypad7,
- // 72-79
- Key.Keypad8,
- Key.Keypad9,
- Key.KeypadSubtract,
- Key.Keypad4,
- Key.Keypad5,
- Key.Keypad6,
- Key.KeypadPlus,
- Key.Keypad1,
- // 80-87
- Key.Keypad2,
- Key.Keypad3,
- Key.Keypad0,
- Key.KeypadPeriod,
- Key.Unknown,
- Key.Unknown, // zenkakuhankaku
- Key.Unknown, // 102ND
- Key.F11,
- // 88-95
- Key.F12,
- Key.Unknown, // ro
- Key.Unknown, // katakana
- Key.Unknown, // hiragana
- Key.Unknown, // henkan
- Key.Unknown, // katakanahiragana
- Key.Unknown, // muhenkan
- Key.Unknown, // kpjpcomma
- // 96-103
- Key.KeypadEnter,
- Key.ControlRight,
- Key.KeypadDivide,
- Key.Unknown, // sysrq
- Key.AltRight,
- Key.Unknown, // linefeed
- Key.Home,
- Key.Up,
- // 104-111
- Key.PageUp,
- Key.Left,
- Key.Right,
- Key.End,
- Key.Down,
- Key.PageDown,
- Key.Insert,
- Key.Delete,
- // 112-119
- Key.Unknown, // macro
- Key.Unknown, // mute
- Key.Unknown, // volumedown
- Key.Unknown, // volumeup
- Key.Unknown, // power
- Key.Unknown, // kpequal
- Key.Unknown, // kpplusminus
- Key.Pause,
- // 120-127
- Key.Unknown, // scale
- Key.Unknown, // kpcomma
- Key.Unknown, // hangeul / hanguel
- Key.Unknown, // hanja
- Key.Unknown, // yen
- Key.WinLeft,
- Key.WinRight,
- Key.Unknown, // compose
- // 128-135
- Key.Unknown, // stop
- Key.Unknown, // again
- Key.Unknown, // props
- Key.Unknown, // undo
- Key.Unknown, // front
- Key.Unknown, // copy
- Key.Unknown, // open
- Key.Unknown, // paste
- // 136-143
- Key.Unknown, // find
- Key.Unknown, // cut
- Key.Unknown, // help
- Key.Unknown, // menu
- Key.Unknown, // calc
- Key.Unknown, // setup
- Key.Unknown, // sleep
- Key.Unknown, // wakeup
- // 144-151
- Key.Unknown, // file
- Key.Unknown, // send file
- Key.Unknown, // delete file
- Key.Unknown, // xfer
- Key.Unknown, // prog1
- Key.Unknown, // prog2
- Key.Unknown, // www
- Key.Unknown, // msdos
- // 152-159
- Key.Unknown, // coffee / screenlock
- Key.Unknown, // direction
- Key.Unknown, // cycle windows
- Key.Unknown, // mail
- Key.Unknown, // bookmarks
- Key.Unknown, // computer
- Key.Back,
- Key.Unknown, // forward
- // 160-167
- Key.Unknown, // close cd
- Key.Unknown, // eject cd
- Key.Unknown, // eject/close cd
- Key.Unknown, // next song
- Key.Unknown, // play/pause
- Key.Unknown, // previous song
- Key.Unknown, // stop cd
- Key.Unknown, // record
- // 168-175
- Key.Unknown, // rewind
- Key.Unknown, // phone
- Key.Unknown, // iso
- Key.Unknown, // config
- Key.Unknown, // homepage
- Key.Unknown, // refresh
- Key.Unknown, // exit
- Key.Unknown, // move,
- // 176-183
- Key.Unknown, // edit,
- Key.Unknown, // scroll up,
- Key.Unknown, // scroll down,
- Key.Unknown, // kp left paren,
- Key.Unknown, // kp right paren,
- Key.Unknown, // new,
- Key.Unknown, // redo,
- Key.F13,
- // 184-191
- Key.F14,
- Key.F15,
- Key.F16,
- Key.F17,
- Key.F18,
- Key.F19,
- Key.F20,
- Key.F21,
- // 192-199
- Key.F22,
- Key.F23,
- Key.F24,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- // 200-207
- Key.Unknown, // play cd
- Key.Unknown, // pause cd
- Key.Unknown, // prog3
- Key.Unknown, // prog4
- Key.Unknown, // dashboard
- Key.Unknown, // suspend
- Key.Unknown, // close
- Key.Unknown, // play
- // 208-215
- Key.Unknown, // fast forward
- Key.Unknown, // bass boost
- Key.Unknown, // print
- Key.Unknown, // hp
- Key.Unknown, // camera
- Key.Unknown, // sound
- Key.Unknown, // question
- Key.Unknown, // email
- // 216-223
- Key.Unknown, // chat
- Key.Unknown, // search
- Key.Unknown, // connect
- Key.Unknown, // finance
- Key.Unknown, // sport
- Key.Unknown, // shop
- Key.Unknown, // alt erase
- Key.Unknown, // cancel
- // 224-231
- Key.Unknown, // brightness down
- Key.Unknown, // brightness up
- Key.Unknown, // media
- Key.Unknown, // switch video mode
- Key.Unknown, // dillum toggle
- Key.Unknown, // dillum down
- Key.Unknown, // dillum up
- Key.Unknown, // send
- // 232-239
- Key.Unknown, // reply
- Key.Unknown, // forward email
- Key.Unknown, // save
- Key.Unknown, // documents
- Key.Unknown, // battery
- Key.Unknown, // bluetooth
- Key.Unknown, // wlan
- Key.Unknown, // uwb
- // 240-247
- Key.Unknown,
- Key.Unknown, // video next
- Key.Unknown, // video prev
- Key.Unknown, // brightness cycle
- Key.Unknown, // brightness zero
- Key.Unknown, // display off
- Key.Unknown, // wwan / wimax
- Key.Unknown, // rfkill
- // 248-255
- Key.Unknown, // mic mute
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown,
- Key.Unknown, // reserved
- };
-
- #endregion
-
- public static MouseButton GetMouseButton(EvdevButton button)
- {
- switch (button)
- {
- case EvdevButton.LEFT:
- return MouseButton.Left;
- case EvdevButton.RIGHT:
- return MouseButton.Right;
- case EvdevButton.MIDDLE:
- return MouseButton.Middle;
- case EvdevButton.BTN0:
- return MouseButton.Button1;
- case EvdevButton.BTN1:
- return MouseButton.Button2;
- case EvdevButton.BTN2:
- return MouseButton.Button3;
- case EvdevButton.BTN3:
- return MouseButton.Button4;
- case EvdevButton.BTN4:
- return MouseButton.Button5;
- case EvdevButton.BTN5:
- return MouseButton.Button6;
- case EvdevButton.BTN6:
- return MouseButton.Button7;
- case EvdevButton.BTN7:
- return MouseButton.Button8;
- case EvdevButton.BTN8:
- return MouseButton.Button9;
- default:
- Debug.Print("[Input] Unknown EvdevButton {0}", button);
- return MouseButton.Left;
- }
- }
-
- static uint IOCreate(DirectionFlags dir, int number, int length)
- {
- long v =
- ((byte)dir << 30) |
- ((byte)'E' << 8) |
- (number << 0) |
- (length << 16);
- return (uint)v;
- }
-
- // Get absolute value / limits
- public static int GetAbs(int fd, EvdevAxis axis, out InputAbsInfo info)
- {
- info = default(InputAbsInfo);
- unsafe
- {
- fixed (InputAbsInfo* pinfo = &info)
- {
- // EVIOCGABS(abs) = _IOR('E', 0x40 + (abs), struct input_absinfo)
- uint ioctl = IOCreate(DirectionFlags.Read, (int)axis + 0x40, BlittableValueType<InputAbsInfo>.Stride);
- int retval = Libc.ioctl(fd, ioctl, new IntPtr(pinfo));
- return retval;
- }
- }
- }
-
- // Get supported event bits
- public static int GetBit(int fd, EvdevType ev, int length, IntPtr data)
- {
- // EVIOCGBIT = _IOC(_IOC_READ, 'E', 0x20 + (ev), len)
- uint ioctl = IOCreate(DirectionFlags.Read, (int)ev + 0x20, length);
- int retval = Libc.ioctl(fd, ioctl, data);
- return retval;
- }
-
- public static int GetName(int fd, out string name)
- {
- unsafe
- {
- sbyte* pname = stackalloc sbyte[129];
- int ret = Libc.ioctl(fd, (uint)EvdevIoctl.Name128, new IntPtr(pname));
- name = new string(pname);
- return ret;
- }
- }
-
- public static int GetId(int fd, out EvdevInputId id)
- {
- id = default(EvdevInputId);
- unsafe
- {
- fixed (EvdevInputId* pid = &id)
- {
- return Libc.ioctl(fd, (uint)EvdevIoctl.Id, new IntPtr(pid));
- }
- }
- }
- }
-
- enum EvdevAxis
- {
- X = 0x00,
- Y = 0x01,
- Z = 0x02,
- RX = 0x03,
- RY = 0x04,
- RZ = 0x05,
- THROTTLE = 0x06,
- RUDDER = 0x07,
- WHEEL = 0x08,
- GAS = 0x09,
- BRAKE = 0x0a,
- HAT0X = 0x10,
- HAT0Y = 0x11,
- HAT1X = 0x12,
- HAT1Y = 0x13,
- HAT2X = 0x14,
- HAT2Y = 0x15,
- HAT3X = 0x16,
- HAT3Y = 0x17,
- PRESSURE = 0x18,
- DISTANCE = 0x19,
- TILT_X = 0x1a,
- TILT_Y = 0x1b,
- TOOL_WIDTH = 0x1c,
-
- VOLUME = 0x20,
-
- MISC = 0x28,
-
- MT_SLOT = 0x2f, /* MT slot being modified */
- MT_TOUCH_MAJOR = 0x30, /* Major axis of touching ellipse */
- MT_TOUCH_MINOR = 0x31, /* Minor axis (omit if circular) */
- MT_WIDTH_MAJOR = 0x32, /* Major axis of approaching ellipse */
- MT_WIDTH_MINOR = 0x33, /* Minor axis (omit if circular) */
- MT_ORIENTATION = 0x34, /* Ellipse orientation */
- MT_POSITION_X = 0x35, /* Center X touch position */
- MT_POSITION_Y = 0x36, /* Center Y touch position */
- MT_TOOL_TYPE = 0x37, /* Type of touching device */
- MT_BLOB_ID = 0x38, /* Group a set of packets as a blob */
- MT_TRACKING_ID = 0x39, /* Unique ID of initiated contact */
- MT_PRESSURE = 0x3a, /* Pressure on contact area */
- MT_DISTANCE = 0x3b, /* Contact hover distance */
- MT_TOOL_X = 0x3c, /* Center X tool position */
- MT_TOOL_Y = 0x3d, /* Center Y tool position */
-
- MAX = 0x3f,
- CNT = (MAX+1),
- }
-
- enum EvdevButton
- {
- MISC = 0x100,
- BTN0 = 0x100,
- BTN1 = 0x101,
- BTN2 = 0x102,
- BTN3 = 0x103,
- BTN4 = 0x104,
- BTN5 = 0x105,
- BTN6 = 0x106,
- BTN7 = 0x107,
- BTN8 = 0x108,
- BTN9 = 0x109,
-
- MOUSE = 0x110,
- LEFT = 0x110,
- RIGHT = 0x111,
- MIDDLE = 0x112,
- SIDE = 0x113,
- EXTRA = 0x114,
- FORWARD = 0x115,
- BACK = 0x116,
- TASK = 0x117,
-
- JOYSTICK = 0x120,
- TRIGGER = 0x120,
- THUMB = 0x121,
- THUMB2 = 0x122,
- TOP = 0x123,
- TOP2 = 0x124,
- PINKIE = 0x125,
- BASE = 0x126,
- BASE2 = 0x127,
- BASE3 = 0x128,
- BASE4 = 0x129,
- BASE5 = 0x12a,
- BASE6 = 0x12b,
- DEAD = 0x12f,
-
- GAMEPAD = 0x130,
- SOUTH = 0x130,
- A = SOUTH,
- EAST = 0x131,
- B = EAST,
- C = 0x132,
- NORTH = 0x133,
- X = NORTH,
- WEST = 0x134,
- Y = WEST,
- Z = 0x135,
- TL = 0x136,
- TR = 0x137,
- TL2 = 0x138,
- TR2 = 0x139,
- SELECT = 0x13a,
- START = 0x13b,
- MODE = 0x13c,
- THUMBL = 0x13d,
- THUMBR = 0x13e,
-
- DIGI = 0x140,
- TOOL_PEN = 0x140,
- TOOL_RUBBER = 0x141,
- TOOL_BRUSH = 0x142,
- TOOL_PENCIL = 0x143,
- TOOL_AIRBRUSH = 0x144,
- TOOL_FINGER = 0x145,
- TOOL_MOUSE = 0x146,
- TOOL_LENS = 0x147,
- TOOL_QUINTTAP = 0x148, // Five fingers on trackpad
- TOUCH = 0x14a,
- STYLUS = 0x14b,
- STYLUS2 = 0x14c,
- TOOL_DOUBLETAP = 0x14d,
- TOOL_TRIPLETAP = 0x14e,
- TOOL_QUADTAP = 0x14f, // Four fingers on trackpad
-
- WHEEL = 0x150,
- GEAR_DOWN = 0x150,
- GEAR_UP = 0x151,
-
- DPAD_UP = 0x220,
- DPAD_DOWN = 0x221,
- DPAD_LEFT = 0x222,
- DPAD_RIGHT = 0x223,
-
- Last = 0x300,
- }
-
- enum EvdevType : byte
- {
- SYN = 0x00,
- KEY = 0x01,
- REL = 0x02,
- ABS = 0x03,
- MSC = 0x04,
- SW = 0x05,
- LED = 0x11,
- SND = 0x12,
- REP = 0x14,
- FF = 0x15,
- PWR = 0x16,
- FF_STATUS = 0x17,
- MAX = 0x1f,
- CNT = (MAX+1),
- }
-
- enum EvdevIoctl : uint
- {
- Id = (2u << 30) | ((byte)'E' << 8) | (0x02u << 0) | (8u << 16), //EVIOCGID = _IOR('E', 0x02, struct input_id)
- Name128 = (2u << 30) | ((byte)'E' << 8) | (0x06u << 0) | (128u << 16), //EVIOCGNAME(len) = _IOC(_IOC_READ, 'E', 0x06, len)
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct InputAbsInfo
- {
- public int Value;
- public int Minimum;
- public int Maximum;
- public int Fuzz;
- public int Flat;
- public int Resolution;
- };
-
- [StructLayout(LayoutKind.Sequential)]
- struct InputId
- {
- public ushort BusType;
- public ushort Vendor;
- public ushort Product;
- public ushort Version;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct InputEvent
- {
- public TimeVal Time;
- ushort type;
- public ushort Code;
- public int Value;
-
- public EvdevType Type { get { return (EvdevType)type; } }
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct TimeVal
- {
- public IntPtr Seconds;
- public IntPtr MicroSeconds;
- }
-}
-
+++ /dev/null
-#region License
-//
-// LibInput.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
-
-#pragma warning disable 0169, 0219
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace Linux
-{
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int OpenRestrictedCallback(IntPtr path, int flags, IntPtr data);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate void CloseRestrictedCallback(int fd, IntPtr data);
-
- class LibInput
- {
- internal const string lib = "libinput";
-
- [DllImport(lib, EntryPoint = "libinput_udev_create_context", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr CreateContext(InputInterface @interface,
- 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);
-
- [DllImport(lib, EntryPoint = "libinput_event_destroy", CallingConvention = CallingConvention.Cdecl)]
- public static extern void DestroyEvent(IntPtr @event);
-
- [DllImport(lib, EntryPoint = "libinput_device_get_sysname", CallingConvention = CallingConvention.Cdecl)]
- static extern IntPtr DeviceGetNameInternal(IntPtr device);
- public static string DeviceGetName(IntPtr device)
- {
- unsafe
- {
- return new string((sbyte*)DeviceGetNameInternal(device));
- }
- }
-
- [DllImport(lib, EntryPoint = "libinput_device_get_user_data", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr DeviceGetData(IntPtr device);
-
- [DllImport(lib, EntryPoint = "libinput_device_set_user_data", CallingConvention = CallingConvention.Cdecl)]
- public static extern void DeviceSetData(IntPtr device, IntPtr user_data);
-
- [DllImport(lib, EntryPoint = "libinput_device_get_output_name", CallingConvention = CallingConvention.Cdecl)]
- static extern IntPtr DeviceGetOutputNameInternal(IntPtr device);
- public static string DeviceGetOutputName(IntPtr device)
- {
- unsafe
- {
- sbyte* pname = (sbyte*)DeviceGetOutputNameInternal(device);
- return pname == null ? String.Empty : new string(pname);
- }
- }
-
- [DllImport(lib, EntryPoint = "libinput_device_get_seat", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr DeviceGetSeat(IntPtr device);
-
- [DllImport(lib, EntryPoint = "libinput_device_has_capability", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool DeviceHasCapability(IntPtr device, DeviceCapability capability);
-
- [DllImport(lib, EntryPoint = "libinput_dispatch", CallingConvention = CallingConvention.Cdecl)]
- public static extern int Dispatch(IntPtr libinput);
-
- [DllImport(lib, EntryPoint = "libinput_event_get_device", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr GetDevice(IntPtr @event);
-
- [DllImport(lib, EntryPoint = "libinput_get_event", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr GetEvent(IntPtr libinput);
-
- [DllImport(lib, EntryPoint = "libinput_event_get_keyboard_event", CallingConvention = CallingConvention.Cdecl)]
- public static extern KeyboardEvent GetKeyboardEvent(IntPtr @event);
-
- [DllImport(lib, EntryPoint = "libinput_event_get_pointer_event", CallingConvention = CallingConvention.Cdecl)]
- public static extern PointerEvent GetPointerEvent(IntPtr @event);
-
- [DllImport(lib, EntryPoint = "libinput_event_get_type", CallingConvention = CallingConvention.Cdecl)]
- public static extern InputEventType GetEventType(IntPtr @event);
-
- [DllImport(lib, EntryPoint = "libinput_get_fd", CallingConvention = CallingConvention.Cdecl)]
- public static extern int GetFD(IntPtr libinput);
-
- [DllImport(lib, EntryPoint = "libinput_next_event_type", CallingConvention = CallingConvention.Cdecl)]
- public static extern InputEventType NextEventType(IntPtr libinput);
-
- [DllImport(lib, EntryPoint = "libinput_resume", CallingConvention = CallingConvention.Cdecl)]
- public static extern void Resume(IntPtr libinput);
-
- [DllImport(lib, EntryPoint = "libinput_suspend", CallingConvention = CallingConvention.Cdecl)]
- public static extern void Suspend(IntPtr libinput);
-
- [DllImport(lib, EntryPoint = "libinput_seat_get_logical_name", CallingConvention = CallingConvention.Cdecl)]
- static extern public IntPtr SeatGetLogicalNameInternal(IntPtr seat);
- public static string SeatGetLogicalName(IntPtr seat)
- {
- unsafe
- {
- return new string((sbyte*)SeatGetLogicalNameInternal(seat));
- }
- }
-
- [DllImport(lib, EntryPoint = "libinput_seat_get_physical_name", CallingConvention = CallingConvention.Cdecl)]
- static extern public IntPtr SeatGetPhysicalNameInternal(IntPtr seat);
- public static string SeatGetPhysicalName(IntPtr seat)
- {
- unsafe
- {
- return new string((sbyte*)SeatGetPhysicalNameInternal(seat));
- }
- }
- }
-
- enum DeviceCapability
- {
- Keyboard = 0,
- Mouse,
- Touch
- }
-
- enum InputEventType
- {
- None = 0,
-
- DeviceAdded,
- DeviceRemoved,
-
- KeyboardKey = 300,
-
- PointerMotion = 400,
- PointerMotionAbsolute,
- PointerButton,
- PointerAxis,
-
- TouchDown = 500,
- TouchUP,
- TouchMotion,
- TouchCancel,
-
- /// \internal
- /// <summary>
- /// Signals the end of a set of touchpoints at one device sample
- /// time. This event has no coordinate information attached.
- /// </summary>
- TouchFrame
- }
-
- enum ButtonState
- {
- Released = 0,
- Pressed = 1
- }
-
- enum KeyState
- {
- Released = 0,
- Pressed = 1
- }
-
- enum PointerAxis
- {
- VerticalScroll = 0,
- 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
- {
- internal readonly IntPtr open;
- internal readonly IntPtr close;
-
- public InputInterface(
- OpenRestrictedCallback open_restricted,
- CloseRestrictedCallback close_restricted)
- {
- if (open_restricted == null || close_restricted == null)
- throw new ArgumentNullException();
-
- open = Marshal.GetFunctionPointerForDelegate(open_restricted);
- close = Marshal.GetFunctionPointerForDelegate(close_restricted);
- }
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct KeyboardEvent
- {
- IntPtr @event;
-
- public IntPtr BaseEvent { get { return GetBaseEvent(@event); } }
- public IntPtr Event { get { return @event; } }
- public uint Time { get { return GetTime(@event); } }
- public uint Key { get { return GetKey(@event); } }
- public uint KeyCount { get { return GetSeatKeyCount(@event); } }
- public KeyState KeyState { get { return GetKeyState(@event); } }
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_keyboard_get_time", CallingConvention = CallingConvention.Cdecl)]
- static extern uint GetTime(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_keyboard_get_base_event", CallingConvention = CallingConvention.Cdecl)]
- static extern IntPtr GetBaseEvent(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_keyboard_get_seat_key_count", CallingConvention = CallingConvention.Cdecl)]
- static extern uint GetSeatKeyCount(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_keyboard_get_key", CallingConvention = CallingConvention.Cdecl)]
- static extern uint GetKey(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_keyboard_get_key_state", CallingConvention = CallingConvention.Cdecl)]
- static extern KeyState GetKeyState(IntPtr @event);
- }
-
-
- [StructLayout(LayoutKind.Sequential)]
- struct PointerEvent
- {
- IntPtr @event;
-
- public IntPtr BaseEvent { get { return GetBaseEvent(@event); } }
- public IntPtr Event { get { return @event; } }
- public uint Time { get { return GetTime(@event); } }
- public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } }
- public uint ButtonCount { get { return GetButtonCount(@event); } }
- public ButtonState ButtonState { get { return GetButtonState(@event); } }
- 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);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_base_event", CallingConvention = CallingConvention.Cdecl)]
- static extern IntPtr GetBaseEvent(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_seat_key_count", CallingConvention = CallingConvention.Cdecl)]
- static extern uint GetSeatKeyCount(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button", CallingConvention = CallingConvention.Cdecl)]
- static extern uint GetButton(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_seat_button_count", CallingConvention = CallingConvention.Cdecl)]
- static extern uint GetButtonCount(IntPtr @event);
-
- [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_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 double GetAxisValue(IntPtr @event, PointerAxis axis);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)]
- static extern double GetDX(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dy", CallingConvention = CallingConvention.Cdecl)]
- static extern double GetDY(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x", CallingConvention = CallingConvention.Cdecl)]
- static extern double GetAbsX(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y", CallingConvention = CallingConvention.Cdecl)]
- static extern double GetAbsY(IntPtr @event);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x_transformed", CallingConvention = CallingConvention.Cdecl)]
- static extern double GetAbsXTransformed(IntPtr @event, int width);
-
- [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y_transformed", CallingConvention = CallingConvention.Cdecl)]
- static extern double GetAbsYTransformed(IntPtr @event, int height);
-
- public override string ToString ()
- {
- return string.Format ("[PointerEvent: BaseEvent={0}, Event={1}, Time={2}, Button={3}, ButtonCount={4}, ButtonState={5}, DeltaX={6}, DeltaY={7}, X={8}, Y={9}]", BaseEvent, Event, Time, Button, ButtonCount, ButtonState, DeltaX, DeltaY, X, Y);
- }
- }
-}
-
+++ /dev/null
-#region License
-//
-// Udev.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 Linux
-{
- class Udev
- {
- const string lib = "libudev";
-
- [DllImport(lib, EntryPoint = "udev_new", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr New();
-
- [DllImport(lib, EntryPoint = "udev_destroy", CallingConvention = CallingConvention.Cdecl)]
- public static extern void Destroy(IntPtr Udev);
- }
-}
-
+++ /dev/null
-#region License
-//
-// The Open Toolkit Library License
-//
-// Copyright (c) 2006 - 2010 the Open Toolkit library.
-//
-// 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.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-using System.Reflection;
-
-namespace Linux
-{
- #region BlittableValueType<T>
-
- /// <summary>
- /// Checks whether the specified type parameter is a blittable value type.
- /// </summary>
- /// <remarks>
- /// A blittable value type is a struct that only references other value types recursively,
- /// which allows it to be passed to unmanaged code directly.
- /// </remarks>
- public static class BlittableValueType<T>
- {
- #region Fields
-
- static readonly Type Type;
- static readonly int stride;
-
- #endregion
-
- #region Constructors
-
- static BlittableValueType()
- {
- Type = typeof(T);
- if (Type.IsValueType && !Type.IsGenericType)
- {
- // Does this support generic types? On Mono 2.4.3 it does
- // On .Net it doesn't.
- // http://msdn.microsoft.com/en-us/library/5s4920fa.aspx
- stride = Marshal.SizeOf(typeof(T));
- }
- }
-
- #endregion
-
- #region Public Members
-
- /// <summary>
- /// Gets the size of the type in bytes or 0 for non-blittable types.
- /// </summary>
- /// <remarks>
- /// This property returns 0 for non-blittable types.
- /// </remarks>
- public static int Stride { get { return stride; } }
-
- #region Check
-
- /// <summary>
- /// Checks whether the current typename T is blittable.
- /// </summary>
- /// <returns>True if T is blittable; false otherwise.</returns>
- public static bool Check()
- {
- return Check(Type);
- }
-
- /// <summary>
- /// Checks whether type is a blittable value type.
- /// </summary>
- /// <param name="type">A System.Type to check.</param>
- /// <returns>True if T is blittable; false otherwise.</returns>
- public static bool Check(Type type)
- {
- if (!CheckStructLayoutAttribute(type))
- Debug.Print("Warning: type {0} does not specify a StructLayoutAttribute with Pack=1. The memory layout of the struct may change between platforms.", type.Name);
-
- return CheckType(type);
- }
-
- #endregion
-
- #endregion
-
- #region Private Members
-
- // Checks whether the parameter is a primitive type or consists of primitive types recursively.
- // Throws a NotSupportedException if it is not.
- static bool CheckType(Type type)
- {
- //Debug.Print("Checking type {0} (size: {1} bytes).", type.Name, Marshal.SizeOf(type));
- if (type.IsPrimitive)
- return true;
-
- if (!type.IsValueType)
- return false;
-
- FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- Debug.Indent();
- foreach (FieldInfo field in fields)
- {
- if (!CheckType(field.FieldType))
- return false;
- }
- Debug.Unindent();
-
- return Stride != 0;
- }
-
- // Checks whether the specified struct defines [StructLayout(LayoutKind.Sequential, Pack=1)]
- // or [StructLayout(LayoutKind.Explicit)]
- static bool CheckStructLayoutAttribute(Type type)
- {
- StructLayoutAttribute[] attr = (StructLayoutAttribute[])
- type.GetCustomAttributes(typeof(StructLayoutAttribute), true);
-
- if ((attr == null) ||
- (attr != null && attr.Length > 0 && attr[0].Value != LayoutKind.Explicit && attr[0].Pack != 1))
- return false;
-
- return true;
- }
-
- #endregion
- }
-
- #endregion
-
- #region BlittableValueType
-
- /// <summary>
- /// Checks whether the specified type parameter is a blittable value type.
- /// </summary>
- /// <remarks>
- /// A blittable value type is a struct that only references other value types recursively,
- /// which allows it to be passed to unmanaged code directly.
- /// </remarks>
- public static class BlittableValueType
- {
- #region Check
-
- /// <summary>
- /// Checks whether type is a blittable value type.
- /// </summary>
- /// <param name="type">An instance of the type to check.</param>
- /// <returns>True if T is blittable; false otherwise.</returns>
- public static bool Check<T>(T type)
- {
- return BlittableValueType<T>.Check();
- }
-
- /// <summary>
- /// Checks whether type is a blittable value type.
- /// </summary>
- /// <param name="type">An instance of the type to check.</param>
- /// <returns>True if T is blittable; false otherwise.</returns>
- [CLSCompliant(false)]
- public static bool Check<T>(T[] type)
- {
- return BlittableValueType<T>.Check();
- }
-
- /// <summary>
- /// Checks whether type is a blittable value type.
- /// </summary>
- /// <param name="type">An instance of the type to check.</param>
- /// <returns>True if T is blittable; false otherwise.</returns>
- [CLSCompliant(false)]
- public static bool Check<T>(T[,] type)
- {
- return BlittableValueType<T>.Check();
- }
-
- /// <summary>
- /// Checks whether type is a blittable value type.
- /// </summary>
- /// <param name="type">An instance of the type to check.</param>
- /// <returns>True if T is blittable; false otherwise.</returns>
- [CLSCompliant(false)]
- public static bool Check<T>(T[, ,] type)
- {
- return BlittableValueType<T>.Check();
- }
-
- /// <summary>
- /// Checks whether type is a blittable value type.
- /// </summary>
- /// <param name="type">An instance of the type to check.</param>
- /// <returns>True if T is blittable; false otherwise.</returns>
- [CLSCompliant(false)]
- public static bool Check<T>(T[][] type)
- {
- return BlittableValueType<T>.Check();
- }
-
- #endregion
-
- #region StrideOf
-
- /// <summary>
- /// Returns the size of the specified value type in bytes or 0 if the type is not blittable.
- /// </summary>
- /// <typeparam name="T">The value type. Must be blittable.</typeparam>
- /// <param name="type">An instance of the value type.</param>
- /// <returns>An integer, specifying the size of the type in bytes.</returns>
- /// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
- public static int StrideOf<T>(T type)
- {
- if (!Check(type))
- throw new ArgumentException("type");
-
- return BlittableValueType<T>.Stride;
- }
-
- /// <summary>
- /// Returns the size of a single array element in bytes or 0 if the element is not blittable.
- /// </summary>
- /// <typeparam name="T">The value type.</typeparam>
- /// <param name="type">An instance of the value type.</param>
- /// <returns>An integer, specifying the size of the type in bytes.</returns>
- /// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
- [CLSCompliant(false)]
- public static int StrideOf<T>(T[] type)
- {
- if (!Check(type))
- throw new ArgumentException("type");
-
- return BlittableValueType<T>.Stride;
- }
-
- /// <summary>
- /// Returns the size of a single array element in bytes or 0 if the element is not blittable.
- /// </summary>
- /// <typeparam name="T">The value type.</typeparam>
- /// <param name="type">An instance of the value type.</param>
- /// <returns>An integer, specifying the size of the type in bytes.</returns>
- /// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
- [CLSCompliant(false)]
- public static int StrideOf<T>(T[,] type)
- {
- if (!Check(type))
- throw new ArgumentException("type");
-
- return BlittableValueType<T>.Stride;
- }
-
- /// <summary>
- /// Returns the size of a single array element in bytes or 0 if the element is not blittable.
- /// </summary>
- /// <typeparam name="T">The value type.</typeparam>
- /// <param name="type">An instance of the value type.</param>
- /// <returns>An integer, specifying the size of the type in bytes.</returns>
- /// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
- [CLSCompliant(false)]
- public static int StrideOf<T>(T[, ,] type)
- {
- if (!Check(type))
- throw new ArgumentException("type");
-
- return BlittableValueType<T>.Stride;
- }
-
- #endregion
- }
-
- #endregion
-}
+++ /dev/null
-//
-// DRM.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Threading;
-using DRI.DRM;
-using Linux;
-
-
-namespace DRI {
- #region DRM callback signatures
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void VBlankCallback(int fd, int sequence, int tv_sec, int tv_usec, IntPtr user_data);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void PageFlipCallback(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data);
- #endregion
-
- #region DRM enums
- public enum EncoderType : uint
- {
- NONE=0,
- DAC=1,
- TMDS=2,
- LVDS=3,
- TVDAC=4,
- VIRTUAL=5,
- DSI=6,
- DPMST=7,
- DPI=8,
- }
- [Flags]public enum PageFlipFlags : uint
- {
- FlipEvent = 0x01,
- FlipAsync = 0x02,
- FlipFlags = FlipEvent | FlipAsync
- }
- /// <summary>Video mode flags, bit compatible with the xorg definitions. </summary>
- [Flags]public enum VideoMode
- {
- PHSYNC = 0x01,
- NHSYNC = 0x02,
- PVSYNC = 0x04,
- NVSYNC = 0x08,
- INTERLACE = 0x10,
- DBLSCAN = 0x20,
- CSYNC = 0x40,
- PCSYNC = 0x80,
- NCSYNC = 0x10,
- HSKEW = 0x0200,
- BCAST = 0x0400,
- PIXMUX = 0x0800,
- DBLCLK = 0x1000,
- CLKDIV2 = 0x2000,
- // FLAG_3D_MASK (0x1f<<14)
- // FLAG_3D_NONE = 0x0;
- // FLAG_3D_FRAME_PACKING = 0x4000,
- // FLAG_3D_FIELD_ALTERNATIVE = 0x8000,
- // FLAG_3D_LINE_ALTERNATIVE (3<<14)
- // FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
- // FLAG_3D_L_DEPTH (5<<14)
- // FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
- // FLAG_3D_TOP_AND_BOTTOM (7<<14)
- // FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
- }
- #endregion
-
- #region DRM structs
- [StructLayout(LayoutKind.Sequential)]
- public struct EventContext
- {
- public int version;
- public IntPtr vblank_handler;
- public IntPtr page_flip_handler;
- public static readonly int Version = 2;
- }
- [StructLayout(LayoutKind.Sequential)]
- unsafe public struct drmFrameBuffer {
- public uint fb_id;
- public uint width, height;
- public uint pitch;
- public uint bpp;
- public uint depth;
- /* driver specific handle */
- public uint handle;
- }
- [StructLayout(LayoutKind.Sequential)]
- struct drmClip {
- public ushort x1;
- public ushort y1;
- public ushort x2;
- public ushort y2;
- }
- #endregion
-
- public class DRIControler : IDisposable {
- #region PINVOKE
- const string lib = "libdrm";
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmHandleEvent(int fd, ref EventContext evctx);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeAddFB(int fd, uint width, uint height, byte depth, byte bpp,
- uint stride, uint bo_handle, out uint buf_id);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeRmFB(int fd, uint bufferId);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeDirtyFB(int fd, uint bufferId, IntPtr clips, uint num_clips);
- [DllImport(lib,CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern drmFrameBuffer* drmModeGetFB(int fd, uint fb_id);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern void drmModeFreeFB(drmFrameBuffer* ptr);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- static extern int drmModePageFlip(int fd, uint crtc_id, uint fb_id, PageFlipFlags flags, ref int user_data);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- unsafe static extern int drmModeSetCrtc(int fd, uint crtcId, uint bufferId, uint x, uint y, uint* connectors, int count, ref ModeInfo mode);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeSetCursor2(int fd, uint crtcId, uint bo_handle, uint width, uint height, int hot_x, int hot_y);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeMoveCursor(int fd, uint crtcId, uint x, uint y);
- #endregion
-
- int fd_gpu = -1;
- GBM.Device gbmDev;
- GBM.Surface gbmSurf;
- public EGL.Context eglctx;
- EGL.Surface eglSurf;
-
- Cairo.EGLDevice cairoDev;
- public Cairo.GLSurface CairoSurf;
-
- Resources resources = null;
- Connector connector = null;
- Crtc currentCrtc = null;
- ModeInfo currentMode, originalMode;
- uint originalFB;
-
- byte bpp = 32;
- byte depth = 24;
-
- public volatile int FlipPollingSleep = 1;
-
- #region CTOR
- public DRIControler(string gpu_path = "/dev/dri/card0"){
- fd_gpu = Libc.open(gpu_path, OpenFlags.ReadWrite | OpenFlags.CloseOnExec);
- if (fd_gpu < 0)
- throw new NotSupportedException("[DRI] Failed to open gpu");
-
- resources = new Resources (fd_gpu);
- gbmDev = new GBM.Device (fd_gpu);
- eglctx = new EGL.Context (gbmDev);
-
- try {
- if (defaultConfiguration ())
- Console.WriteLine ("default config ok");
- } catch (Exception ex) {
- Console.WriteLine (ex.ToString());
- }
- }
- #endregion
-
- public int Width { get { return (int)currentMode.hdisplay; }}
- public int Height { get { return (int)currentMode.vdisplay; }}
-
- bool defaultConfiguration (){
- //select the first connected connector
- foreach (Connector c in resources.Connectors) {
- if (c.State == ConnectionStatus.Connected) {
- connector = c;
- break;
- }
- }
- if (connector == null)
- return false;
-
- currentCrtc = connector.CurrentEncoder.CurrentCrtc;
- originalMode = currentCrtc.CurrentMode;
- originalFB = currentCrtc.CurrentFbId;
- //currentMode = originalMode;
- currentMode = getNewMode();
-
- //configure a rendering stack
- gbmSurf = new GBM.Surface (gbmDev, Width, Height,
- GBM.SurfaceFlags.Rendering | GBM.SurfaceFlags.Scanout);
-
- eglSurf = new EGL.Surface (eglctx, gbmSurf);
- eglSurf.MakeCurrent ();
-
- Console.WriteLine ("dpy:{0} ctx{1}", eglctx.dpy, eglctx.ctx);
-
- cairoDev = new Cairo.EGLDevice (eglctx.dpy, eglctx.ctx);
- CairoSurf = new Cairo.GLSurface (cairoDev, eglSurf.handle, Width, Height);
- //cairoSurf = new Cairo.EGLSurface (cairoDev, egl_surface, 1600, 900);
-
- cairoDev.SetThreadAware (false);
-
- if (cairoDev.Acquire () != Cairo.Status.Success)
- Console.WriteLine ("[Cairo]: Failed to acquire egl device.");
-
-// using (Cairo.Context ctx = new Cairo.Context (CairoSurf)) {
-// ctx.Rectangle (0, 0, Width, Height);
-// ctx.SetSourceRGB (0, 0, 1);
-// ctx.Fill ();
-// }
- //CairoSurf.Flush ();
- //CairoSurf.SwapBuffers ();
- //Update ();
- //setScanOutRegion();
- //Thread.Sleep (100);
-
- initPageFlipUpdate ();
- return true;
- }
-
- void handleDestroyFB(ref GBM.gbm_bo bo, ref uint data)
- {
- uint fb = data;
-
- if (fb != 0) {
- if (drmModeRmFB (fd_gpu, fb) != 0)
- Console.WriteLine ("DestroyFB failed");
-
- data = 0;
- }
- }
-
- unsafe GBM.gbm_bo* bo;
- uint fb;
-
- unsafe public void Update(){
- int ret = 0;
- if (!gbmSurf.HasFreeBuffers)
- throw new NotSupportedException("[GBM] Out of free buffer");
- bo = gbmSurf.Lock ();
-
- if (fb == 0) {
- ret = drmModeAddFB (fd_gpu, currentMode.hdisplay, currentMode.vdisplay, (byte)depth, (byte)bpp, bo->Stride, (uint)bo->Handle32, out fb);
- if (ret != 0)
- Console.WriteLine ("addFb failed: {0}", ret);
- }
- uint connId = connector.Id;
- ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, fb, 0, 0, &connId, 1, ref currentMode);
- if (ret != 0)
- Console.WriteLine ("setCrtc failed: {0}", ret);
- gbmSurf.Release (bo);
- }
-
- static void HandlePageFlip(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data)
- {
- user_data = 0;
- }
-
- PollFD fds;
- EventContext evctx;
- static IntPtr PageFlipPtr = Marshal.GetFunctionPointerForDelegate((PageFlipCallback)HandlePageFlip);
- public void initPageFlipUpdate (){
- fds = new PollFD();
- fds.fd = fd_gpu;
- fds.events = PollFlags.In;
-
- evctx = new EventContext();
- evctx.version = EventContext.Version;
- evctx.page_flip_handler = Marshal.GetFunctionPointerForDelegate((PageFlipCallback)HandlePageFlip);
- }
- unsafe public void UpdateWithPageFlip(){
- GBM.gbm_bo* next_bo;
- uint fb;
-
- int timeout = -1;//block ? -1 : 0;
-
- if (!gbmSurf.HasFreeBuffers)
- throw new NotSupportedException("[GBM] Out of free buffer");
-
- next_bo = gbmSurf.Lock ();
-
- int ret = drmModeAddFB (fd_gpu, currentMode.hdisplay, currentMode.vdisplay, (byte)depth, (byte)bpp, next_bo->Stride, (uint)next_bo->Handle32, out fb);
- if (ret != 0)
- Console.WriteLine ("addFb failed: {0}", ret);
- next_bo->SetUserData (ref fb, handleDestroyFB);
-
- if (bo == null) {
- uint connId = connector.Id;
- ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, fb, 0, 0, &connId, 1, ref currentMode);
- if (ret != 0)
- Console.WriteLine ("setCrtc failed: {0}", ret);
- bo = next_bo;
- } else {
-
- int is_flip_queued = 1;
-
- while (drmModePageFlip (fd_gpu, currentCrtc.Id, fb, PageFlipFlags.FlipEvent, ref is_flip_queued) < 0) {
- //Console.WriteLine ("[DRM] Failed to enqueue framebuffer flip.");
- Thread.Sleep (1);
- }
-
- while (is_flip_queued != 0) {
- fds.revents = 0;
- if (Libc.poll (ref fds, 1, timeout) < 0)
- break;
- if ((fds.revents & (PollFlags.Hup | PollFlags.Error)) != 0)
- break;
- if ((fds.revents & PollFlags.In) != 0)
- drmHandleEvent (fd_gpu, ref evctx);
- else
- break;
- Thread.Sleep (FlipPollingSleep);
- }
- if (is_flip_queued != 0)
- Console.WriteLine ("flip canceled");
-
- gbmSurf.Release (bo);
- bo = next_bo;
- }
- }
-
- #region cursor
- GBM.BufferObject boMouseCursor;
-
- internal void updateCursor (Crow.XCursor cursor) {
- uint width = 64, height = 64;
- if (cursor.Width > width || cursor.Height > height){
- Debug.Print("[DRM] Cursor size {0}x{1} unsupported. Maximum is 64x64.",
- cursor.Width, cursor.Height);
- return;
- }
- boMouseCursor = new GBM.BufferObject (gbmDev, width, height, GBM.SurfaceFormat.ARGB8888,
- GBM.SurfaceFlags.Cursor64x64 | GBM.SurfaceFlags.Write);
-
- // Copy cursor.Data into a new buffer of the correct size
- byte[] cursor_data = new byte[width * height * 4];
- for (uint y = 0; y < cursor.Height; y++)
- {
- uint dst_offset = y * width * 4;
- uint src_offset = y * cursor.Width * 4;
- uint src_length = cursor.Width * 4;
- Array.Copy(
- cursor.data, src_offset,
- cursor_data, dst_offset,
- src_length);
- }
-
- boMouseCursor.Data = cursor_data;
- uint crtcid = currentCrtc.Id;
-
- unsafe {
- drmModeSetCursor2 (fd_gpu, crtcid,
- (uint)boMouseCursor.handle->Handle32, width, height, (int)cursor.Xhot, (int)cursor.Yhot);
- //drmModeMoveCursor (fd_gpu, crtcid, 0, 0);
- }
- }
- internal void moveCursor (uint x, uint y){
- drmModeMoveCursor (fd_gpu, currentCrtc.Id, x, y);
- }
- #endregion
-
- ModeInfo getNewMode(){
- ModeInfo mode = currentCrtc.CurrentMode;
- mode.clock = 118250;
- mode.hdisplay = 1600;
- mode.hsync_start = 1696;
- mode.hsync_end = 1856;
- mode.htotal = 2112;
- mode.vdisplay = 900;
- mode.vsync_start = 903;
- mode.vsync_end = 908;
- mode.vtotal = 934;
- mode.flags |= (uint)VideoMode.NHSYNC;
- mode.flags |= (uint)VideoMode.PVSYNC;
- return mode;
- }
-
-
-// unsafe public drmPlane GetPlane (uint id) {
-// drmPlane p = new drmPlane();
-// drmPlane* pPlane = ModeGetPlane (fd_gpu, id);
-// if (pPlane != null) {
-// p = *pPlane;
-// ModeFreePlane (pPlane);
-// }
-// return p;
-// }
-// public void SetPlane (drmPlane p, uint flags, uint crtc_w, uint crtc_h, uint src_w, uint src_h) {
-// ModeSetPlane (fd_gpu, p.plane_id, p.crtc_id, p.fb_id, flags,
-// (int)p.crtc_x, (int)p.crtc_y,
-// crtc_w, crtc_h,
-// p.x, p.y,
-// src_w, src_h);
-//
-//
-// }
-
- #region IDisposable implementation
- ~DRIControler(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- bool disposed = false;
- protected virtual void Dispose (bool disposing){
- if (disposed)
- return;
- unsafe{
- if (bo != null)
- gbmSurf.Release (bo);
- }
- if (fb != 0)
- if (drmModeRmFB (fd_gpu, fb) != 0)
- Console.WriteLine ("DestroyFB failed");
- if (eglctx != null)
- eglctx.ResetMakeCurrent ();
- if (cairoDev != null) {
- cairoDev.Release ();
- CairoSurf.Dispose ();
- cairoDev.Dispose ();
- cairoDev = null;
- CairoSurf = null;
- }
-
- if (boMouseCursor != null) {
- drmModeSetCursor2 (fd_gpu, currentCrtc.Id, 0u, 0, 0, 0, 0);
- boMouseCursor.Dispose ();
- }
- boMouseCursor = null;
- if (connector != null) {
- uint connId = connector.Id;
- unsafe {
- int ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, originalFB, 0, 0, &connId, 1, ref originalMode);
- if (ret != 0)
- Console.WriteLine ("restore Crtc failed: {0}", ret);
- }
- }
- if (eglctx != null) {
- eglctx.ResetMakeCurrent ();
- if (eglSurf != null)
- eglSurf.Dispose ();
- eglSurf = null;
- if (eglctx != null)
- eglctx.Dispose ();
- eglctx = null;
- }
-
- if (gbmSurf != null)
- gbmSurf.Dispose ();
- if (gbmDev != null)
- gbmDev.Dispose ();
- if (currentCrtc != null)
- currentCrtc.Dispose ();
- if (connector != null)
- connector.Dispose ();
- if (resources != null)
- resources.Dispose ();
- resources = null;
- if (fd_gpu > 0)
- Libc.close (fd_gpu);
- fd_gpu = -1;
- disposed = true;
- Console.WriteLine ("GPU controler disposed");
- }
- #endregion
- }
-}
\ No newline at end of file
using System.IO;
using System.Collections.Generic;
using Cairo;
-using Crow.Linux;
using Crow;
using System.Reflection;
using System.Linq;
{
Stopwatch frame = Stopwatch.StartNew ();
- testegldraw ();
+ //testegldraw ();
base.uiDraw ();
using System.Runtime.InteropServices;
using System.Threading;
-using VT = Linux.VT;
-using DRI = Linux.DRI;
-
using Linux;
+using Linux.VT;
using System.Text;
-using OpenTK.Platform.Linux;
using Linux.oldEvDev;
+using Linux.DRI;
namespace Crow
{
public volatile RunState CurrentState = RunState.Running;
protected Interface CrowInterface;
- protected DRI.DRIControler gpu;
+ protected DRIControler gpu;
protected Cairo.GLSurface cairoSurf { get { return gpu?.CairoSurf; }}
protected bool mouseIsInInterface = false;
if (Kernel.signal (Signal.SIGINT, sigint_handler) < 0)
throw new Exception ("SIGINT handler registation failed");
- using (VT.VTControler master = new VT.VTControler ()) {
+ using (VTControler master = new VTControler ()) {
previousVT = master.CurrentVT;
appVT = master.FirstAvailableVT;
master.SwitchTo (appVT);
try {
- master.KDMode = VT.KDMode.GRAPHICS;
+ master.KDMode = KDMode.GRAPHICS;
// VT.vt_mode vtm = master.VTMode;
// vtm.mode = VT.SwitchMode.PROCESS;
// master.VTMode = vtm;
}
}
- initDri ();
+ gpu = new DRIControler();
initCrow ();
}
#endregion
- void initDri(){
- gpu = new DRI.DRIControler();
- //cairoSurf = gpu.CairoSurf;
- }
void initCursor(){
gpu.updateCursor (XCursor.Default);
gpu.moveCursor ((uint)MouseX - 8, (uint)MouseY - 4);
void switch_request_handle (Signal s){
Console.WriteLine ("****** switch request catched: " + s.ToString());
- using (VT.VTControler master = new VT.VTControler ()) {
+ using (VTControler master = new VTControler ()) {
Libc.write (master.fd, Encoding.ASCII.GetBytes ("this is a test string"));
master.AcknoledgeSwitchRequest ();
}
}
}
protected virtual void uiDraw (){
-// #if MEASURE_TIME
-// glDrawMeasure.StartCycle();
-// #endif
+ #if MEASURE_TIME
+ glDrawMeasure.StartCycle();
+ #endif
bool update = false;
Monitor.Exit (CrowInterface.RenderMutex);
}
-// if (!update)
-// return;
-// update = false;
-
-
-
+ if (!update)
+ return;
+ update = false;
cairoSurf.Flush ();
cairoSurf.SwapBuffers ();
//gpu.UpdateWithPageFlip ();
gpu.Update();
-// #if MEASURE_TIME
-// glDrawMeasure.StopCycle ();
-// #endif
+ #if MEASURE_TIME
+ glDrawMeasure.StopCycle ();
+ #endif
}
#region INPUT
void desactivate () {
CurrentState = RunState.Paused;
-
- //cairoSurf = null;
gpu.Dispose ();
gpu = null;
}
void activate (){
- initDri();
+ gpu = new DRIControler();
initCursor ();
-
CurrentState = RunState.Running;
}
gpu.Dispose ();
gpu = null;
- using (VT.VTControler master = new VT.VTControler ()) {
+ using (VTControler master = new VTControler ()) {
// try {
// master.KDMode = VT.KDMode.TEXT;
// } catch (Exception ex) {
Grab = 3,
Ungrab = 4
}
+
+ #region Native structs
[StructLayout(LayoutKind.Sequential)]
public struct InputAbsInfo
{
public int Fuzz;
public int Flat;
public int Resolution;
- };
+ }
[StructLayout(LayoutKind.Sequential)]
public struct InputId
public IntPtr Seconds;
public IntPtr MicroSeconds;
}
+ #endregion
public class Device : IDisposable
{
+++ /dev/null
-//
-// Context.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-using Linux;
-using GBM = Linux.GBM;
-
-namespace EGL
-{
- using EGLNativeDisplayType = IntPtr;
- using EGLNativeWindowType = IntPtr;
- using EGLNativePixmapType = IntPtr;
- using EGLConfig = IntPtr;
- using EGLContext = IntPtr;
- using EGLDisplay = IntPtr;
- using EGLSurface = IntPtr;
- using EGLClientBuffer = IntPtr;
-
- public enum RenderApi
- {
- ES = Egl.OPENGL_ES_API,
- GL = Egl.OPENGL_API,
- VG = Egl.OPENVG_API
- }
- [Flags]public enum RenderableFlags
- {
- ES = Egl.OPENGL_ES_BIT,
- ES2 = Egl.OPENGL_ES2_BIT,
- ES3 = Egl.OPENGL_ES3_BIT,
- GL = Egl.OPENGL_BIT,
- VG = Egl.OPENVG_BIT,
- }
- public enum ErrorCode
- {
- SUCCESS = 12288,
- NOT_INITIALIZED = 12289,
- BAD_ACCESS = 12290,
- BAD_ALLOC = 12291,
- BAD_ATTRIBUTE = 12292,
- BAD_CONFIG = 12293,
- BAD_CONTEXT = 12294,
- BAD_CURRENT_SURFACE = 12295,
- BAD_DISPLAY = 12296,
- BAD_MATCH = 12297,
- BAD_NATIVE_PIXMAP = 12298,
- BAD_NATIVE_WINDOW = 12299,
- BAD_PARAMETER = 12300,
- BAD_SURFACE = 12301,
- CONTEXT_LOST = 12302,
- }
-
- #region consts
- public static class Egl {
- public const int VERSION_1_0 = 1;
- public const int VERSION_1_1 = 1;
- public const int VERSION_1_2 = 1;
- public const int VERSION_1_3 = 1;
- public const int VERSION_1_4 = 1;
- public const int FALSE = 0;
- public const int TRUE = 1;
- public const int DONT_CARE = -1;
- public const int CONTEXT_LOST = 12302;
- public const int BUFFER_SIZE = 12320;
- public const int ALPHA_SIZE = 12321;
- public const int BLUE_SIZE = 12322;
- public const int GREEN_SIZE = 12323;
- public const int RED_SIZE = 12324;
- public const int DEPTH_SIZE = 12325;
- public const int STENCIL_SIZE = 12326;
- public const int CONFIG_CAVEAT = 12327;
- public const int CONFIG_ID = 12328;
- public const int LEVEL = 12329;
- public const int MAX_PBUFFER_HEIGHT = 12330;
- public const int MAX_PBUFFER_PIXELS = 12331;
- public const int MAX_PBUFFER_WIDTH = 12332;
- public const int NATIVE_RENDERABLE = 12333;
- public const int NATIVE_VISUAL_ID = 12334;
- public const int NATIVE_VISUAL_TYPE = 12335;
- public const int PRESERVED_RESOURCES = 12336;
- public const int SAMPLES = 12337;
- public const int SAMPLE_BUFFERS = 12338;
- public const int SURFACE_TYPE = 12339;
- public const int TRANSPARENT_TYPE = 12340;
- public const int TRANSPARENT_BLUE_VALUE = 12341;
- public const int TRANSPARENT_GREEN_VALUE = 12342;
- public const int TRANSPARENT_RED_VALUE = 12343;
- public const int NONE = 12344;
- public const int BIND_TO_TEXTURE_RGB = 12345;
- public const int BIND_TO_TEXTURE_RGBA = 12346;
- public const int MIN_SWAP_INTERVAL = 12347;
- public const int MAX_SWAP_INTERVAL = 12348;
- public const int LUMINANCE_SIZE = 12349;
- public const int ALPHA_MASK_SIZE = 12350;
- public const int COLOR_BUFFER_TYPE = 12351;
- public const int RENDERABLE_TYPE = 12352;
- public const int MATCH_NATIVE_PIXMAP = 12353;
- public const int CONFORMANT = 12354;
- public const int SLOW_CONFIG = 12368;
- public const int NON_CONFORMANT_CONFIG = 12369;
- public const int TRANSPARENT_RGB = 12370;
- public const int RGB_BUFFER = 12430;
- public const int LUMINANCE_BUFFER = 12431;
- public const int NO_TEXTURE = 12380;
- public const int TEXTURE_RGB = 12381;
- public const int TEXTURE_RGBA = 12382;
- public const int TEXTURE_2D = 12383;
- public const int PBUFFER_BIT = 1;
- public const int PIXMAP_BIT = 2;
- public const int WINDOW_BIT = 4;
- public const int VG_COLORSPACE_LINEAR_BIT = 32;
- public const int VG_ALPHA_FORMAT_PRE_BIT = 64;
- public const int MULTISAMPLE_RESOLVE_BOX_BIT = 512;
- public const int SWAP_BEHAVIOR_PRESERVED_BIT = 1024;
- public const int OPENGL_ES_BIT = 1;
- public const int OPENVG_BIT = 2;
- public const int OPENGL_ES2_BIT = 4;
- public const int OPENGL_BIT = 8;
- public const int OPENGL_ES3_BIT = 64;
- public const int VENDOR = 12371;
- public const int VERSION = 12372;
- public const int EXTENSIONS = 12373;
- public const int CLIENT_APIS = 12429;
- public const int HEIGHT = 12374;
- public const int WIDTH = 12375;
- public const int LARGEST_PBUFFER = 12376;
- public const int TEXTURE_FORMAT = 12416;
- public const int TEXTURE_TARGET = 12417;
- public const int MIPMAP_TEXTURE = 12418;
- public const int MIPMAP_LEVEL = 12419;
- public const int RENDER_BUFFER = 12422;
- public const int VG_COLORSPACE = 12423;
- public const int VG_ALPHA_FORMAT = 12424;
- public const int HORIZONTAL_RESOLUTION = 12432;
- public const int VERTICAL_RESOLUTION = 12433;
- public const int PIXEL_ASPECT_RATIO = 12434;
- public const int SWAP_BEHAVIOR = 12435;
- public const int MULTISAMPLE_RESOLVE = 12441;
- public const int BACK_BUFFER = 12420;
- public const int SINGLE_BUFFER = 12421;
- public const int VG_COLORSPACE_sRGB = 12425;
- public const int VG_COLORSPACE_LINEAR = 12426;
- public const int VG_ALPHA_FORMAT_NONPRE = 12427;
- public const int VG_ALPHA_FORMAT_PRE = 12428;
- public const int DISPLAY_SCALING = 10000;
- public const int UNKNOWN = -1;
- public const int BUFFER_PRESERVED = 12436;
- public const int BUFFER_DESTROYED = 12437;
- public const int OPENVG_IMAGE = 12438;
- public const int CONTEXT_CLIENT_TYPE = 12439;
- public const int CONTEXT_CLIENT_VERSION = 12440;
- public const int MULTISAMPLE_RESOLVE_DEFAULT = 12442;
- public const int MULTISAMPLE_RESOLVE_BOX = 12443;
- public const int OPENGL_ES_API = 12448;
- public const int OPENVG_API = 12449;
- public const int OPENGL_API = 12450;
- public const int DRAW = 12377;
- public const int READ = 12378;
- public const int CORE_NATIVE_ENGINE = 12379;
- public const int COLORSPACE = VG_COLORSPACE;
- public const int ALPHA_FORMAT = VG_ALPHA_FORMAT;
- public const int COLORSPACE_sRGB = VG_COLORSPACE_sRGB;
- public const int COLORSPACE_LINEAR = VG_COLORSPACE_LINEAR;
- public const int ALPHA_FORMAT_NONPRE = VG_ALPHA_FORMAT_NONPRE;
- public const int ALPHA_FORMAT_PRE = VG_ALPHA_FORMAT_PRE;
-
- // EGL_ANGLE_d3d_share_handle_client_buffer
- public const int D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200;
- // EGL_ANGLE_window_fixed_size
- public const int FIXED_SIZE_ANGLE = 0x3201;
- // EGL_ANGLE_query_surface_pointer
- [DllImport("libEGL.dll", EntryPoint = "eglQuerySurfacePointerANGLE")]
- public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value);
- // EGL_ANGLE_software_display
- public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1);
- // EGL_ANGLE_direct3d_display
- public static readonly EGLNativeDisplayType D3D11_ELSE_D3D9_DISPLAY_ANGLE = new EGLNativeDisplayType(-2);
- public static readonly EGLNativeDisplayType D3D11_ONLY_DISPLAY_ANGLE = new EGLNativeDisplayType(-3);
- // EGL_ANGLE_device_d3d
- public const int D3D9_DEVICE_ANGLE = 0x33A0;
- public const int D3D11_DEVICE_ANGLE = 0x33A1;
- // EGL_ANGLE_platform_angle
- public const int PLATFORM_ANGLE_ANGLE = 0x3202;
- public const int PLATFORM_ANGLE_TYPE_ANGLE = 0x3203;
- public const int PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE = 0x3204;
- public const int PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE = 0x3205;
- public const int PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE = 0x3206;
- // EGL_ANGLE_platform_angle_d3d
- public const int PLATFORM_ANGLE_TYPE_D3D9_ANGLE = 0x3207;
- public const int PLATFORM_ANGLE_TYPE_D3D11_ANGLE = 0x3208;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_ANGLE = 0x3209;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE = 0x320A;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE = 0x320B;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE = 0x320C;
- public const int PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE = 0x320F;
- // EGL_ANGLE_platform_angle_opengl
- public const int PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D;
- public const int PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE = 0x320E;
- }
- #endregion
-
- unsafe public class Context : IDisposable
- {
- #region pinvoke
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetError")]
- public static extern ErrorCode GetError();
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetDisplay")]
- public static extern EGLDisplay GetDisplay(EGLNativeDisplayType display_id);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglInitialize")]
- public static extern bool Initialize(EGLDisplay dpy, out int major, out int minor);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglTerminate")]
- public static extern bool Terminate(EGLDisplay dpy);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryString")]
- public static extern IntPtr QueryString(EGLDisplay dpy, int name);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetConfigs")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool GetConfigs(EGLDisplay dpy, EGLConfig[] configs, int config_size, out int num_config);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglChooseConfig")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool ChooseConfig(EGLDisplay dpy, int[] attrib_list, [In, Out] EGLConfig[] configs, int config_size, out int num_config);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetConfigAttrib")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool GetConfigAttrib(EGLDisplay dpy, EGLConfig config, int attribute, out int value);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglBindAPI")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool BindAPI(RenderApi api);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryAPI")]
- public static extern int QueryAPI();
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitClient")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool WaitClient();
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglReleaseThread")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool ReleaseThread();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglSwapInterval")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool SwapInterval(EGLDisplay dpy, int interval);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCreateContext")]
- static extern IntPtr eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list);
- public static EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list)
- {
- IntPtr ptr = eglCreateContext(dpy, config, share_context, attrib_list);
- if (ptr == IntPtr.Zero)
- throw new Exception(String.Format("Failed to create EGL context, error: {0}.", GetError()));
- return ptr;
- }
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglDestroyContext")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool DestroyContext(EGLDisplay dpy, EGLContext ctx);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglMakeCurrent")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentContext")]
- public static extern EGLContext GetCurrentContext();
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentSurface")]
- public static extern EGLSurface GetCurrentSurface(int readdraw);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentDisplay")]
- public static extern EGLDisplay GetCurrentDisplay();
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryContext")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool QueryContext(EGLDisplay dpy, EGLContext ctx, int attribute, out int value);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitGL")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool WaitGL();
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitNative")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool WaitNative(int engine);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCopyBuffers")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
- public static extern IntPtr GetProcAddress(string funcname);
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
- public static extern IntPtr GetProcAddress(IntPtr funcname);
- // EGL_EXT_platform_base
- [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")]
- public static extern EGLDisplay GetPlatformDisplayEXT(int platform, EGLNativeDisplayType native_display, int[] attrib_list);
- [DllImport("libEGL.dll", EntryPoint = "eglCreatePlatformWindowSurfaceEXT")]
- public static extern EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType native_window, int[] attrib_list);
- [DllImport("libEGL.dll", EntryPoint = "eglCreatePlatformPixmapSurfaceEXT")]
- public static extern EGLSurface CreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType native_pixmap, int[] attrib_list);
- // Returns true if Egl drivers exist on the system.
- public static bool IsSupported
- {
- get
- {
- try { GetCurrentContext(); }
- catch (Exception) { return false; }
- return true;
- }
- }
- #endregion
-
- int fd_gpu;
- internal EGLDisplay dpy;
- internal EGLContext ctx;
- internal EGLConfig currentCfg;
-
- int major, minor;
-
- public string Version { get { return Marshal.PtrToStringAuto (QueryString (dpy, Egl.VERSION)); }}
- public string Vendor { get { return Marshal.PtrToStringAuto (QueryString (dpy, Egl.VENDOR)); }}
- public string Extensions { get { return Marshal.PtrToStringAuto (QueryString (dpy, Egl.EXTENSIONS)); }}
- public string OffScreenExtensions { get { return Marshal.PtrToStringAuto (QueryString (IntPtr.Zero, Egl.EXTENSIONS)); }}
-
- #region ctor
- public Context (GBM.Device gbmDev)
- {
- dpy = GetDisplay(gbmDev.handle);
-
- if (dpy == IntPtr.Zero)
- throw new NotSupportedException("[EGL] GetDisplay failed.: " + GetError());
-
- if (!Initialize(dpy, out major, out minor))
- throw new NotSupportedException("[EGL] Failed to initialize EGL display. Error code: " + GetError());
-
- if (!BindAPI (RenderApi.GL))
- throw new NotSupportedException("[EGL] Failed to bind EGL Api: " + GetError());
-
- int[] contextAttrib = new int[] {
- Egl.CONTEXT_CLIENT_VERSION, 2,
- Egl.NONE
- };
- int[] desiredConfig = new int[]
- {
- Egl.SURFACE_TYPE, Egl.WINDOW_BIT,
- Egl.RENDERABLE_TYPE, Egl.OPENGL_BIT,
- Egl.RED_SIZE, 1,
- Egl.GREEN_SIZE, 1,
- Egl.BLUE_SIZE, 1,
- Egl.ALPHA_SIZE, 0,
- //Egl.DEPTH_SIZE, 24,
- //Egl.STENCIL_SIZE, 0,
- //Egl.SAMPLE_BUFFERS, 2,
- //Egl.SAMPLES, 0,
- Egl.NONE
- };
- int num_configs;
- IntPtr[] configs = new IntPtr[1];
- if (!ChooseConfig(dpy, desiredConfig, configs, 1, out num_configs))
- throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", GetError()));
-
- currentCfg = configs [0];
-
- ctx = CreateContext(dpy, currentCfg, IntPtr.Zero, contextAttrib);
- if (ctx == IntPtr.Zero)
- throw new NotSupportedException(String.Format("[EGL] Failed to create egl context, error {0}.", GetError()));
- }
- #endregion
-
- public IntPtr GetConfig (int[] desiredCfg){
- int num_configs;
- IntPtr[] configs = new IntPtr[1];
- if (!ChooseConfig(dpy, desiredCfg, configs, 1, out num_configs)||num_configs<1)
- throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", GetError()));
- return configs [0];
- }
- public IntPtr[] GetAllConfigs (){
- int num_configs;
- int[] desiredConfig = new int[]
- {
- Egl.SURFACE_TYPE, Egl.PBUFFER_BIT,
- Egl.RENDERABLE_TYPE, Egl.OPENGL_BIT,
- Egl.NONE
- };
-
- if (!ChooseConfig(dpy, desiredConfig, null, 0, out num_configs)||num_configs==0)
- throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", GetError()));
-
- IntPtr[] configs = new IntPtr[num_configs];
- if (!ChooseConfig(dpy, null, configs, num_configs, out num_configs))
- throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", GetError()));
- return configs;
- }
- public void DumpAllConf(){
- Console.Write ("EGL Configs");
- IntPtr[] configs = GetAllConfigs();
- int[] attribs = new int[] {
- (int)Attribute.BufferSize,
- Egl.RED_SIZE,
- Egl.GREEN_SIZE,
- Egl.BLUE_SIZE,
- Egl.ALPHA_SIZE,
- (int)Attribute.DepthSize,
- //(int)Attribute.Height,
- Egl.WIDTH,
- (int)Attribute.Width,
- (int)Attribute.Samples,
- (int)Attribute.SampleBuffers,
- (int)Attribute.RenderableType,
- (int)Attribute.SurfaceType,
- (int)Attribute.Level,
- (int)Attribute.ConfigCaveat,
- };
-
- for (int i = 0; i < configs.Length; i++) {
- IntPtr conf = configs[i];
- Console.Write ("{0,-3}:", i);
- for (int j = 0; j < attribs.Length; j++) {
- int value;
- GetConfigAttrib (dpy, conf, attribs[j], out value);
- Console.Write ("\t{0} = {1}, ", EglConstToString ((int)attribs[j]), value);
- }
- Console.Write ("\n");
- }
- }
- enum ConfigAttribute {
- RedSize ,
- GreenSize,
- BlueSize,
- AlphaSize
- }
- public void ResetMakeCurrent (){
- if (!Context.MakeCurrent (dpy, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))
- Console.WriteLine ("egl clear current ctx failed");
- }
-
- #region IDisposable implementation
- ~Context(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- try {
- if (ctx != IntPtr.Zero)
- DestroyContext (dpy, ctx);
- if (dpy != IntPtr.Zero)
- Terminate (dpy);
- } catch (Exception ex) {
- Console.WriteLine ("error disposing egl context: {0}", ex.ToString ());
- }finally {
- ctx = IntPtr.Zero;
- dpy = IntPtr.Zero;
- }
- }
- #endregion
-
-
- static string EglConstToString (int cst){
- switch (cst) {
-/* not hex value: EGL_DONT_CARE ((EGLint)-1)
- not hex value: EGL_FALSE 0
- not hex value: EGL_NO_CONTEXT ((EGLContext)0)
- not hex value: EGL_NO_DISPLAY ((EGLDisplay)0)
- not hex value: EGL_NO_SURFACE ((EGLSurface)0)
- not hex value: EGL_TRUE 1
- not hex value: EGL_VERSION_1_1 1
- not hex value: EGL_VERSION_1_2 1
- not hex value: EGL_DISPLAY_SCALING 10000
- not hex value: EGL_UNKNOWN ((EGLint)-1)
- not hex value: EGL_VERSION_1_3 1
- not hex value: EGL_VERSION_1_4 1
- not hex value: EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
- not hex value: EGL_VERSION_1_5 1
- parsing error: EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
- not hex value: EGL_NO_SYNC ((EGLSync)0)
- not hex value: EGL_NO_IMAGE ((EGLImage)0)*/
- case 1:
- return "PBUFFER_BIT|OPENGL_ES_BIT|CONTEXT_OPENGL_CORE_PROFILE_BIT|SYNC_FLUSH_COMMANDS_BIT";
- case 2:
- return "PIXMAP_BIT|OPENVG_BIT|CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT";
- case 4:
- return "WINDOW_BIT|OPENGL_ES2_BIT";
- case 8:
- return "OPENGL_BIT";
- case 32:
- return "VG_COLORSPACE_LINEAR_BIT";
- case 64:
- return "VG_ALPHA_FORMAT_PRE_BIT|OPENGL_ES3_BIT";
- case 512:
- return "MULTISAMPLE_RESOLVE_BOX_BIT";
- case 1024:
- return "SWAP_BEHAVIOR_PRESERVED_BIT";
- case 12288:
- return "SUCCESS";
- case 12289:
- return "NOT_INITIALIZED";
- case 12290:
- return "BAD_ACCESS";
- case 12291:
- return "BAD_ALLOC";
- case 12292:
- return "BAD_ATTRIBUTE";
- case 12293:
- return "BAD_CONFIG";
- case 12294:
- return "BAD_CONTEXT";
- case 12295:
- return "BAD_CURRENT_SURFACE";
- case 12296:
- return "BAD_DISPLAY";
- case 12297:
- return "BAD_MATCH";
- case 12298:
- return "BAD_NATIVE_PIXMAP";
- case 12299:
- return "BAD_NATIVE_WINDOW";
- case 12300:
- return "BAD_PARAMETER";
- case 12301:
- return "BAD_SURFACE";
- case 12302:
- return "CONTEXT_LOST";
- case 12320:
- return "BUFFER_SIZE";
- case 12321:
- return "ALPHA_SIZE";
- case 12322:
- return "BLUE_SIZE";
- case 12323:
- return "GREEN_SIZE";
- case 12324:
- return "RED_SIZE";
- case 12325:
- return "DEPTH_SIZE";
- case 12326:
- return "STENCIL_SIZE";
- case 12327:
- return "CONFIG_CAVEAT";
- case 12328:
- return "CONFIG_ID";
- case 12329:
- return "LEVEL";
- case 12330:
- return "MAX_PBUFFER_HEIGHT";
- case 12331:
- return "MAX_PBUFFER_PIXELS";
- case 12332:
- return "MAX_PBUFFER_WIDTH";
- case 12333:
- return "NATIVE_RENDERABLE";
- case 12334:
- return "NATIVE_VISUAL_ID";
- case 12335:
- return "NATIVE_VISUAL_TYPE";
- case 12337:
- return "SAMPLES";
- case 12338:
- return "SAMPLE_BUFFERS";
- case 12339:
- return "SURFACE_TYPE";
- case 12340:
- return "TRANSPARENT_TYPE";
- case 12341:
- return "TRANSPARENT_BLUE_VALUE";
- case 12342:
- return "TRANSPARENT_GREEN_VALUE";
- case 12343:
- return "TRANSPARENT_RED_VALUE";
- case 12344:
- return "NONE";
- case 12345:
- return "BIND_TO_TEXTURE_RGB";
- case 12346:
- return "BIND_TO_TEXTURE_RGBA";
- case 12347:
- return "MIN_SWAP_INTERVAL";
- case 12348:
- return "MAX_SWAP_INTERVAL";
- case 12349:
- return "LUMINANCE_SIZE";
- case 12350:
- return "ALPHA_MASK_SIZE";
- case 12351:
- return "COLOR_BUFFER_TYPE";
- case 12352:
- return "RENDERABLE_TYPE";
- case 12353:
- return "MATCH_NATIVE_PIXMAP";
- case 12354:
- return "CONFORMANT";
- case 12368:
- return "SLOW_CONFIG";
- case 12369:
- return "NON_CONFORMANT_CONFIG";
- case 12370:
- return "TRANSPARENT_RGB";
- case 12371:
- return "VENDOR";
- case 12372:
- return "VERSION";
- case 12373:
- return "EXTENSIONS";
- case 12374:
- return "HEIGHT";
- case 12375:
- return "WIDTH";
- case 12376:
- return "LARGEST_PBUFFER";
- case 12377:
- return "DRAW";
- case 12378:
- return "READ";
- case 12379:
- return "CORE_NATIVE_ENGINE";
- case 12380:
- return "NO_TEXTURE";
- case 12381:
- return "TEXTURE_RGB";
- case 12382:
- return "TEXTURE_RGBA";
- case 12383:
- return "TEXTURE_2D";
- case 12416:
- return "TEXTURE_FORMAT";
- case 12417:
- return "TEXTURE_TARGET";
- case 12418:
- return "MIPMAP_TEXTURE";
- case 12419:
- return "MIPMAP_LEVEL";
- case 12420:
- return "BACK_BUFFER";
- case 12421:
- return "SINGLE_BUFFER";
- case 12422:
- return "RENDER_BUFFER";
- case 12423:
- return "COLORSPACE|VG_COLORSPACE";
- case 12424:
- return "ALPHA_FORMAT|VG_ALPHA_FORMAT";
- case 12425:
- return "COLORSPACE_sRGB|VG_COLORSPACE_sRGB|GL_COLORSPACE_SRGB";
- case 12426:
- return "COLORSPACE_LINEAR|VG_COLORSPACE_LINEAR|GL_COLORSPACE_LINEAR";
- case 12427:
- return "ALPHA_FORMAT_NONPRE|VG_ALPHA_FORMAT_NONPRE";
- case 12428:
- return "ALPHA_FORMAT_PRE|VG_ALPHA_FORMAT_PRE";
- case 12429:
- return "CLIENT_APIS";
- case 12430:
- return "RGB_BUFFER";
- case 12431:
- return "LUMINANCE_BUFFER";
- case 12432:
- return "HORIZONTAL_RESOLUTION";
- case 12433:
- return "VERTICAL_RESOLUTION";
- case 12434:
- return "PIXEL_ASPECT_RATIO";
- case 12435:
- return "SWAP_BEHAVIOR";
- case 12436:
- return "BUFFER_PRESERVED";
- case 12437:
- return "BUFFER_DESTROYED";
- case 12438:
- return "OPENVG_IMAGE";
- case 12439:
- return "CONTEXT_CLIENT_TYPE";
- case 12440:
- return "CONTEXT_CLIENT_VERSION|CONTEXT_MAJOR_VERSION";
- case 12441:
- return "MULTISAMPLE_RESOLVE";
- case 12442:
- return "MULTISAMPLE_RESOLVE_DEFAULT";
- case 12443:
- return "MULTISAMPLE_RESOLVE_BOX";
- case 12444:
- return "CL_EVENT_HANDLE";
- case 12445:
- return "GL_COLORSPACE";
- case 12448:
- return "OPENGL_ES_API";
- case 12449:
- return "OPENVG_API";
- case 12450:
- return "OPENGL_API";
- case 12465:
- return "GL_TEXTURE_2D";
- case 12466:
- return "GL_TEXTURE_3D";
- case 12467:
- return "GL_TEXTURE_CUBE_MAP_POSITIVE_X";
- case 12468:
- return "GL_TEXTURE_CUBE_MAP_NEGATIVE_X";
- case 12469:
- return "GL_TEXTURE_CUBE_MAP_POSITIVE_Y";
- case 12470:
- return "GL_TEXTURE_CUBE_MAP_NEGATIVE_Y";
- case 12471:
- return "GL_TEXTURE_CUBE_MAP_POSITIVE_Z";
- case 12472:
- return "GL_TEXTURE_CUBE_MAP_NEGATIVE_Z";
- case 12473:
- return "GL_RENDERBUFFER";
- case 12476:
- return "GL_TEXTURE_LEVEL";
- case 12477:
- return "GL_TEXTURE_ZOFFSET";
- case 12498:
- return "IMAGE_PRESERVED";
- case 12528:
- return "SYNC_PRIOR_COMMANDS_COMPLETE";
- case 12529:
- return "SYNC_STATUS";
- case 12530:
- return "SIGNALED";
- case 12531:
- return "UNSIGNALED";
- case 12533:
- return "TIMEOUT_EXPIRED";
- case 12534:
- return "CONDITION_SATISFIED";
- case 12535:
- return "SYNC_TYPE";
- case 12536:
- return "SYNC_CONDITION";
- case 12537:
- return "SYNC_FENCE";
- case 12539:
- return "CONTEXT_MINOR_VERSION";
- case 12541:
- return "CONTEXT_OPENGL_PROFILE_MASK";
- case 12542:
- return "SYNC_CL_EVENT";
- case 12543:
- return "SYNC_CL_EVENT_COMPLETE";
- case 12720:
- return "CONTEXT_OPENGL_DEBUG";
- case 12721:
- return "CONTEXT_OPENGL_FORWARD_COMPATIBLE";
- case 12722:
- return "CONTEXT_OPENGL_ROBUST_ACCESS";
- case 12733:
- return "CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY";
- case 12734:
- return "NO_RESET_NOTIFICATION";
- case 12735:
- return "LOSE_CONTEXT_ON_RESET";
- default:
- return "unknown";
- }
- }
- }
-}
-
+++ /dev/null
-//
-// EGL.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-
-namespace EGL
-{
- public enum Error {
- NoContext = 0,
- NoDisplay = 0,
- NoSurface = 0,
-
- NotInitialized = 0x3001,
- BadAccess = 0x3002,
- BadAlloc = 0x3003,
- BadAttribute = 0x3004,
- BadConfig = 0x3005,
- BadContext = 0x3006,
- BadCurrentSurface= 0x3007,
- BadDisplay = 0x3008,
- BadMatch = 0x3009,
- BadNativePixmap = 0x300A,
- BadNativeWindow = 0x300B,
- BadParameter = 0x300C,
- BadSurface = 0x300D,
-
- ContextLost = 0x300E,
-
- }
- public enum Attribute {
- BufferSize = 0x3020,
- AlphaSize = 0x3021,
- BlueSize = 0x3022,
- GreenSize = 0x3023,
- RedSize = 0x3024,
- DepthSize = 0x3025,
- StencilSize = 0x3026,
- ConfigCaveat= 0x3027,
- ConfigId = 0x3028,
- Level = 0x3029,
- Samples = 0x3031,
- SampleBuffers = 0x3032,
- Height = 0x3056,
- Width = 0x3057,
- LargestPbuffer = 0x3058,
- MaxPbufferHeight = 0x302A,
- MaxPbufferPixels = 0x302B,
- MaxPbufferWidth = 0x302C,
- SurfaceType = 0x3033,
- TransparentType = 0x3034,
- TransparentBlueValue = 0x3035,
- TransparentGreenValue = 0x3036,
- TransparentRedValue = 0x3037,
- BindToTextureRgb = 0x3039,
- RenderableType = 0x3040,
- BindToTextureRgba = 0x303A,
- MinSwapInterval = 0x303B,
- MaxSwapInterval = 0x303C,
- AlphaMaskSize = 0x303E,
- ColorBufferType = 0x303F,
- MatchNativePixmap = 0x3041,
- TransparentRgb = 0x3052,
- }
-
- [Flags]public enum SurfaceType {
- DontCare = -1,
- None = 0x3038,
-
- Pbuffer = 0x0001,
- Pixmap = 0x0002,
- Window = 0x0004,
- VgColorspaceLinear = 0x0020,
- VgAlphaFormatPre = 0x0040,
- MultisampleResolveBox = 0x0200,
- SwapBehaviorPreserved = 0x0400,
- }
- [Flags]public enum RenderableType {
- DontCare = -1,
- None = 0x3038,
-
- OpenglEs = 0x0001,
- Openvg = 0x0002,
- OpenglEs2 = 0x0004,
- Opengl = 0x0008,
- OpenglEs3 = 0x00000040,
- }
- [Flags]enum ConformantType {
- DontCare = -1,
- None = 0x3038,
-
- SlowConfig = 0x3050,
- NonConformantConfig = 0x3051,
- }
- [Flags]enum ColorBufferType {
- RgbBuffer = 0x308E,
- LuminanceBuffer = 0x308F,
- }
-
- [Flags]public enum EglConsts {
- Version10 = 1,
-
- CoreNativeEngine = 0x305B,
-
-
- Draw = 0x3059,
- Extensions = 0x3055,
- False = 0,
- NativeRenderable = 0x302D,
- NativeVisualId = 0x302E,
- NativeVisualType = 0x302F,
-
-
- Read = 0x305A,
-
-
- Success = 0x3000,
-
-
- True = 1,
-
- Vendor = 0x3053,
- Version = 0x3054,
-
-
- Version11 = 1,
-
- BackBuffer = 0x3084,
-
-
- MipmapTexture = 0x3082,
- MipmapLevel = 0x3083,
- NoTexture = 0x305C,
- Texture2d = 0x305F,
- TextureFormat = 0x3080,
- TextureRgb = 0x305D,
- TextureRgba = 0x305E,
- TextureTarget = 0x3081,
- Version12 = 1,
- AlphaFormat = 0x3088,
- AlphaFormatNonpre = 0x308B,
- AlphaFormatPre = 0x308C,
-
- BufferPreserved = 0x3094,
- BufferDestroyed = 0x3095,
- ClientApis = 0x308D,
- Colorspace = 0x3087,
- ColorspaceSrgb = 0x3089,
- ColorspaceLinear = 0x308A,
-
- ContextClientType = 0x3097,
- DisplayScaling = 10000,
- HorizontalResolution = 0x3090,
- LuminanceSize = 0x303D,
-
- OpenglEsApi = 0x30A0,
- OpenvgApi = 0x30A1,
- OpenvgImage = 0x3096,
- PixelAspectRatio = 0x3092,
-
- RenderBuffer = 0x3086,
-
-
-
- SingleBuffer = 0x3085,
- SwapBehavior = 0x3093,
- Unknown = -1,
- VerticalResolution = 0x3091,
- Version13 = 1,
- Conformant = 0x3042,
- ContextClientVersion = 0x3098,
-
- VgAlphaFormat = 0x3088,
- VgAlphaFormatNonpre = 0x308B,
- VgAlphaFormatPre = 0x308C,
-
- VgColorspace = 0x3087,
- VgColorspaceSrgb = 0x3089,
- VgColorspaceLinear = 0x308A,
-
- Version14 = 1,
-
- DefaultDisplay = 0,
-
- MultisampleResolve = 0x3099,
- MultisampleResolveDefault = 0x309A,
- MultisampleResolveBox = 0x309B,
- OpenglApi = 0x30A2,
- Version15 = 1,
- ContextMajorVersion = 0x3098,
- ContextMinorVersion = 0x30FB,
- ContextOpenglProfileMask = 0x30FD,
- ContextOpenglResetNotificationStrategy = 0x31BD,
- NoResetNotification = 0x31BE,
- LoseContextOnReset = 0x31BF,
- ContextOpenglCoreProfileBit = 0x00000001,
- ContextOpenglCompatibilityProfileBit = 0x00000002,
- ContextOpenglDebug = 0x31B0,
- ContextOpenglForwardCompatible = 0x31B1,
- ContextOpenglRobustAccess = 0x31B2,
-
- ClEventHandle = 0x309C,
- SyncClEvent = 0x30FE,
- SyncClEventComplete = 0x30FF,
- SyncPriorCommandsComplete = 0x30F0,
- SyncType = 0x30F7,
- SyncStatus = 0x30F1,
- SyncCondition = 0x30F8,
- Signaled = 0x30F2,
- Unsignaled = 0x30F3,
- SyncFlushCommandsBit = 0x0001,
- Forever = int.MinValue,
- TimeoutExpired = 0x30F5,
- ConditionSatisfied = 0x30F6,
- NoSync = 0,
- SyncFence = 0x30F9,
-
- GlColorspace = 0x309D,
- GlColorspaceSrgb = 0x3089,
- GlColorspaceLinear = 0x308A,
- GlRenderbuffer = 0x30B9,
- GlTexture2d = 0x30B1,
- GlTextureLevel = 0x30BC,
- GlTexture3d = 0x30B2,
- GlTextureZoffset = 0x30BD,
- GlTextureCubeMapPositiveX = 0x30B3,
- GlTextureCubeMapNegativeX = 0x30B4,
- GlTextureCubeMapPositiveY = 0x30B5,
- GlTextureCubeMapNegativeY = 0x30B6,
- GlTextureCubeMapPositiveZ = 0x30B7,
- GlTextureCubeMapNegativeZ = 0x30B8,
- ImagePreserved = 0x30D2,
- NoImage = 0,
- }
-}
-
+++ /dev/null
-//
-// Surface.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace EGL
-{
- using EGLNativeDisplayType = IntPtr;
- using EGLNativeWindowType = IntPtr;
- using EGLNativePixmapType = IntPtr;
- using EGLConfig = IntPtr;
- using EGLContext = IntPtr;
- using EGLDisplay = IntPtr;
- using EGLSurface = IntPtr;
- using EGLClientBuffer = IntPtr;
-
- public class Surface : IDisposable
- {
- #region pinvoke
- [DllImportAttribute("libEGL.dll")]
- internal static extern EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, IntPtr win, IntPtr attrib_list);
- [DllImportAttribute("libEGL.dll")]
- internal static extern EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, int[] attrib_list);
- [DllImportAttribute("libEGL.dll")]
- internal static extern EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, int[] attrib_list);
- [DllImportAttribute("libEGL.dll")][return: MarshalAsAttribute(UnmanagedType.I1)]
- internal static extern bool eglDestroySurface(EGLDisplay dpy, EGLSurface surface);
- [DllImportAttribute("libEGL.dll")][return: MarshalAsAttribute(UnmanagedType.I1)]
- internal static extern bool eglQuerySurface(EGLDisplay dpy, EGLSurface surface, int attribute, out int value);
- [DllImportAttribute("libEGL.dll")]
- internal static extern EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, int buftype, EGLClientBuffer buffer, EGLConfig config, int[] attrib_list);
- [DllImportAttribute("libEGL.dll")][return: MarshalAsAttribute(UnmanagedType.I1)]
- internal static extern bool eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, int attribute, int value);
- [DllImportAttribute("libEGL.dll")][return: MarshalAsAttribute(UnmanagedType.I1)]
- internal static extern bool eglBindTexImage(EGLDisplay dpy, EGLSurface surface, int buffer);
- [DllImportAttribute("libEGL.dll")][return: MarshalAsAttribute(UnmanagedType.I1)]
- internal static extern bool eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, int buffer);
- [DllImportAttribute("libEGL.dll")][return: MarshalAsAttribute(UnmanagedType.I1)]
- internal static extern bool eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);
-
- #endregion
-
- Context ctx;
- internal EGLSurface handle;
-
- Surface (Context _ctx, IntPtr config, int[] attrib_list){
- ctx = _ctx;
- handle = eglCreatePbufferSurface (ctx.dpy, config, attrib_list);
- if (handle == IntPtr.Zero)
- throw new NotSupportedException(String.Format("[EGL] Failed to create surface, error {0}.", EGL.Context.GetError()));
- }
- public Surface (Context _ctx, Linux.GBM.Surface gbmSurf)
- {
- ctx = _ctx;
- handle = eglCreateWindowSurface(ctx.dpy, ctx.currentCfg, gbmSurf.handle, IntPtr.Zero);
- if (handle == IntPtr.Zero)
- throw new NotSupportedException(String.Format("[EGL] Failed to create surface, error {0}.", EGL.Context.GetError()));
- }
- public static Surface CreatePBuffer (Context _ctx, int _width, int _height){
- int[] config = new int[]
- {
- Egl.SURFACE_TYPE, Egl.PBUFFER_BIT,
-// Egl.RENDERABLE_TYPE, Egl.OPENGL_BIT,
-// Egl.RED_SIZE, 8,
-// Egl.GREEN_SIZE, 8,
-// Egl.BLUE_SIZE, 8,
- Egl.NONE
- };
- int[] attribs = new int[]
- {
- Egl.WIDTH, _width,
- Egl.HEIGHT, _height,
- Egl.NONE
- };
- IntPtr cfg = _ctx.GetConfig (config);
- Console.WriteLine ("pbuff cfg: {0}", cfg.ToString ());
- return new Surface (_ctx, cfg, attribs);
- }
-
- public void MakeCurrent (){
- if (!Context.MakeCurrent(ctx.dpy, handle, handle, ctx.ctx))
- throw new NotSupportedException(string.Format("eglMakeCurrent on surface Failed: {0}",Context.GetError()));
- }
- public void SwapBuffers () {
- if (!eglSwapBuffers (ctx.dpy, handle))
- throw new NotSupportedException(string.Format("eglSwapBuffers Failed: {0}",Context.GetError()));
- }
-
- #region IDisposable implementation
- ~Surface(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (handle != IntPtr.Zero)
- eglDestroySurface (ctx.dpy, handle);
- handle = IntPtr.Zero;
- }
- #endregion
-
- }
-}
-
+++ /dev/null
-#region License
-//
-// Drm.cs
-//
-// Author:
-// Stefanos A. <stapostol@gmail.com>
-// Bruyère JP <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2006-2017 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;
-
-#pragma warning disable 0649 // field is never assigned
-
-namespace Crow.Linux
-{
- [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,
- ref int user_data);
-
- class Drm
- {
- const string lib = "libdrm";
-
- [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);
-
- [DllImport(lib, EntryPoint = "drmModeFreeCrtc", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ModeFreeCrtc(IntPtr ptr);
-
- [DllImport(lib, EntryPoint = "drmModeGetCrtc", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr ModeGetCrtc(int fd, int crtcId);
-
- [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)]
- public static extern IntPtr ModeGetConnector(int fd, int connector_id);
-
- [DllImport(lib, EntryPoint = "drmModeGetEncoder", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr ModeGetEncoder(int fd, int encoder_id);
-
- [DllImport(lib, EntryPoint = "drmModeGetResources", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr ModeGetResources(int fd);
-
- [DllImport(lib, EntryPoint = "drmModePageFlip", CallingConvention = CallingConvention.Cdecl)]
- public static extern int ModePageFlip(int fd, int crtc_id, int fb_id,
- PageFlipFlags flags, ref int user_data);
-
- [DllImport(lib, EntryPoint = "drmModeSetCrtc", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern int ModeSetCrtc(int fd, int crtcId, int bufferId,
- int x, int y, int* connectors, int count, ModeInfo* mode);
-
- [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);
- }
-
- enum ModeConnection
- {
- Connected = 1,
- Disconnected = 2,
- Unknown = 3
- }
- enum ModeConnectorType
- {
- Unknown = 0,
- VGA=1,
- DVII=2,
- DVID=3,
- DVIA=4,
- Composite=5,
- SVIDEO=6,
- LVDS=7,
- Component=8,
- PinDIN9 = 9,
- DisplayPort=10,
- HDMIA=11,
- HDMIB=12,
- TV=13,
- eDP=14,
- VIRTUAL=15,
- DSI=16,
- DPI=17
- }
- enum ModeEncoderType
- {
- NONE=0,
- DAC=1,
- TMDS=2,
- LVDS=3,
- TVDAC=4,
- VIRTUAL=5,
- DSI=6,
- DPMST=7,
- DPI=8,
- }
- enum ModeSubPixel
- {
- Unknown = 1,
- HorizontalRgb = 2,
- HorizontalBgr = 3,
- VerticalRgb = 4,
- VerticalBgr = 5,
- None = 6
- }
-
- [Flags]
- enum PageFlipFlags
- {
- FlipEvent = 0x01,
- FlipAsync = 0x02,
- FlipFlags = FlipEvent | FlipAsync
- }
- [Flags]
- enum ModeFlags
- {
- /* Video mode flags */
- /* bit compatible with the xorg definitions. */
- PHSYNC = 0x01,
- NHSYNC = 0x02,
- PVSYNC = 0x04,
- NVSYNC = 0x08,
- INTERLACE = 0x10,
- DBLSCAN = 0x20,
- CSYNC = 0x40,
- PCSYNC = 0x80,
- NCSYNC = 0x10,
- HSKEW = 0x0200,
- BCAST = 0x0400,
- PIXMUX = 0x0800,
- DBLCLK = 0x1000,
- CLKDIV2 = 0x2000,
-// FLAG_3D_MASK (0x1f<<14)
-// FLAG_3D_NONE = 0x0;
-// FLAG_3D_FRAME_PACKING = 0x4000,
-// FLAG_3D_FIELD_ALTERNATIVE = 0x8000,
-// FLAG_3D_LINE_ALTERNATIVE (3<<14)
-// FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
-// FLAG_3D_L_DEPTH (5<<14)
-// FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
-// FLAG_3D_TOP_AND_BOTTOM (7<<14)
-// FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
- }
- [StructLayout(LayoutKind.Sequential)]
- struct EventContext
- {
- public int version;
- public IntPtr vblank_handler;
- public IntPtr page_flip_handler;
-
- public static readonly int Version = 2;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- unsafe struct ModeConnector
- {
- public int connector_id;
- public int encoder_id;
- public ModeConnectorType connector_type;
- public int connector_type_id;
- public ModeConnection connection;
- public int mmWidth, mmHeight;
- public ModeSubPixel subpixel;
-
- public int count_modes;
- public ModeInfo* modes;
-
- public int count_props;
- public int *props;
- public long *prop_values;
-
- public int count_encoders;
- public int *encoders;
- }
-
- struct ModeCrtc
- {
- public int crtc_id;
- public int buffer_id;
-
- public int x, y;
- public int width, height;
- public int mode_valid;
- public ModeInfo mode;
-
- public int gamma_size;
- }
-
- struct ModeEncoder
- {
- public int encoder_id;
- public ModeEncoderType encoder_type;
- public int crtc_id;
- public int possible_crtcs;
- public int possible_clones;
- }
-
- [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;
-
- public int vrefresh; // refresh rate * 1000
-
- public uint flags;
- public uint type;
- public fixed sbyte name[32];
- }
-
- [StructLayout(LayoutKind.Sequential)]
- unsafe struct ModeRes
- {
- public int count_fbs;
- public int* fbs;
- public int count_crtcs;
- public int* crtcs;
- public int count_connectors;
- public int* connectors;
- public int count_encoders;
- public int* encoders;
- public int min_width, max_width;
- public int min_height, max_height;
- }
-}
-
+++ /dev/null
-#region License
-//
-// The Open Toolkit Library License
-//
-// Copyright (c) 2006 - 2011 the Open Toolkit library.
-//
-// 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;
-using System.Collections.Generic;
-using System.Text;
-
-
-namespace Crow.Linux
-{
- using EGLNativeDisplayType = IntPtr;
- using EGLNativeWindowType = IntPtr;
- using EGLNativePixmapType = IntPtr;
- using EGLConfig = IntPtr;
- using EGLContext = IntPtr;
- using EGLDisplay = IntPtr;
- using EGLSurface = IntPtr;
- using EGLClientBuffer = IntPtr;
-
- enum RenderApi
- {
- ES = Egl.OPENGL_ES_API,
- GL = Egl.OPENGL_API,
- VG = Egl.OPENVG_API
- }
-
- [Flags]enum RenderableFlags
- {
- ES = Egl.OPENGL_ES_BIT,
- ES2 = Egl.OPENGL_ES2_BIT,
- ES3 = Egl.OPENGL_ES3_BIT,
- GL = Egl.OPENGL_BIT,
- VG = Egl.OPENVG_BIT,
- }
- public enum ErrorCode
- {
- SUCCESS = 12288,
- NOT_INITIALIZED = 12289,
- BAD_ACCESS = 12290,
- BAD_ALLOC = 12291,
- BAD_ATTRIBUTE = 12292,
- BAD_CONFIG = 12293,
- BAD_CONTEXT = 12294,
- BAD_CURRENT_SURFACE = 12295,
- BAD_DISPLAY = 12296,
- BAD_MATCH = 12297,
- BAD_NATIVE_PIXMAP = 12298,
- BAD_NATIVE_WINDOW = 12299,
- BAD_PARAMETER = 12300,
- BAD_SURFACE = 12301,
- CONTEXT_LOST = 12302,
- }
-
- static partial class Egl
- {
- public const int VERSION_1_0 = 1;
- public const int VERSION_1_1 = 1;
- public const int VERSION_1_2 = 1;
- public const int VERSION_1_3 = 1;
- public const int VERSION_1_4 = 1;
- public const int FALSE = 0;
- public const int TRUE = 1;
- public const int DONT_CARE = -1;
- public const int CONTEXT_LOST = 12302;
- public const int BUFFER_SIZE = 12320;
- public const int ALPHA_SIZE = 12321;
- public const int BLUE_SIZE = 12322;
- public const int GREEN_SIZE = 12323;
- public const int RED_SIZE = 12324;
- public const int DEPTH_SIZE = 12325;
- public const int STENCIL_SIZE = 12326;
- public const int CONFIG_CAVEAT = 12327;
- public const int CONFIG_ID = 12328;
- public const int LEVEL = 12329;
- public const int MAX_PBUFFER_HEIGHT = 12330;
- public const int MAX_PBUFFER_PIXELS = 12331;
- public const int MAX_PBUFFER_WIDTH = 12332;
- public const int NATIVE_RENDERABLE = 12333;
- public const int NATIVE_VISUAL_ID = 12334;
- public const int NATIVE_VISUAL_TYPE = 12335;
- public const int PRESERVED_RESOURCES = 12336;
- public const int SAMPLES = 12337;
- public const int SAMPLE_BUFFERS = 12338;
- public const int SURFACE_TYPE = 12339;
- public const int TRANSPARENT_TYPE = 12340;
- public const int TRANSPARENT_BLUE_VALUE = 12341;
- public const int TRANSPARENT_GREEN_VALUE = 12342;
- public const int TRANSPARENT_RED_VALUE = 12343;
- public const int NONE = 12344;
- public const int BIND_TO_TEXTURE_RGB = 12345;
- public const int BIND_TO_TEXTURE_RGBA = 12346;
- public const int MIN_SWAP_INTERVAL = 12347;
- public const int MAX_SWAP_INTERVAL = 12348;
- public const int LUMINANCE_SIZE = 12349;
- public const int ALPHA_MASK_SIZE = 12350;
- public const int COLOR_BUFFER_TYPE = 12351;
- public const int RENDERABLE_TYPE = 12352;
- public const int MATCH_NATIVE_PIXMAP = 12353;
- public const int CONFORMANT = 12354;
- public const int SLOW_CONFIG = 12368;
- public const int NON_CONFORMANT_CONFIG = 12369;
- public const int TRANSPARENT_RGB = 12370;
- public const int RGB_BUFFER = 12430;
- public const int LUMINANCE_BUFFER = 12431;
- public const int NO_TEXTURE = 12380;
- public const int TEXTURE_RGB = 12381;
- public const int TEXTURE_RGBA = 12382;
- public const int TEXTURE_2D = 12383;
- public const int PBUFFER_BIT = 1;
- public const int PIXMAP_BIT = 2;
- public const int WINDOW_BIT = 4;
- public const int VG_COLORSPACE_LINEAR_BIT = 32;
- public const int VG_ALPHA_FORMAT_PRE_BIT = 64;
- public const int MULTISAMPLE_RESOLVE_BOX_BIT = 512;
- public const int SWAP_BEHAVIOR_PRESERVED_BIT = 1024;
- public const int OPENGL_ES_BIT = 1;
- public const int OPENVG_BIT = 2;
- public const int OPENGL_ES2_BIT = 4;
- public const int OPENGL_BIT = 8;
- public const int OPENGL_ES3_BIT = 64;
- public const int VENDOR = 12371;
- public const int VERSION = 12372;
- public const int EXTENSIONS = 12373;
- public const int CLIENT_APIS = 12429;
- public const int HEIGHT = 12374;
- public const int WIDTH = 12375;
- public const int LARGEST_PBUFFER = 12376;
- public const int TEXTURE_FORMAT = 12416;
- public const int TEXTURE_TARGET = 12417;
- public const int MIPMAP_TEXTURE = 12418;
- public const int MIPMAP_LEVEL = 12419;
- public const int RENDER_BUFFER = 12422;
- public const int VG_COLORSPACE = 12423;
- public const int VG_ALPHA_FORMAT = 12424;
- public const int HORIZONTAL_RESOLUTION = 12432;
- public const int VERTICAL_RESOLUTION = 12433;
- public const int PIXEL_ASPECT_RATIO = 12434;
- public const int SWAP_BEHAVIOR = 12435;
- public const int MULTISAMPLE_RESOLVE = 12441;
- public const int BACK_BUFFER = 12420;
- public const int SINGLE_BUFFER = 12421;
- public const int VG_COLORSPACE_sRGB = 12425;
- public const int VG_COLORSPACE_LINEAR = 12426;
- public const int VG_ALPHA_FORMAT_NONPRE = 12427;
- public const int VG_ALPHA_FORMAT_PRE = 12428;
- public const int DISPLAY_SCALING = 10000;
- public const int UNKNOWN = -1;
- public const int BUFFER_PRESERVED = 12436;
- public const int BUFFER_DESTROYED = 12437;
- public const int OPENVG_IMAGE = 12438;
- public const int CONTEXT_CLIENT_TYPE = 12439;
- public const int CONTEXT_CLIENT_VERSION = 12440;
- public const int MULTISAMPLE_RESOLVE_DEFAULT = 12442;
- public const int MULTISAMPLE_RESOLVE_BOX = 12443;
- public const int OPENGL_ES_API = 12448;
- public const int OPENVG_API = 12449;
- public const int OPENGL_API = 12450;
- public const int DRAW = 12377;
- public const int READ = 12378;
- public const int CORE_NATIVE_ENGINE = 12379;
- public const int COLORSPACE = VG_COLORSPACE;
- public const int ALPHA_FORMAT = VG_ALPHA_FORMAT;
- public const int COLORSPACE_sRGB = VG_COLORSPACE_sRGB;
- public const int COLORSPACE_LINEAR = VG_COLORSPACE_LINEAR;
- public const int ALPHA_FORMAT_NONPRE = VG_ALPHA_FORMAT_NONPRE;
- public const int ALPHA_FORMAT_PRE = VG_ALPHA_FORMAT_PRE;
-
- // EGL_ANGLE_d3d_share_handle_client_buffer
- public const int D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200;
- // EGL_ANGLE_window_fixed_size
- public const int FIXED_SIZE_ANGLE = 0x3201;
- // EGL_ANGLE_query_surface_pointer
- [DllImport("libEGL.dll", EntryPoint = "eglQuerySurfacePointerANGLE")]
- public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value);
- // EGL_ANGLE_software_display
- public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1);
- // EGL_ANGLE_direct3d_display
- public static readonly EGLNativeDisplayType D3D11_ELSE_D3D9_DISPLAY_ANGLE = new EGLNativeDisplayType(-2);
- public static readonly EGLNativeDisplayType D3D11_ONLY_DISPLAY_ANGLE = new EGLNativeDisplayType(-3);
- // EGL_ANGLE_device_d3d
- public const int D3D9_DEVICE_ANGLE = 0x33A0;
- public const int D3D11_DEVICE_ANGLE = 0x33A1;
- // EGL_ANGLE_platform_angle
- public const int PLATFORM_ANGLE_ANGLE = 0x3202;
- public const int PLATFORM_ANGLE_TYPE_ANGLE = 0x3203;
- public const int PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE = 0x3204;
- public const int PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE = 0x3205;
- public const int PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE = 0x3206;
- // EGL_ANGLE_platform_angle_d3d
- public const int PLATFORM_ANGLE_TYPE_D3D9_ANGLE = 0x3207;
- public const int PLATFORM_ANGLE_TYPE_D3D11_ANGLE = 0x3208;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_ANGLE = 0x3209;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE = 0x320A;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE = 0x320B;
- public const int PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE = 0x320C;
- public const int PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE = 0x320F;
- // EGL_ANGLE_platform_angle_opengl
- public const int PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D;
- public const int PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE = 0x320E;
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetError")]
- public static extern ErrorCode GetError();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetDisplay")]
- public static extern EGLDisplay GetDisplay(EGLNativeDisplayType display_id);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglInitialize")]
- //[return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool Initialize(EGLDisplay dpy, out int major, out int minor);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglTerminate")]
- //[return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool Terminate(EGLDisplay dpy);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryString")]
- public static extern IntPtr QueryString(EGLDisplay dpy, int name);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetConfigs")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool GetConfigs(EGLDisplay dpy, EGLConfig[] configs, int config_size, out int num_config);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglChooseConfig")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool ChooseConfig(EGLDisplay dpy, int[] attrib_list, [In, Out] EGLConfig[] configs, int config_size, out int num_config);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetConfigAttrib")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool GetConfigAttrib(EGLDisplay dpy, EGLConfig config, int attribute, out int value);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCreateWindowSurface")]
- public static extern EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, IntPtr win, IntPtr attrib_list);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePbufferSurface")]
- public static extern EGLSurface CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, int[] attrib_list);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePixmapSurface")]
- public static extern EGLSurface CreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, int[] attrib_list);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglDestroySurface")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool DestroySurface(EGLDisplay dpy, EGLSurface surface);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQuerySurface")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool QuerySurface(EGLDisplay dpy, EGLSurface surface, int attribute, out int value);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglBindAPI")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool BindAPI(RenderApi api);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryAPI")]
- public static extern int QueryAPI();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitClient")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool WaitClient();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglReleaseThread")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool ReleaseThread();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePbufferFromClientBuffer")]
- public static extern EGLSurface CreatePbufferFromClientBuffer(EGLDisplay dpy, int buftype, EGLClientBuffer buffer, EGLConfig config, int[] attrib_list);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglSurfaceAttrib")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool SurfaceAttrib(EGLDisplay dpy, EGLSurface surface, int attribute, int value);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglBindTexImage")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool BindTexImage(EGLDisplay dpy, EGLSurface surface, int buffer);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglReleaseTexImage")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, int buffer);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglSwapInterval")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool SwapInterval(EGLDisplay dpy, int interval);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCreateContext")]
- static extern IntPtr eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list);
-
- public static EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list)
- {
- IntPtr ptr = eglCreateContext(dpy, config, share_context, attrib_list);
- if (ptr == IntPtr.Zero)
- throw new Exception(String.Format("Failed to create EGL context, error: {0}.", GetError()));
- return ptr;
- }
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglDestroyContext")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool DestroyContext(EGLDisplay dpy, EGLContext ctx);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglMakeCurrent")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentContext")]
- public static extern EGLContext GetCurrentContext();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentSurface")]
- public static extern EGLSurface GetCurrentSurface(int readdraw);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentDisplay")]
- public static extern EGLDisplay GetCurrentDisplay();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryContext")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool QueryContext(EGLDisplay dpy, EGLContext ctx, int attribute, out int value);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitGL")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool WaitGL();
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitNative")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool WaitNative(int engine);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglSwapBuffers")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool SwapBuffers(EGLDisplay dpy, EGLSurface surface);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglCopyBuffers")]
- [return: MarshalAsAttribute(UnmanagedType.I1)]
- public static extern bool CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
- public static extern IntPtr GetProcAddress(string funcname);
-
- [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
- public static extern IntPtr GetProcAddress(IntPtr funcname);
-
- // EGL_EXT_platform_base
- [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")]
- public static extern EGLDisplay GetPlatformDisplayEXT(int platform, EGLNativeDisplayType native_display, int[] attrib_list);
-
- [DllImport("libEGL.dll", EntryPoint = "eglCreatePlatformWindowSurfaceEXT")]
- public static extern EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType native_window, int[] attrib_list);
-
- [DllImport("libEGL.dll", EntryPoint = "eglCreatePlatformPixmapSurfaceEXT")]
- public static extern EGLSurface CreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType native_pixmap, int[] attrib_list);
-
- // Returns true if Egl drivers exist on the system.
- public static bool IsSupported
- {
- get
- {
- try { GetCurrentContext(); }
- catch (Exception) { return false; }
- return true;
- }
- }
-
- }
-#pragma warning restore 0169
-}
\ No newline at end of file
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
-using OpenTK;
+
using Linux;
using Crow;
unsafe
{
sbyte* pname = stackalloc sbyte[129];
- int ret = Libc.ioctl(fd, EvdevIoctl.Name128, new IntPtr(pname));
+ int ret = Libc.ioctl(fd, (uint)EvdevIoctl.Name128, new IntPtr(pname));
name = new string(pname);
return ret;
}
{
fixed (EvdevInputId* pid = &id)
{
- return Libc.ioctl(fd, EvdevIoctl.Id, new IntPtr(pid));
+ return Libc.ioctl(fd, (uint)EvdevIoctl.Id, new IntPtr(pid));
}
}
}
+++ /dev/null
-#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 Linux.gbm
-{
- using Device = IntPtr; // struct gbm_device*
- using Surface = IntPtr;
- using BufferObjectHandle = IntPtr;
-
-// [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-// delegate void DestroyUserDataCallback(BufferObject bo, IntPtr data);
-
- class Gbm
- {
- const string lib = "gbm";
-
- [DllImport(lib, EntryPoint = "gbm_bo_create", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern gbm_bo* CreateBO (Device gbm, int width, int height, SurfaceFormat format, SurfaceFlags flags);
-
- [DllImport(lib, EntryPoint = "gbm_bo_destroy", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern void DestroyBuffer (gbm_bo* bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_write", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOWrite(IntPtr bo, IntPtr buf, IntPtr count);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_device", CallingConvention = CallingConvention.Cdecl)]
- public static extern Device BOGetDevice(IntPtr bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_handle", CallingConvention = CallingConvention.Cdecl)]
- public static extern BufferObjectHandle BOGetHandle(IntPtr bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_handle", CallingConvention = CallingConvention.Cdecl)]
- public static extern ulong BOGetHandle(ref gbm_bo bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_height", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOGetHeight(IntPtr bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_width", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOGetWidth(IntPtr bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_stride", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOGetStride(IntPtr bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_get_stride", CallingConvention = CallingConvention.Cdecl)]
- public static extern uint BOGetStride (ref gbm_bo bo);
-
- [DllImport(lib, EntryPoint = "gbm_bo_set_user_data", CallingConvention = CallingConvention.Cdecl)]
- public static extern void BOSetUserData(ref gbm_bo bo, IntPtr data, IntPtr callback);
-
-// [DllImport(lib, EntryPoint = "gbm_bo_get_user_data", CallingConvention = CallingConvention.Cdecl)]
-// public static extern IntPtr BOGetUserData (IntPtr bo);
-
- [DllImport(lib, EntryPoint = "gbm_create_device", CallingConvention = CallingConvention.Cdecl)]
- public static extern Device CreateDevice(int fd);
-
- [DllImport(lib, EntryPoint = "gbm_device_destroy", CallingConvention = CallingConvention.Cdecl)]
- public static extern void DestroyDevice(Device gbm);
-
- [DllImport(lib, EntryPoint = "gbm_device_get_fd", CallingConvention = CallingConvention.Cdecl)]
- public static extern int DeviceGetFD(IntPtr gbm);
-
- [DllImport(lib, EntryPoint = "gbm_surface_create", CallingConvention = CallingConvention.Cdecl)]
- public static extern Surface CreateSurface(Device gbm, int width, int height, SurfaceFormat format, SurfaceFlags flags);
-
- [DllImport(lib, EntryPoint = "gbm_surface_destroy", CallingConvention = CallingConvention.Cdecl)]
- public static extern void DestroySurface(IntPtr surface);
-
- [DllImport(lib, EntryPoint = "gbm_device_is_format_supported", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool IsFormatSupported(Device gbm, SurfaceFormat format, SurfaceFlags usage);
-
- [DllImport(lib, EntryPoint = "gbm_surface_lock_front_buffer", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern gbm_bo* LockFrontBuffer(Surface surface);
-
- [DllImport(lib, EntryPoint = "gbm_surface_release_buffer", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern void ReleaseBuffer(Surface surface, gbm_bo* buffer);
-
- [DllImport(lib, EntryPoint = "gbm_surface_has_free_buffers", CallingConvention = CallingConvention.Cdecl)]
- public static extern int HasFreeBuffers (Surface surface);
-
- [DllImport(lib, EntryPoint = "gbm_bo_map", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern IntPtr Map (gbm_bo* bo, uint x, uint y, uint width, uint height, TransferFlags flags, ref uint stride, out IntPtr data);
-
- [DllImport(lib, EntryPoint = "gbm_bo_unmap", CallingConvention = CallingConvention.Cdecl)]
- unsafe public static extern void Unmap (gbm_bo* bo, IntPtr data);
-
- }
-
- public enum SurfaceFormat : uint
- {
- BigEndian = 1u << 31,
- C8 = ((int)('C') | ((int)('8') << 8) | ((int)(' ') << 16) | ((int)(' ') << 24)),
-
- RGB332 = ((int)('R') | ((int)('G') << 8) | ((int)('B') << 16) | ((int)('8') << 24)),
- BGR233 = ((int)('B') | ((int)('G') << 8) | ((int)('R') << 16) | ((int)('8') << 24)),
-
- XRGB4444 = ((int)('X') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- XBGR4444 = ((int)('X') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- RGBX4444 = ((int)('R') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- BGRX4444 = ((int)('B') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
-
- ARGB4444 = ((int)('A') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- ABGR4444 = ((int)('A') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- RGBA4444 = ((int)('R') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- BGRA4444 = ((int)('B') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
-
- XRGB1555 = ((int)('X') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- XBGR1555 = ((int)('X') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- RGBX5551 = ((int)('R') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- BGRX5551 = ((int)('B') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
-
- ARGB1555 = ((int)('A') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- ABGR1555 = ((int)('A') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- RGBA5551 = ((int)('R') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- BGRA5551 = ((int)('B') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
-
- RGB565 = ((int)('R') | ((int)('G') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- BGR565 = ((int)('B') | ((int)('G') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
-
- RGB888 = ((int)('R') | ((int)('G') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- BGR888 = ((int)('B') | ((int)('G') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
-
- XRGB8888 = ((int)('X') | ((int)('R') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- XBGR8888 = ((int)('X') | ((int)('B') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- RGBX8888 = ((int)('R') | ((int)('X') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- BGRX8888 = ((int)('B') | ((int)('X') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
-
- ARGB8888 = ((int)('A') | ((int)('R') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- ABGR8888 = ((int)('A') | ((int)('B') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- RGBA8888 = ((int)('R') | ((int)('A') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- BGRA8888 = ((int)('B') | ((int)('A') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
-
- XRGB2101010 = ((int)('X') | ((int)('R') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- XBGR2101010 = ((int)('X') | ((int)('B') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- RGBX1010102 = ((int)('R') | ((int)('X') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- BGRX1010102 = ((int)('B') | ((int)('X') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
-
- ARGB2101010 = ((int)('A') | ((int)('R') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- ABGR2101010 = ((int)('A') | ((int)('B') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- RGBA1010102 = ((int)('R') | ((int)('A') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- BGRA1010102 = ((int)('B') | ((int)('A') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
-
- YUYV = ((int)('Y') | ((int)('U') << 8) | ((int)('Y') << 16) | ((int)('V') << 24)),
- YVYU = ((int)('Y') | ((int)('V') << 8) | ((int)('Y') << 16) | ((int)('U') << 24)),
- UYVY = ((int)('U') | ((int)('Y') << 8) | ((int)('V') << 16) | ((int)('Y') << 24)),
- VYUY = ((int)('V') | ((int)('Y') << 8) | ((int)('U') << 16) | ((int)('Y') << 24)),
-
- AYUV = ((int)('A') | ((int)('Y') << 8) | ((int)('U') << 16) | ((int)('V') << 24)),
-
- NV12 = ((int)('N') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- NV21 = ((int)('N') | ((int)('V') << 8) | ((int)('2') << 16) | ((int)('1') << 24)),
- NV16 = ((int)('N') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- NV61 = ((int)('N') | ((int)('V') << 8) | ((int)('6') << 16) | ((int)('1') << 24)),
-
- YUV410 = ((int)('Y') | ((int)('U') << 8) | ((int)('V') << 16) | ((int)('9') << 24)),
- YVU410 = ((int)('Y') | ((int)('V') << 8) | ((int)('U') << 16) | ((int)('9') << 24)),
- YUV411 = ((int)('Y') | ((int)('U') << 8) | ((int)('1') << 16) | ((int)('1') << 24)),
- YVU411 = ((int)('Y') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('1') << 24)),
- YUV420 = ((int)('Y') | ((int)('U') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- YVU420 = ((int)('Y') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- YUV422 = ((int)('Y') | ((int)('U') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- YVU422 = ((int)('Y') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- YUV444 = ((int)('Y') | ((int)('U') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- YVU444 = ((int)('Y') | ((int)('V') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- }
-
- [Flags]public enum SurfaceFlags : uint
- {
- Scanout = (1 << 0),
- Cursor64x64 = (1 << 1),
- Rendering = (1 << 2),
- Write = (1 << 3),
- Linear = (1 << 4),
- }
- [Flags]public enum TransferFlags : uint {
- /// <summary> Buffer contents read back (or accessed directly) at transfer create time.</summary>
- Read = 1 << 0,
- /// <summary> Buffer contents will be written back at unmap time (or modified as a result of being accessed directly).</summary>
- Write = 1 << 1,
- /// <summary>Read/modify/write</summary>
- ReadWrite = Read | Write,
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public struct gbm_bo {
- IntPtr device;
- public uint Width, Height;
- public SurfaceFormat Format;
- public SurfaceFlags Flags;
-
- public uint Handle32
- {
- get { return (uint)Gbm.BOGetHandle(ref this); }
- }
- public uint Stride
- {
- get { return Gbm.BOGetStride(ref this); }
- }
- public void SetUserData(IntPtr data, IntPtr destroyFB)
- {
- Gbm.BOSetUserData(ref this, data, destroyFB);
- }
- }
-// [StructLayout(LayoutKind.Sequential)]
-// public struct BufferObject : IEquatable<BufferObject>
-// {
-// IntPtr buffer;
-//
-// public static readonly BufferObject Zero =
-// default(BufferObject);
-//
-// public int Write(byte[] data)
-// {
-// unsafe
-// {
-// fixed (byte* pdata = data)
-// {
-// return Gbm.BOWrite(buffer, (IntPtr)pdata, (IntPtr)data.Length);
-// }
-// }
-// }
-//
-// public void SetUserData(IntPtr data, IntPtr destroyFB)
-// {
-// Gbm.BOSetUserData(buffer, data, destroyFB);
-// }
-//
-// public Device Device
-// {
-// get { return Gbm.BOGetDevice(buffer); }
-// }
-//
-// public int Handle
-// {
-// get { return Gbm.BOGetHandle(buffer).ToInt32(); }
-// }
-//
-// public int Width
-// {
-// get { return Gbm.BOGetWidth(buffer); }
-// }
-//
-// public int Height
-// {
-// get { return Gbm.BOGetHeight(buffer); }
-// }
-//
-// public int Stride
-// {
-// get { return Gbm.BOGetStride(buffer); }
-// }
-//
-// public void Dispose()
-// {
-// Gbm.DestroyBuffer(this);
-// buffer = IntPtr.Zero;
-// }
-//
-// public static bool operator ==(BufferObject left, BufferObject right)
-// {
-// return left.Equals(right);
-// }
-//
-// public static bool operator !=(BufferObject left, BufferObject right)
-// {
-// return !left.Equals(right);
-// }
-//
-// public override bool Equals(object obj)
-// {
-// return
-// obj is BufferObject &&
-// this.Equals((BufferObject)obj);
-// }
-//
-// public override int GetHashCode()
-// {
-// return buffer.GetHashCode();
-// }
-//
-// public override string ToString()
-// {
-// return string.Format("[BufferObject: {0}]", buffer);
-// }
-//
-// #region IEquatable implementation
-//
-// public bool Equals(BufferObject other)
-// {
-// return buffer == other.buffer;
-// }
-//
-// #endregion
-// }
-}
-
+++ /dev/null
-#region License
-//
-// Kms.cs
-//
-// Author:
-// Stefanos A. <stapostol@gmail.com>
-//
-// Copyright (c) 2006-2014
-//
-// 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 Kms
- {
- const string lib = "libkms";
-
- [DllImport(lib, EntryPoint = "kms_bo_map", CallingConvention = CallingConvention.Cdecl)]
- public static extern int MapBuffer(IntPtr bo, out IntPtr @out);
-
- [DllImport(lib, EntryPoint = "kms_bo_unmap", CallingConvention = CallingConvention.Cdecl)]
- public static extern int UnmapBuffer(IntPtr bo);
- }
-}
-
+++ /dev/null
-#region License
-//
-// Terminal.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 Terminal
- {
- const string lib = "libc";
-
- [DllImport(lib, EntryPoint = "isatty", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.I4)]
- public static extern bool IsTerminal(int fd);
-
- [DllImport(lib, EntryPoint = "tcgetattr", CallingConvention = CallingConvention.Cdecl)]
- public static extern int GetAttributes(int fd, out TerminalState state);
-
- [DllImport(lib, EntryPoint = "tcsetattr", CallingConvention = CallingConvention.Cdecl)]
- public static extern int SetAttributes(int fd, OptionalActions actions, ref TerminalState state);
- }
-
- [Flags]
- enum InputFlags
- {
- IGNBRK = 1 << 0,
- BRKINT = 1 << 1,
- IGNPAR = 1 << 2,
- PARMRK = 1 << 3,
- INPCK = 1 << 4,
- ISTRIP = 1 << 5,
- INLCR = 1 << 6,
- IGNCR = 1 << 7,
- ICRNL = 1 << 8,
- IUCLC = 1 << 9,
- IXON = 1 << 10,
- IXANY = 1 << 11,
- IXOFF = 1 << 12,
- IMAXBEL = 1 << 13,
- IUTF8 = 1 << 14,
- }
-
- [Flags]
- enum OutputFlags
- {
- OPOST = 1 << 1,
- OLCUC = 1 << 2,
- ONLCR = 1 << 3,
- OCRNL = 1 << 4,
- ONOCR = 1 << 5,
- ONLRET = 1 << 6,
- OFILL = 1 << 7,
- OFDEL = 1 << 8,
- }
-
- [Flags]
- enum ControlFlags
- {
- B0 = 0, // hang up
- B50,
- B75,
- B110,
- B134,
- B150,
- B200,
- B300,
- B600,
- B1200,
- B1800,
- B2400,
- B4800,
- B9600,
- B19200,
- B38400,
- }
-
- [Flags]
- enum LocalFlags
- {
- ISIG = 0x01,
- ICANON = 0x02,
- ECHO = 0x08,
- }
-
- enum OptionalActions
- {
- NOW = 0,
- DRAIN = 1,
- FLUSH = 2
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct TerminalState
- {
- public InputFlags InputMode;
- public OutputFlags OutputMode;
- public ControlFlags ControlMode;
- public LocalFlags LocalMode;
- public byte LineDiscipline;
- public ControlCharacters ControlCharacters;
- public int InputSpeed;
- public int OutputSpeed;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct ControlCharacters
- {
- public byte VINTR;
- public byte VQUIT;
- public byte VERASE;
- public byte VKILL;
- public byte VEOF;
- public byte VTIME;
- public byte VMIN;
- public byte VSWTC;
- public byte VSTART;
- public byte VSTOP;
- public byte VSUSP;
- public byte VEOL;
- public byte VREPRINT;
- public byte VDISCARD;
- public byte VWERASE;
- public byte VLNEXT;
- public byte VEOL2;
- public byte C17;
- public byte C18;
- public byte C19;
- public byte C20;
- public byte C21;
- public byte C22;
- public byte C23;
- public byte C24;
- public byte C25;
- public byte C26;
- public byte C27;
- public byte C28;
- public byte C29;
- public byte C30;
- public byte C31;
-
- }
-}
-
using System;
using System.Runtime.InteropServices;
-namespace OpenTK.Platform.Linux
+namespace Linux
{
class Udev
{
+++ /dev/null
-//
-// Connector.cs
-//
-// Author:
-// Stefanos Apostolopoulos <stapostol@gmail.com>
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2006-2014 Stefanos Apostolopoulos
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.DRI
-{
- #region Enums
- public enum ConnectionStatus
- {
- Connected = 1,
- Disconnected = 2,
- Unknown = 3
- }
- public enum ConnectorType
- {
- Unknown = 0,
- VGA=1,
- DVII=2,
- DVID=3,
- DVIA=4,
- Composite=5,
- SVIDEO=6,
- LVDS=7,
- Component=8,
- PinDIN9 = 9,
- DisplayPort=10,
- HDMIA=11,
- HDMIB=12,
- TV=13,
- eDP=14,
- VIRTUAL=15,
- DSI=16,
- DPI=17
- }
- public enum SubPixel
- {
- Unknown = 1,
- HorizontalRgb = 2,
- HorizontalBgr = 3,
- VerticalRgb = 4,
- VerticalBgr = 5,
- None = 6
- }
- #endregion
-
- [StructLayout(LayoutKind.Sequential)]
- unsafe internal struct drmConnector
- {
- public uint connector_id;
- public uint encoder_id;
- public ConnectorType connector_type;
- public uint connector_type_id;
- public ConnectionStatus connection;
- public uint mmWidth, mmHeight;
- public SubPixel subpixel;
-
- public int count_modes;
- public ModeInfo* modes;
-
- public int count_props;
- public uint *props;
- public ulong *prop_values;
-
- public int count_encoders;
- public uint *encoders;
- }
- [StructLayout(LayoutKind.Sequential)]
- unsafe public struct ModeInfo
- {
- public uint clock;
- public ushort hdisplay, hsync_start, hsync_end, htotal, hskew;
- public ushort vdisplay, vsync_start, vsync_end, vtotal, vscan;
-
- public int vrefresh; // refresh rate * 1000
-
- public uint flags;
- public uint type;
- public fixed sbyte name[32];
-
- public string Name {
- get {
- fixed( sbyte* bytes = name)
- return new string (bytes);
- }
- }
-
- public override string ToString ()
- {
- return string.Format ("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}",
- Name, clock, hdisplay, hsync_start, hsync_end, htotal, hskew,
- vdisplay, vsync_start, vsync_end, vtotal, vscan, vrefresh);
- }
- }
-
- unsafe public class Connector : IDisposable
- {
- #region pinvoke
- [DllImport("libdrm", EntryPoint = "drmModeGetConnector", CallingConvention = CallingConvention.Cdecl)]
- internal static extern drmConnector* ModeGetConnector(int fd, uint connector_id);
- [DllImport("libdrm", EntryPoint = "drmModeFreeConnector", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void ModeFreeConnector(drmConnector* ptr);
- #endregion
-
- int fd_gpu;
- internal drmConnector* handle;
-
- #region ctor
- public Connector (int _fd_gpu, uint _id)
- {
- fd_gpu = _fd_gpu;
- handle = ModeGetConnector (fd_gpu, _id);
-
- if (handle == null)
- throw new NotSupportedException("[DRI] drmModeGetConnector failed.");
- }
- #endregion
-
- public uint Id { get { return handle->connector_id; }}
- public ConnectionStatus State { get { return handle->connection; }}
- public ConnectorType Type { get { return handle->connector_type; }}
- public SubPixel SubPixel { get { return handle->subpixel; }}
-
- public Encoder CurrentEncoder {
- get {
- return handle->encoder_id == 0 ? null : new Encoder (fd_gpu, handle->encoder_id);
- }
- }
-
- public ModeInfo[] Modes {
- get {
- ModeInfo[] tmp = new ModeInfo[handle->count_modes];
- for (int i = 0; i < handle->count_modes; i++) {
- ModeInfo m = *(handle->modes + i);
- tmp [i] = m;
- }
- return tmp;
- }
- }
-
- #region IDisposable implementation
- ~Connector(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- unsafe {
- if (handle != null)
- ModeFreeConnector (handle);
- handle = null;
- }
- }
- #endregion
-
- public override string ToString ()
- {
- return string.Format ("Connector: Id={0}, State={1}, Type={2}, SubPixel={3}", Id, State, Type, SubPixel);
- }
- }
-}
-
+++ /dev/null
-//
-// Crtc.cs
-//
-// Author:
-// Stefanos Apostolopoulos <stapostol@gmail.com>
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2006-2014 Stefanos Apostolopoulos
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.DRI
-{
- [StructLayout(LayoutKind.Sequential)]
- internal struct drmCrtc
- {
- public uint crtc_id;
- public uint buffer_id;
-
- public uint x, y;
- public uint width, height;
- public int mode_valid;
- public ModeInfo mode;
-
- public int gamma_size;
- }
-
- unsafe public class Crtc : IDisposable
- {
- #region pinvoke
- [DllImport("libdrm", EntryPoint = "drmModeGetCrtc", CallingConvention = CallingConvention.Cdecl)]
- internal static extern drmCrtc* ModeGetCrtc(int fd, uint crtcId);
- [DllImport("libdrm", EntryPoint = "drmModeFreeCrtc", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void ModeFreeCrtc(drmCrtc* ptr);
- #endregion
-
- int fd_gpu;
- internal drmCrtc* handle;
-
- #region ctor
- internal Crtc (int _fd_gpu, uint _id)
- {
- fd_gpu = _fd_gpu;
- handle = ModeGetCrtc (fd_gpu, _id);
-
- if (handle == null)
- throw new NotSupportedException("[DRI] drmModeGetCrtc failed.");
- }
- #endregion
-
- public uint Id { get { return handle->crtc_id; }}
- public ModeInfo CurrentMode { get { return handle->mode; }}
- public uint CurrentFbId { get { return handle->buffer_id; }}
- public bool ModeIsValid { get { return handle->mode_valid == 0 ? false : true; }}
- public uint X { get { return handle->x; }}
- public uint Y { get { return handle->x; }}
- public uint Height { get { return handle->height; }}
- public uint Width { get { return handle->width; }}
- public int GammaSize { get { return handle->gamma_size; }}
-
- #region IDisposable implementation
- ~Crtc(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- unsafe {
- if (handle != null)
- ModeFreeCrtc (handle);
- handle = null;
- }
- }
- #endregion
-
- public override string ToString ()
- {
- return string.Format ("[Crtc: Id={0}, CurrentMode={1}, CurrentFbId={2}, ModeIsValid={3}, X={4}, Y={5}, Height={6}, Width={7}, GammaSize={8}]", Id, CurrentMode, CurrentFbId, ModeIsValid, X, Y, Height, Width, GammaSize);
- }
- }
-}
-
+++ /dev/null
-//
-// DRM.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Threading;
-
-namespace Linux.DRI {
- #region DRM callback signatures
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void VBlankCallback(int fd, int sequence, int tv_sec, int tv_usec, IntPtr user_data);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void PageFlipCallback(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data);
- #endregion
-
- #region DRM enums
- public enum EncoderType : uint
- {
- NONE=0,
- DAC=1,
- TMDS=2,
- LVDS=3,
- TVDAC=4,
- VIRTUAL=5,
- DSI=6,
- DPMST=7,
- DPI=8,
- }
- [Flags]public enum PageFlipFlags : uint
- {
- FlipEvent = 0x01,
- FlipAsync = 0x02,
- FlipFlags = FlipEvent | FlipAsync
- }
- /// <summary>Video mode flags, bit compatible with the xorg definitions. </summary>
- [Flags]public enum VideoMode
- {
- PHSYNC = 0x01,
- NHSYNC = 0x02,
- PVSYNC = 0x04,
- NVSYNC = 0x08,
- INTERLACE = 0x10,
- DBLSCAN = 0x20,
- CSYNC = 0x40,
- PCSYNC = 0x80,
- NCSYNC = 0x10,
- HSKEW = 0x0200,
- BCAST = 0x0400,
- PIXMUX = 0x0800,
- DBLCLK = 0x1000,
- CLKDIV2 = 0x2000,
- // FLAG_3D_MASK (0x1f<<14)
- // FLAG_3D_NONE = 0x0;
- // FLAG_3D_FRAME_PACKING = 0x4000,
- // FLAG_3D_FIELD_ALTERNATIVE = 0x8000,
- // FLAG_3D_LINE_ALTERNATIVE (3<<14)
- // FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
- // FLAG_3D_L_DEPTH (5<<14)
- // FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
- // FLAG_3D_TOP_AND_BOTTOM (7<<14)
- // FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
- }
- #endregion
-
- #region DRM structs
- [StructLayout(LayoutKind.Sequential)]
- public struct EventContext
- {
- public int version;
- public IntPtr vblank_handler;
- public IntPtr page_flip_handler;
- public static readonly int Version = 2;
- }
- [StructLayout(LayoutKind.Sequential)]
- unsafe public struct drmFrameBuffer {
- public uint fb_id;
- public uint width, height;
- public uint pitch;
- public uint bpp;
- public uint depth;
- /* driver specific handle */
- public uint handle;
- }
- [StructLayout(LayoutKind.Sequential)]
- struct drmClip {
- public ushort x1;
- public ushort y1;
- public ushort x2;
- public ushort y2;
- }
- #endregion
-
- public class DRIControler : IDisposable {
- #region PINVOKE
- const string lib = "libdrm";
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmHandleEvent(int fd, ref EventContext evctx);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeAddFB(int fd, uint width, uint height, byte depth, byte bpp,
- uint stride, uint bo_handle, out uint buf_id);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeRmFB(int fd, uint bufferId);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeDirtyFB(int fd, uint bufferId, IntPtr clips, uint num_clips);
- [DllImport(lib,CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern drmFrameBuffer* drmModeGetFB(int fd, uint fb_id);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern void drmModeFreeFB(drmFrameBuffer* ptr);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- static extern int drmModePageFlip(int fd, uint crtc_id, uint fb_id, PageFlipFlags flags, ref int user_data);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- unsafe static extern int drmModeSetCrtc(int fd, uint crtcId, uint bufferId, uint x, uint y, uint* connectors, int count, ref ModeInfo mode);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeSetCursor2(int fd, uint crtcId, uint bo_handle, uint width, uint height, int hot_x, int hot_y);
- [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int drmModeMoveCursor(int fd, uint crtcId, uint x, uint y);
- #endregion
-
- int fd_gpu = -1;
- GBM.Device gbmDev;
- GBM.Surface gbmSurf;
- public EGL.Context eglctx;
- EGL.Surface eglSurf;
-
- Cairo.EGLDevice cairoDev;
- public Cairo.GLSurface CairoSurf;
-
- Resources resources = null;
- Connector connector = null;
- Crtc currentCrtc = null;
- ModeInfo currentMode, originalMode;
- uint originalFB;
-
- byte bpp = 32;
- byte depth = 24;
-
- public volatile int FlipPollingSleep = 1;
-
- #region CTOR
- public DRIControler(string gpu_path = "/dev/dri/card0"){
- fd_gpu = Libc.open(gpu_path, OpenFlags.ReadWrite | OpenFlags.CloseOnExec);
- if (fd_gpu < 0)
- throw new NotSupportedException("[DRI] Failed to open gpu");
-
- resources = new Resources (fd_gpu);
- gbmDev = new GBM.Device (fd_gpu);
- eglctx = new EGL.Context (gbmDev);
-
- try {
- if (defaultConfiguration ())
- Console.WriteLine ("default config ok");
- } catch (Exception ex) {
- Console.WriteLine (ex.ToString());
- }
- }
- #endregion
-
- public int Width { get { return (int)currentMode.hdisplay; }}
- public int Height { get { return (int)currentMode.vdisplay; }}
-
- bool defaultConfiguration (){
- //select the first connected connector
- foreach (Connector c in resources.Connectors) {
- if (c.State == ConnectionStatus.Connected) {
- connector = c;
- break;
- }
- }
- if (connector == null)
- return false;
-
- currentCrtc = connector.CurrentEncoder.CurrentCrtc;
- originalMode = currentCrtc.CurrentMode;
- originalFB = currentCrtc.CurrentFbId;
- //currentMode = originalMode;
- currentMode = getNewMode();
-
- //configure a rendering stack
- gbmSurf = new GBM.Surface (gbmDev, Width, Height,
- GBM.SurfaceFlags.Rendering | GBM.SurfaceFlags.Scanout);
-
- eglSurf = new EGL.Surface (eglctx, gbmSurf);
- eglSurf.MakeCurrent ();
-
- cairoDev = new Cairo.EGLDevice (eglctx.dpy, eglctx.ctx);
-
- CairoSurf = new Cairo.GLSurface (cairoDev, eglSurf.handle, Width, Height);
- //cairoSurf = new Cairo.EGLSurface (cairoDev, egl_surface, 1600, 900);
-
- cairoDev.SetThreadAware (true);
-
- if (cairoDev.Acquire () != Cairo.Status.Success)
- Console.WriteLine ("[Cairo]: Failed to acquire egl device.");
-
-// using (Cairo.Context ctx = new Cairo.Context (CairoSurf)) {
-// ctx.Rectangle (0, 0, Width, Height);
-// ctx.SetSourceRGB (0, 0, 1);
-// ctx.Fill ();
-// }
- //CairoSurf.Flush ();
- //CairoSurf.SwapBuffers ();
- //Update ();
- //setScanOutRegion();
- //Thread.Sleep (100);
-
- initPageFlipUpdate ();
- return true;
- }
-
- void handleDestroyFB(ref GBM.gbm_bo bo, ref uint data)
- {
- uint fb = data;
-
- if (fb != 0) {
- if (drmModeRmFB (fd_gpu, fb) != 0)
- Console.WriteLine ("DestroyFB failed");
-
- data = 0;
- }
- }
-
- unsafe GBM.gbm_bo* bo;
- uint fb;
-
- unsafe public void Update(){
- int ret = 0;
- if (!gbmSurf.HasFreeBuffers)
- throw new NotSupportedException("[GBM] Out of free buffer");
- bo = gbmSurf.Lock ();
-
- if (fb == 0) {
- ret = drmModeAddFB (fd_gpu, currentMode.hdisplay, currentMode.vdisplay, (byte)depth, (byte)bpp, bo->Stride, (uint)bo->Handle32, out fb);
- if (ret != 0)
- Console.WriteLine ("addFb failed: {0}", ret);
- }
- uint connId = connector.Id;
- ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, fb, 0, 0, &connId, 1, ref currentMode);
- if (ret != 0)
- Console.WriteLine ("setCrtc failed: {0}", ret);
- gbmSurf.Release (bo);
- }
-
- static void HandlePageFlip(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data)
- {
- user_data = 0;
- }
-
- PollFD fds;
- EventContext evctx;
- static IntPtr PageFlipPtr = Marshal.GetFunctionPointerForDelegate((PageFlipCallback)HandlePageFlip);
- public void initPageFlipUpdate (){
- fds = new PollFD();
- fds.fd = fd_gpu;
- fds.events = PollFlags.In;
-
- evctx = new EventContext();
- evctx.version = EventContext.Version;
- evctx.page_flip_handler = Marshal.GetFunctionPointerForDelegate((PageFlipCallback)HandlePageFlip);
- }
- unsafe public void UpdateWithPageFlip(){
- GBM.gbm_bo* next_bo;
- uint fb;
-
- int timeout = -1;//block ? -1 : 0;
-
- if (!gbmSurf.HasFreeBuffers)
- throw new NotSupportedException("[GBM] Out of free buffer");
-
- next_bo = gbmSurf.Lock ();
-
- int ret = drmModeAddFB (fd_gpu, currentMode.hdisplay, currentMode.vdisplay, (byte)depth, (byte)bpp, next_bo->Stride, (uint)next_bo->Handle32, out fb);
- if (ret != 0)
- Console.WriteLine ("addFb failed: {0}", ret);
- next_bo->SetUserData (ref fb, handleDestroyFB);
-
- if (bo == null) {
- uint connId = connector.Id;
- ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, fb, 0, 0, &connId, 1, ref currentMode);
- if (ret != 0)
- Console.WriteLine ("setCrtc failed: {0}", ret);
- bo = next_bo;
- } else {
-
- int is_flip_queued = 1;
-
- while (drmModePageFlip (fd_gpu, currentCrtc.Id, fb, PageFlipFlags.FlipEvent, ref is_flip_queued) < 0) {
- //Console.WriteLine ("[DRM] Failed to enqueue framebuffer flip.");
- Thread.Sleep (1);
- }
-
- while (is_flip_queued != 0) {
- fds.revents = 0;
- if (Libc.poll (ref fds, 1, timeout) < 0)
- break;
- if ((fds.revents & (PollFlags.Hup | PollFlags.Error)) != 0)
- break;
- if ((fds.revents & PollFlags.In) != 0)
- drmHandleEvent (fd_gpu, ref evctx);
- else
- break;
- Thread.Sleep (FlipPollingSleep);
- }
- if (is_flip_queued != 0)
- Console.WriteLine ("flip canceled");
-
- gbmSurf.Release (bo);
- bo = next_bo;
- }
- }
-
- #region cursor
- GBM.BufferObject boMouseCursor;
-
- internal void updateCursor (Crow.XCursor cursor) {
- uint width = 64, height = 64;
- if (cursor.Width > width || cursor.Height > height){
- Debug.Print("[DRM] Cursor size {0}x{1} unsupported. Maximum is 64x64.",
- cursor.Width, cursor.Height);
- return;
- }
- boMouseCursor = new GBM.BufferObject (gbmDev, width, height, GBM.SurfaceFormat.ARGB8888,
- GBM.SurfaceFlags.Cursor64x64 | GBM.SurfaceFlags.Write);
-
- // Copy cursor.Data into a new buffer of the correct size
- byte[] cursor_data = new byte[width * height * 4];
- for (uint y = 0; y < cursor.Height; y++)
- {
- uint dst_offset = y * width * 4;
- uint src_offset = y * cursor.Width * 4;
- uint src_length = cursor.Width * 4;
- Array.Copy(
- cursor.data, src_offset,
- cursor_data, dst_offset,
- src_length);
- }
-
- boMouseCursor.Data = cursor_data;
- uint crtcid = currentCrtc.Id;
-
- unsafe {
- drmModeSetCursor2 (fd_gpu, crtcid,
- (uint)boMouseCursor.handle->Handle32, width, height, (int)cursor.Xhot, (int)cursor.Yhot);
- //drmModeMoveCursor (fd_gpu, crtcid, 0, 0);
- }
- }
- internal void moveCursor (uint x, uint y){
- drmModeMoveCursor (fd_gpu, currentCrtc.Id, x, y);
- }
- #endregion
-
- ModeInfo getNewMode(){
- ModeInfo mode = currentCrtc.CurrentMode;
- mode.clock = 118250;
- mode.hdisplay = 1600;
- mode.hsync_start = 1696;
- mode.hsync_end = 1856;
- mode.htotal = 2112;
- mode.vdisplay = 900;
- mode.vsync_start = 903;
- mode.vsync_end = 908;
- mode.vtotal = 934;
- mode.flags |= (uint)VideoMode.NHSYNC;
- mode.flags |= (uint)VideoMode.PVSYNC;
- return mode;
- }
-
-
-// unsafe public drmPlane GetPlane (uint id) {
-// drmPlane p = new drmPlane();
-// drmPlane* pPlane = ModeGetPlane (fd_gpu, id);
-// if (pPlane != null) {
-// p = *pPlane;
-// ModeFreePlane (pPlane);
-// }
-// return p;
-// }
-// public void SetPlane (drmPlane p, uint flags, uint crtc_w, uint crtc_h, uint src_w, uint src_h) {
-// ModeSetPlane (fd_gpu, p.plane_id, p.crtc_id, p.fb_id, flags,
-// (int)p.crtc_x, (int)p.crtc_y,
-// crtc_w, crtc_h,
-// p.x, p.y,
-// src_w, src_h);
-//
-//
-// }
-
- #region IDisposable implementation
- ~DRIControler(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- bool disposed = false;
- protected virtual void Dispose (bool disposing){
- if (disposed)
- return;
- unsafe{
- if (bo != null)
- gbmSurf.Release (bo);
- }
- if (fb != 0)
- if (drmModeRmFB (fd_gpu, fb) != 0)
- Console.WriteLine ("DestroyFB failed");
- if (eglctx != null)
- eglctx.ResetMakeCurrent ();
- if (cairoDev != null) {
- cairoDev.Release ();
- CairoSurf.Dispose ();
- cairoDev.Dispose ();
- cairoDev = null;
- CairoSurf = null;
- }
-
- if (boMouseCursor != null) {
- drmModeSetCursor2 (fd_gpu, currentCrtc.Id, 0u, 0, 0, 0, 0);
- boMouseCursor.Dispose ();
- }
- boMouseCursor = null;
- if (connector != null) {
- uint connId = connector.Id;
- unsafe {
- int ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, originalFB, 0, 0, &connId, 1, ref originalMode);
- if (ret != 0)
- Console.WriteLine ("restore Crtc failed: {0}", ret);
- }
- }
- if (eglctx != null) {
- eglctx.ResetMakeCurrent ();
- if (eglSurf != null)
- eglSurf.Dispose ();
- eglSurf = null;
- if (eglctx != null)
- eglctx.Dispose ();
- eglctx = null;
- }
-
- if (gbmSurf != null)
- gbmSurf.Dispose ();
- if (gbmDev != null)
- gbmDev.Dispose ();
- if (currentCrtc != null)
- currentCrtc.Dispose ();
- if (connector != null)
- connector.Dispose ();
- if (resources != null)
- resources.Dispose ();
- resources = null;
- if (fd_gpu > 0)
- Libc.close (fd_gpu);
- fd_gpu = -1;
- disposed = true;
- Console.WriteLine ("GPU controler disposed");
- }
- #endregion
- }
-}
\ No newline at end of file
+++ /dev/null
-//
-// Encoder.cs
-//
-// Author:
-// Stefanos Apostolopoulos <stapostol@gmail.com>
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2006-2014 Stefanos Apostolopoulos
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.DRI
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct drmEncoder
- {
- public uint encoder_id;
- public EncoderType encoder_type;
- public uint crtc_id;
- public uint possible_crtcs;
- public uint possible_clones;
- }
-
- unsafe public class Encoder : IDisposable
- {
- #region pinvoke
- [DllImport("libdrm", EntryPoint = "drmModeGetEncoder", CallingConvention = CallingConvention.Cdecl)]
- internal static extern drmEncoder* ModeGetEncoder(int fd, uint encoder_id);
- [DllImport("libdrm", EntryPoint = "drmModeFreeEncoder", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void ModeFreeEncoder(drmEncoder* ptr);
- #endregion
-
- int fd_gpu;
- internal drmEncoder* handle;
-
- #region ctor
- unsafe internal Encoder (int _fd_gpu, uint _id)
- {
- fd_gpu = _fd_gpu;
- handle = ModeGetEncoder (fd_gpu, _id);
-
- if (handle == null)
- throw new NotSupportedException("[DRI] drmModeGetEncoder failed.");
- }
- #endregion
-
- public uint Id { get { return handle->encoder_id; }}
- public EncoderType Type { get { return handle->encoder_type; }}
- public uint PossibleCrtcs { get { return handle->possible_crtcs; }}
- public uint PossibleClones { get { return handle->possible_clones; }}
-
- public Crtc CurrentCrtc {
- get {
- return handle->crtc_id == 0 ? null : new Crtc (fd_gpu, handle->crtc_id);
- }
- }
-
- #region IDisposable implementation
- ~Encoder(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- unsafe {
- if (handle != null)
- ModeFreeEncoder (handle);
- handle = null;
- }
- }
- #endregion
-
- public override string ToString ()
- {
- return string.Format ("[Encoder: Id={0}, Type={1}, PossibleCrtcs={2}, PossibleClones={3}]", Id, Type, PossibleCrtcs, PossibleClones);
- }
- }
-}
-
+++ /dev/null
-//
-// Plane.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.DRI
-{
- public enum PlaneType {
- Overlay = 0,
- Primary = 1,
- Cursor = 2
- }
- [StructLayout(LayoutKind.Sequential)]
- unsafe public struct drmPlane {
- public uint count_formats;
- public uint *formats;
- public uint plane_id;
-
- public uint crtc_id;
- public uint fb_id;
-
- public uint crtc_x, crtc_y;
- public uint x, y;
-
- public uint possible_crtcs;
- public uint gamma_size;
- }
-
- unsafe public class Plane : IDisposable
- {
- #region pinvoke
- [DllImport("libdrm", CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern drmPlane* drmModeGetPlane(int fd, uint id);
- [DllImport("libdrm", CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern void drmModeFreePlane(drmPlane* ptr);
- [DllImport("libdrm", CallingConvention = CallingConvention.Cdecl)]
- unsafe static extern int drmModeSetPlane(int fd, uint plane_id, uint crtc_id,
- uint fb_id, uint flags,
- int crtc_x, int crtc_y,
- uint crtc_w, uint crtc_h,
- uint src_x, uint src_y,
- uint src_w, uint src_h);
-
- #endregion
-
- drmPlane* handle;
-
- internal Plane (drmPlane* _handle)
- {
- handle = _handle;
- }
-
- public uint Id { get { return handle->plane_id; }}
-
- #region IDisposable implementation
- ~Plane(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- unsafe {
- if (handle != null)
- drmModeFreePlane (handle);
- handle = null;
- }
- }
- #endregion
- }
-}
-
+++ /dev/null
-//
-// PlaneResources.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.DRI
-{
- [StructLayout(LayoutKind.Sequential)]
- unsafe internal struct drmPlaneRes {
- public uint count_planes;
- public uint *planes;
- }
-
- unsafe public class PlaneResources : IDisposable
- {
- #region pinvoke
- [DllImport("libdrm", CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern drmPlaneRes* drmModeGetPlaneResources(int fd);
- [DllImport("libdrm", CallingConvention = CallingConvention.Cdecl)]
- unsafe internal static extern void drmModeFreePlaneResources(drmPlaneRes* ptr);
- #endregion
-
- int gpu_fd;
- drmPlaneRes* handle;
-
- internal PlaneResources (int fd_gpu)
- {
- gpu_fd = fd_gpu;
- handle = drmModeGetPlaneResources (fd_gpu);
-
- if (handle == null)
- throw new NotSupportedException("[DRI] drmModeGetPlaneResources failed.");
- }
-
- #region IDisposable implementation
- ~PlaneResources(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- unsafe {
- if (handle != null)
- drmModeFreePlaneResources (handle);
- handle = null;
- }
- }
- #endregion
- }
-}
-
+++ /dev/null
-//
-// Resources.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.DRI
-{
- [StructLayout(LayoutKind.Sequential)]
- unsafe internal struct drmResources
- {
- public int count_fbs;
- public uint* fbs;
- public int count_crtcs;
- public uint* crtcs;
- public int count_connectors;
- public uint* connectors;
- public int count_encoders;
- public uint* encoders;
- public uint min_width, max_width;
- public uint min_height, max_height;
- }
-
- unsafe public class Resources: IDisposable
- {
- #region pinvoke
- [DllImport("libdrm", EntryPoint = "drmModeGetResources", CallingConvention = CallingConvention.Cdecl)]
- internal static extern drmResources* ModeGetResources(int fd);
- [DllImport("libdrm", EntryPoint = "drmModeFreeResources", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void ModeFreeResources(drmResources* ptr);
- #endregion
-
- int gpu_fd;
- drmResources* handle;
-
- #region ctor
- public Resources (int fd_gpu)
- {
- gpu_fd = fd_gpu;
- handle = ModeGetResources (fd_gpu);
-
- if (handle == null)
- throw new NotSupportedException("[DRI] drmModeGetResources failed.");
- }
- #endregion
-
- public uint min_width { get { return handle->min_width; }}
- public uint max_width { get { return handle->max_width; }}
- public uint min_height { get { return handle->min_height; }}
- public uint max_height { get { return handle->max_height; }}
-
- public Connector[] Connectors {
- get {
- Connector[] tmp = new Connector[handle->count_connectors];
- for (int i = 0; i < handle->count_connectors; i++)
- tmp [i] = new Connector (gpu_fd, *(handle->connectors + i));
- return tmp;
- }
- }
- public Encoder[] Encoders {
- get {
- Encoder[] tmp = new Encoder[handle->count_encoders];
- for (int i = 0; i < handle->count_encoders; i++)
- tmp [i] = new Encoder (gpu_fd, *(handle->encoders + i));
- return tmp;
- }
- }
- public Crtc[] Crtcs {
- get {
- Crtc[] tmp = new Crtc[handle->count_encoders];
- for (int i = 0; i < handle->count_crtcs; i++)
- tmp [i] = new Crtc (gpu_fd, *(handle->crtcs + i));
- return tmp;
- }
- }
-
- #region IDisposable implementation
- ~Resources(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (handle != null)
- ModeFreeResources (handle);
- handle = null;
- }
- #endregion
-
- }
-}
-
--- /dev/null
+//
+// DRM.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2013-2017 Jean-Philippe Bruyère
+//
+// 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.
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Threading;
+using DRI.DRM;
+using GBM = DRI.GBM;
+
+namespace Linux.DRI {
+ #region DRM callback signatures
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate void VBlankCallback(int fd, int sequence, int tv_sec, int tv_usec, IntPtr user_data);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate void PageFlipCallback(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data);
+ #endregion
+
+ #region DRM enums
+ public enum EncoderType : uint
+ {
+ NONE=0,
+ DAC=1,
+ TMDS=2,
+ LVDS=3,
+ TVDAC=4,
+ VIRTUAL=5,
+ DSI=6,
+ DPMST=7,
+ DPI=8,
+ }
+ [Flags]public enum PageFlipFlags : uint
+ {
+ FlipEvent = 0x01,
+ FlipAsync = 0x02,
+ FlipFlags = FlipEvent | FlipAsync
+ }
+ /// <summary>Video mode flags, bit compatible with the xorg definitions. </summary>
+ [Flags]public enum VideoMode
+ {
+ PHSYNC = 0x01,
+ NHSYNC = 0x02,
+ PVSYNC = 0x04,
+ NVSYNC = 0x08,
+ INTERLACE = 0x10,
+ DBLSCAN = 0x20,
+ CSYNC = 0x40,
+ PCSYNC = 0x80,
+ NCSYNC = 0x10,
+ HSKEW = 0x0200,
+ BCAST = 0x0400,
+ PIXMUX = 0x0800,
+ DBLCLK = 0x1000,
+ CLKDIV2 = 0x2000,
+ // FLAG_3D_MASK (0x1f<<14)
+ // FLAG_3D_NONE = 0x0;
+ // FLAG_3D_FRAME_PACKING = 0x4000,
+ // FLAG_3D_FIELD_ALTERNATIVE = 0x8000,
+ // FLAG_3D_LINE_ALTERNATIVE (3<<14)
+ // FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
+ // FLAG_3D_L_DEPTH (5<<14)
+ // FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
+ // FLAG_3D_TOP_AND_BOTTOM (7<<14)
+ // FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
+ }
+ #endregion
+
+ #region DRM structs
+ [StructLayout(LayoutKind.Sequential)]
+ public struct EventContext
+ {
+ public int version;
+ public IntPtr vblank_handler;
+ public IntPtr page_flip_handler;
+ public static readonly int Version = 2;
+ }
+ [StructLayout(LayoutKind.Sequential)]
+ unsafe public struct drmFrameBuffer {
+ public uint fb_id;
+ public uint width, height;
+ public uint pitch;
+ public uint bpp;
+ public uint depth;
+ /* driver specific handle */
+ public uint handle;
+ }
+ [StructLayout(LayoutKind.Sequential)]
+ struct drmClip {
+ public ushort x1;
+ public ushort y1;
+ public ushort x2;
+ public ushort y2;
+ }
+ #endregion
+
+ public class DRIControler : IDisposable {
+ #region PINVOKE
+ const string lib = "libdrm";
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int drmHandleEvent(int fd, ref EventContext evctx);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int drmModeAddFB(int fd, uint width, uint height, byte depth, byte bpp,
+ uint stride, uint bo_handle, out uint buf_id);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int drmModeRmFB(int fd, uint bufferId);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int drmModeDirtyFB(int fd, uint bufferId, IntPtr clips, uint num_clips);
+ [DllImport(lib,CallingConvention = CallingConvention.Cdecl)]
+ unsafe internal static extern drmFrameBuffer* drmModeGetFB(int fd, uint fb_id);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ unsafe internal static extern void drmModeFreeFB(drmFrameBuffer* ptr);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ static extern int drmModePageFlip(int fd, uint crtc_id, uint fb_id, PageFlipFlags flags, ref int user_data);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ unsafe static extern int drmModeSetCrtc(int fd, uint crtcId, uint bufferId, uint x, uint y, uint* connectors, int count, ref ModeInfo mode);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int drmModeSetCursor2(int fd, uint crtcId, uint bo_handle, uint width, uint height, int hot_x, int hot_y);
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int drmModeMoveCursor(int fd, uint crtcId, uint x, uint y);
+ #endregion
+
+ int fd_gpu = -1;
+ GBM.Device gbmDev;
+ GBM.Surface gbmSurf;
+ public EGL.Context eglctx;
+ EGL.Surface eglSurf;
+
+ Cairo.EGLDevice cairoDev;
+ public Cairo.GLSurface CairoSurf;
+
+ Resources resources = null;
+ Connector connector = null;
+ Crtc currentCrtc = null;
+ ModeInfo currentMode, originalMode;
+ uint originalFB;
+
+ byte bpp = 32;
+ byte depth = 24;
+
+ public volatile int FlipPollingSleep = 1;
+
+ #region CTOR
+ public DRIControler(string gpu_path = "/dev/dri/card0"){
+ fd_gpu = Libc.open(gpu_path, OpenFlags.ReadWrite | OpenFlags.CloseOnExec);
+ if (fd_gpu < 0)
+ throw new NotSupportedException("[DRI] Failed to open gpu");
+
+ resources = new Resources (fd_gpu);
+ gbmDev = new GBM.Device (fd_gpu);
+ eglctx = new EGL.Context (gbmDev);
+
+ try {
+ if (defaultConfiguration ())
+ Console.WriteLine ("default config ok");
+ } catch (Exception ex) {
+ Console.WriteLine (ex.ToString());
+ }
+ }
+ #endregion
+
+ public int Width { get { return (int)currentMode.hdisplay; }}
+ public int Height { get { return (int)currentMode.vdisplay; }}
+
+ bool defaultConfiguration (){
+ //select the first connected connector
+ foreach (Connector c in resources.Connectors) {
+ if (c.State == ConnectionStatus.Connected) {
+ connector = c;
+ break;
+ }
+ }
+ if (connector == null)
+ return false;
+
+ currentCrtc = connector.CurrentEncoder.CurrentCrtc;
+ originalMode = currentCrtc.CurrentMode;
+ originalFB = currentCrtc.CurrentFbId;
+ //currentMode = originalMode;
+ currentMode = getNewMode();
+
+ //configure a rendering stack
+ gbmSurf = new GBM.Surface (gbmDev, Width, Height,
+ GBM.SurfaceFlags.Rendering | GBM.SurfaceFlags.Scanout);
+
+ eglSurf = new EGL.Surface (eglctx, gbmSurf);
+ //eglSurf.MakeCurrent ();
+
+ cairoDev = new Cairo.EGLDevice (eglctx.dpy, eglctx.ctx);
+
+ CairoSurf = new Cairo.GLSurface (cairoDev, eglSurf.handle, Width, Height);
+ //cairoSurf = new Cairo.EGLSurface (cairoDev, egl_surface, 1600, 900);
+
+ cairoDev.SetThreadAware (true);
+
+ if (cairoDev.Acquire () != Cairo.Status.Success)
+ Console.WriteLine ("[Cairo]: Failed to acquire egl device.");
+
+// using (Cairo.Context ctx = new Cairo.Context (CairoSurf)) {
+// ctx.Rectangle (0, 0, Width, Height);
+// ctx.SetSourceRGB (0, 0, 1);
+// ctx.Fill ();
+// }
+ //CairoSurf.Flush ();
+ //CairoSurf.SwapBuffers ();
+ //Update ();
+ //setScanOutRegion();
+ //Thread.Sleep (100);
+
+ initPageFlipUpdate ();
+ return true;
+ }
+
+ void handleDestroyFB(ref GBM.gbm_bo bo, ref uint data)
+ {
+ uint fb = data;
+
+ if (fb != 0) {
+ if (drmModeRmFB (fd_gpu, fb) != 0)
+ Console.WriteLine ("DestroyFB failed");
+
+ data = 0;
+ }
+ }
+
+ unsafe GBM.gbm_bo* bo;
+ uint fb;
+
+ unsafe public void Update(){
+ int ret = 0;
+ if (!gbmSurf.HasFreeBuffers)
+ throw new NotSupportedException("[GBM] Out of free buffer");
+ bo = gbmSurf.Lock ();
+
+ if (fb == 0) {
+ ret = drmModeAddFB (fd_gpu, currentMode.hdisplay, currentMode.vdisplay, (byte)depth, (byte)bpp, bo->Stride, (uint)bo->Handle32, out fb);
+ if (ret != 0)
+ Console.WriteLine ("addFb failed: {0}", ret);
+ }
+ uint connId = connector.Id;
+ ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, fb, 0, 0, &connId, 1, ref currentMode);
+ if (ret != 0)
+ Console.WriteLine ("setCrtc failed: {0}", ret);
+ gbmSurf.Release (bo);
+ }
+
+ static void HandlePageFlip(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data)
+ {
+ user_data = 0;
+ }
+
+ PollFD fds;
+ EventContext evctx;
+ static IntPtr PageFlipPtr = Marshal.GetFunctionPointerForDelegate((PageFlipCallback)HandlePageFlip);
+ public void initPageFlipUpdate (){
+ fds = new PollFD();
+ fds.fd = fd_gpu;
+ fds.events = PollFlags.In;
+
+ evctx = new EventContext();
+ evctx.version = EventContext.Version;
+ evctx.page_flip_handler = Marshal.GetFunctionPointerForDelegate((PageFlipCallback)HandlePageFlip);
+ }
+ unsafe public void UpdateWithPageFlip(){
+ GBM.gbm_bo* next_bo;
+ uint fb;
+
+ int timeout = -1;//block ? -1 : 0;
+
+ if (!gbmSurf.HasFreeBuffers)
+ throw new NotSupportedException("[GBM] Out of free buffer");
+
+ next_bo = gbmSurf.Lock ();
+
+ int ret = drmModeAddFB (fd_gpu, currentMode.hdisplay, currentMode.vdisplay, (byte)depth, (byte)bpp, next_bo->Stride, (uint)next_bo->Handle32, out fb);
+ if (ret != 0)
+ Console.WriteLine ("addFb failed: {0}", ret);
+ next_bo->SetUserData (ref fb, handleDestroyFB);
+
+ if (bo == null) {
+ uint connId = connector.Id;
+ ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, fb, 0, 0, &connId, 1, ref currentMode);
+ if (ret != 0)
+ Console.WriteLine ("setCrtc failed: {0}", ret);
+ bo = next_bo;
+ } else {
+
+ int is_flip_queued = 1;
+
+ while (drmModePageFlip (fd_gpu, currentCrtc.Id, fb, PageFlipFlags.FlipEvent, ref is_flip_queued) < 0) {
+ //Console.WriteLine ("[DRM] Failed to enqueue framebuffer flip.");
+ Thread.Sleep (1);
+ }
+
+ while (is_flip_queued != 0) {
+ fds.revents = 0;
+ if (Libc.poll (ref fds, 1, timeout) < 0)
+ break;
+ if ((fds.revents & (PollFlags.Hup | PollFlags.Error)) != 0)
+ break;
+ if ((fds.revents & PollFlags.In) != 0)
+ drmHandleEvent (fd_gpu, ref evctx);
+ else
+ break;
+ Thread.Sleep (FlipPollingSleep);
+ }
+ if (is_flip_queued != 0)
+ Console.WriteLine ("flip canceled");
+
+ gbmSurf.Release (bo);
+ bo = next_bo;
+ }
+ }
+
+ #region cursor
+ GBM.BufferObject boMouseCursor;
+
+ internal void updateCursor (Crow.XCursor cursor) {
+ uint width = 64, height = 64;
+ if (cursor.Width > width || cursor.Height > height){
+ Debug.Print("[DRM] Cursor size {0}x{1} unsupported. Maximum is 64x64.",
+ cursor.Width, cursor.Height);
+ return;
+ }
+ boMouseCursor = new GBM.BufferObject (gbmDev, width, height, GBM.SurfaceFormat.ARGB8888,
+ GBM.SurfaceFlags.Cursor64x64 | GBM.SurfaceFlags.Write);
+
+ // Copy cursor.Data into a new buffer of the correct size
+ byte[] cursor_data = new byte[width * height * 4];
+ for (uint y = 0; y < cursor.Height; y++)
+ {
+ uint dst_offset = y * width * 4;
+ uint src_offset = y * cursor.Width * 4;
+ uint src_length = cursor.Width * 4;
+ Array.Copy(
+ cursor.data, src_offset,
+ cursor_data, dst_offset,
+ src_length);
+ }
+
+ boMouseCursor.Data = cursor_data;
+ uint crtcid = currentCrtc.Id;
+
+ unsafe {
+ drmModeSetCursor2 (fd_gpu, crtcid,
+ (uint)boMouseCursor.handle->Handle32, width, height, (int)cursor.Xhot, (int)cursor.Yhot);
+ //drmModeMoveCursor (fd_gpu, crtcid, 0, 0);
+ }
+ }
+ internal void moveCursor (uint x, uint y){
+ drmModeMoveCursor (fd_gpu, currentCrtc.Id, x, y);
+ }
+ #endregion
+
+ ModeInfo getNewMode(){
+ ModeInfo mode = currentCrtc.CurrentMode;
+ mode.clock = 118250;
+ mode.hdisplay = 1600;
+ mode.hsync_start = 1696;
+ mode.hsync_end = 1856;
+ mode.htotal = 2112;
+ mode.vdisplay = 900;
+ mode.vsync_start = 903;
+ mode.vsync_end = 908;
+ mode.vtotal = 934;
+ mode.flags |= (uint)VideoMode.NHSYNC;
+ mode.flags |= (uint)VideoMode.PVSYNC;
+ return mode;
+ }
+
+
+// unsafe public drmPlane GetPlane (uint id) {
+// drmPlane p = new drmPlane();
+// drmPlane* pPlane = ModeGetPlane (fd_gpu, id);
+// if (pPlane != null) {
+// p = *pPlane;
+// ModeFreePlane (pPlane);
+// }
+// return p;
+// }
+// public void SetPlane (drmPlane p, uint flags, uint crtc_w, uint crtc_h, uint src_w, uint src_h) {
+// ModeSetPlane (fd_gpu, p.plane_id, p.crtc_id, p.fb_id, flags,
+// (int)p.crtc_x, (int)p.crtc_y,
+// crtc_w, crtc_h,
+// p.x, p.y,
+// src_w, src_h);
+//
+//
+// }
+
+ #region IDisposable implementation
+ ~DRIControler(){
+ Dispose (false);
+ }
+ public void Dispose ()
+ {
+ Dispose (true);
+ GC.SuppressFinalize (this);
+ }
+ bool disposed = false;
+ protected virtual void Dispose (bool disposing){
+ if (disposed)
+ return;
+ unsafe{
+ if (bo != null)
+ gbmSurf.Release (bo);
+ }
+ if (fb != 0)
+ if (drmModeRmFB (fd_gpu, fb) != 0)
+ Console.WriteLine ("DestroyFB failed");
+
+ if (cairoDev != null) {
+ cairoDev.Release ();
+ CairoSurf.Dispose ();
+ cairoDev.Dispose ();
+ cairoDev = null;
+ CairoSurf = null;
+ }
+
+ if (boMouseCursor != null) {
+ drmModeSetCursor2 (fd_gpu, currentCrtc.Id, 0u, 0, 0, 0, 0);
+ boMouseCursor.Dispose ();
+ }
+ boMouseCursor = null;
+ if (connector != null) {
+ uint connId = connector.Id;
+ unsafe {
+ int ret = drmModeSetCrtc (fd_gpu, currentCrtc.Id, originalFB, 0, 0, &connId, 1, ref originalMode);
+ if (ret != 0)
+ Console.WriteLine ("restore Crtc failed: {0}", ret);
+ }
+ }
+ if (eglctx != null) {
+ eglctx.ResetMakeCurrent ();
+ if (eglSurf != null)
+ eglSurf.Dispose ();
+ eglSurf = null;
+ if (eglctx != null)
+ eglctx.Dispose ();
+ eglctx = null;
+ }
+
+ if (gbmSurf != null)
+ gbmSurf.Dispose ();
+ if (gbmDev != null)
+ gbmDev.Dispose ();
+ if (currentCrtc != null)
+ currentCrtc.Dispose ();
+ if (connector != null)
+ connector.Dispose ();
+ if (resources != null)
+ resources.Dispose ();
+ resources = null;
+ if (fd_gpu > 0)
+ Libc.close (fd_gpu);
+ fd_gpu = -1;
+ disposed = true;
+ Console.WriteLine ("GPU controler disposed");
+ }
+ #endregion
+ }
+}
\ No newline at end of file
+++ /dev/null
-//
-// Device.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.GBM
-{
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void DestroyUserDataCallback(ref GBM.gbm_bo bo, ref uint data);
-
- [StructLayout(LayoutKind.Sequential)]
- public struct gbm_bo {
- IntPtr device;
- public uint Width, Height;
- public SurfaceFormat Format;
- public SurfaceFlags Flags;
-
- public uint Handle32
- {
- get { return (uint)BufferObject.gbm_bo_get_handle(ref this); }
- }
- public uint Stride
- {
- get { return BufferObject.gbm_bo_get_stride(ref this); }
- }
- public void SetUserData(ref uint data, DestroyUserDataCallback destroyFB)
- {
- BufferObject.gbm_bo_set_user_data(ref this, ref data, destroyFB);
- }
- }
- unsafe public class BufferObject : IDisposable
- {
- #region pinvoke
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern gbm_bo* gbm_bo_create (IntPtr gbm, uint width, uint height, SurfaceFormat format, SurfaceFlags flags);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void gbm_bo_destroy (gbm_bo* bo);
- [DllImport("gbm", EntryPoint = "gbm_bo_destroy", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void destryBO (ref gbm_bo bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern int gbm_bo_write(gbm_bo* bo, IntPtr buf, IntPtr count);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern Device gbm_bo_get_device(ref gbm_bo bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong gbm_bo_get_handle(ref gbm_bo bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern int gbm_bo_get_height(ref gbm_bo bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern int gbm_bo_get_width(ref gbm_bo bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint gbm_bo_get_stride (ref gbm_bo bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void gbm_bo_set_user_data(ref gbm_bo bo, ref uint data, DestroyUserDataCallback callback);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr gbm_bo_get_user_data (IntPtr bo);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr gbm_bo_map (ref gbm_bo bo, uint x, uint y, uint width, uint height, TransferFlags flags, ref uint stride, out IntPtr data);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void gbm_bo_unmap (ref gbm_bo bo, IntPtr data);
- #endregion
-
- internal gbm_bo* handle;
-
- #region ctor
- public BufferObject (gbm_bo* _handle){
- handle = _handle;
- }
- public BufferObject (Device dev, uint _width, uint _height, SurfaceFormat format, SurfaceFlags flags)
- {
- handle = gbm_bo_create (dev.handle, _width, _height, format, flags);
- if (handle == null)
- throw new NotSupportedException("[GBM] BO creation failed.");
- }
- #endregion
-
- public uint Stride { get { return handle->Stride; }}
- public byte[] Data {
- set {
- fixed (byte* pdata = value) {
- gbm_bo_write (handle, (IntPtr)pdata, (IntPtr)value.Length);
- }
- }
- }
-
- #region IDisposable implementation
- ~BufferObject(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (handle != null)
- gbm_bo_destroy (handle);
- handle = null;
- }
- #endregion
- }
-}
-
+++ /dev/null
-//
-// Device.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.GBM
-{
- unsafe public class Device : IDisposable
- {
- #region pinvoke
- [DllImport("gbm", EntryPoint = "gbm_create_device", CallingConvention = CallingConvention.Cdecl)]
- static extern IntPtr CreateDevice(int fd);
- [DllImport("gbm", EntryPoint = "gbm_device_destroy", CallingConvention = CallingConvention.Cdecl)]
- static extern void DestroyDevice(IntPtr gbm);
- [DllImport("gbm", EntryPoint = "gbm_device_get_fd", CallingConvention = CallingConvention.Cdecl)]
- static extern int DeviceGetFD(IntPtr gbm);
- [DllImport("gbm", EntryPoint = "gbm_device_is_format_supported", CallingConvention = CallingConvention.Cdecl)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsFormatSupported(IntPtr gbm, SurfaceFormat format, SurfaceFlags usage);
- #endregion
-
- int fd_gpu;
- internal IntPtr handle;
-
- #region ctor
- public Device (int _fd_gpu)
- {
- fd_gpu = _fd_gpu;
- handle = CreateDevice(fd_gpu);
-
- if (handle == IntPtr.Zero)
- throw new NotSupportedException("[GBM] device creation failed.");
- }
- #endregion
-
- #region IDisposable implementation
- ~Device(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (handle != IntPtr.Zero)
- DestroyDevice (handle);
- handle = IntPtr.Zero;
- }
- #endregion
- }
-}
-
+++ /dev/null
-//
-// Surface.cs
-//
-// Author:
-// Stefanos Apostolopoulos <stapostol@gmail.com>
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2006-2014 Stefanos Apostolopoulos
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Linux.GBM
-{
- public enum SurfaceFormat : uint
- {
- BigEndian = 1u << 31,
- C8 = ((int)('C') | ((int)('8') << 8) | ((int)(' ') << 16) | ((int)(' ') << 24)),
-
- RGB332 = ((int)('R') | ((int)('G') << 8) | ((int)('B') << 16) | ((int)('8') << 24)),
- BGR233 = ((int)('B') | ((int)('G') << 8) | ((int)('R') << 16) | ((int)('8') << 24)),
-
- XRGB4444 = ((int)('X') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- XBGR4444 = ((int)('X') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- RGBX4444 = ((int)('R') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- BGRX4444 = ((int)('B') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
-
- ARGB4444 = ((int)('A') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- ABGR4444 = ((int)('A') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- RGBA4444 = ((int)('R') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- BGRA4444 = ((int)('B') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
-
- XRGB1555 = ((int)('X') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- XBGR1555 = ((int)('X') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- RGBX5551 = ((int)('R') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- BGRX5551 = ((int)('B') | ((int)('X') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
-
- ARGB1555 = ((int)('A') | ((int)('R') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- ABGR1555 = ((int)('A') | ((int)('B') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- RGBA5551 = ((int)('R') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
- BGRA5551 = ((int)('B') | ((int)('A') << 8) | ((int)('1') << 16) | ((int)('5') << 24)),
-
- RGB565 = ((int)('R') | ((int)('G') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- BGR565 = ((int)('B') | ((int)('G') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
-
- RGB888 = ((int)('R') | ((int)('G') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- BGR888 = ((int)('B') | ((int)('G') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
-
- XRGB8888 = ((int)('X') | ((int)('R') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- XBGR8888 = ((int)('X') | ((int)('B') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- RGBX8888 = ((int)('R') | ((int)('X') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- BGRX8888 = ((int)('B') | ((int)('X') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
-
- ARGB8888 = ((int)('A') | ((int)('R') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- ABGR8888 = ((int)('A') | ((int)('B') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- RGBA8888 = ((int)('R') | ((int)('A') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- BGRA8888 = ((int)('B') | ((int)('A') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
-
- XRGB2101010 = ((int)('X') | ((int)('R') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- XBGR2101010 = ((int)('X') | ((int)('B') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- RGBX1010102 = ((int)('R') | ((int)('X') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- BGRX1010102 = ((int)('B') | ((int)('X') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
-
- ARGB2101010 = ((int)('A') | ((int)('R') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- ABGR2101010 = ((int)('A') | ((int)('B') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- RGBA1010102 = ((int)('R') | ((int)('A') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
- BGRA1010102 = ((int)('B') | ((int)('A') << 8) | ((int)('3') << 16) | ((int)('0') << 24)),
-
- YUYV = ((int)('Y') | ((int)('U') << 8) | ((int)('Y') << 16) | ((int)('V') << 24)),
- YVYU = ((int)('Y') | ((int)('V') << 8) | ((int)('Y') << 16) | ((int)('U') << 24)),
- UYVY = ((int)('U') | ((int)('Y') << 8) | ((int)('V') << 16) | ((int)('Y') << 24)),
- VYUY = ((int)('V') | ((int)('Y') << 8) | ((int)('U') << 16) | ((int)('Y') << 24)),
-
- AYUV = ((int)('A') | ((int)('Y') << 8) | ((int)('U') << 16) | ((int)('V') << 24)),
-
- NV12 = ((int)('N') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- NV21 = ((int)('N') | ((int)('V') << 8) | ((int)('2') << 16) | ((int)('1') << 24)),
- NV16 = ((int)('N') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- NV61 = ((int)('N') | ((int)('V') << 8) | ((int)('6') << 16) | ((int)('1') << 24)),
-
- YUV410 = ((int)('Y') | ((int)('U') << 8) | ((int)('V') << 16) | ((int)('9') << 24)),
- YVU410 = ((int)('Y') | ((int)('V') << 8) | ((int)('U') << 16) | ((int)('9') << 24)),
- YUV411 = ((int)('Y') | ((int)('U') << 8) | ((int)('1') << 16) | ((int)('1') << 24)),
- YVU411 = ((int)('Y') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('1') << 24)),
- YUV420 = ((int)('Y') | ((int)('U') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- YVU420 = ((int)('Y') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('2') << 24)),
- YUV422 = ((int)('Y') | ((int)('U') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- YVU422 = ((int)('Y') | ((int)('V') << 8) | ((int)('1') << 16) | ((int)('6') << 24)),
- YUV444 = ((int)('Y') | ((int)('U') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- YVU444 = ((int)('Y') | ((int)('V') << 8) | ((int)('2') << 16) | ((int)('4') << 24)),
- }
- [Flags]public enum SurfaceFlags : uint
- {
- Scanout = (1 << 0),
- Cursor64x64 = (1 << 1),
- Rendering = (1 << 2),
- Write = (1 << 3),
- Linear = (1 << 4),
- }
- [Flags]public enum TransferFlags : uint {
- /// <summary> Buffer contents read back (or accessed directly) at transfer create time.</summary>
- Read = 1 << 0,
- /// <summary> Buffer contents will be written back at unmap time (or modified as a result of being accessed directly).</summary>
- Write = 1 << 1,
- /// <summary>Read/modify/write</summary>
- ReadWrite = Read | Write,
- }
-
- unsafe public class Surface : IDisposable
- {
- #region pinvoke
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- static extern IntPtr gbm_surface_create (IntPtr gbm, int width, int height, SurfaceFormat format, SurfaceFlags flags);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void gbm_surface_destroy (IntPtr surface);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- static extern gbm_bo* gbm_surface_lock_front_buffer (IntPtr surface);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- static extern void gbm_surface_release_buffer (IntPtr surface, gbm_bo* buffer);
- [DllImport("gbm", CallingConvention = CallingConvention.Cdecl)]
- static extern int gbm_surface_has_free_buffers (IntPtr surface);
- #endregion
-
- internal IntPtr handle;
-
- #region ctor
- public Surface (Device gbmDev, int width, int height, SurfaceFlags flags, SurfaceFormat format = SurfaceFormat.ARGB8888)
- {
- handle = gbm_surface_create(gbmDev.handle, width, height, format, flags);
-
- if (handle == IntPtr.Zero)
- throw new NotSupportedException("[GBM] Failed to create GBM surface");
- }
- #endregion
-
- public bool HasFreeBuffers { get { return gbm_surface_has_free_buffers (handle) > 0; }}
-
- public gbm_bo* Lock (){
- gbm_bo* bo = gbm_surface_lock_front_buffer (handle);
- if (bo == null)
- throw new Exception ("[GBM]: Failed to lock front buffer.");
- return bo;
- }
- public void Release (gbm_bo* bo) {
- gbm_surface_release_buffer (handle, bo);
- }
-
- #region IDisposable implementation
- ~Surface(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (handle != IntPtr.Zero)
- gbm_surface_destroy (handle);
- handle = IntPtr.Zero;
- }
- #endregion
- }
-}
-
+++ /dev/null
-//
-// TTY.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-
-namespace Crow.Linux.VT
-{
- internal class TTY {
- [DllImport("libc")]
- static extern IntPtr ptsname(int fd);
- [DllImport("libc")]
- public static extern int unlockpt(int fd);
-
- public static string GetFreePtsPath (int fd){
- IntPtr pStr = ptsname (fd);
- string name = Marshal.PtrToStringAnsi (pStr);
- return name;
- }
- }
-}
-
+++ /dev/null
-//
-// VT.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
-using System;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
-
-namespace Linux.VT {
- public enum KDMode : byte {
- TEXT = 0x00,
- GRAPHICS= 0x01,
- TEXT0 = 0x02, /* obsolete */
- TEXT1 = 0x03 /* obsolete */
- }
- public enum SwitchMode : byte {
- AUTO = 0x00, /* auto vt switching */
- PROCESS = 0x01, /* process controls switching */
- ACKACQ = 0x02 /* acknowledge switch */
- }
- public enum KbdMode{
- RAW = 0x00,
- XLATE = 0x01,
- MEDIUMRAW = 0x02,
- UNICODE = 0x03,
- OFF = 0x04,
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct vt_mode {
- public SwitchMode mode; /* vt mode */
- public byte waitv; /* if set, hang on writes if not active */
- public short relsig; /* signal to raise on release req */
- public short acqsig; /* signal to raise on acquisition */
- public short frsig; /* unused (set to 0) */
- public override string ToString ()
- {
- return string.Format ("[vt_mode]:waitv:{0} relsig:{1} acqsig:{2} switchmode:{3}", waitv, relsig, acqsig, mode);
- }
- }
- public struct State {
- public ushort v_active; /* active vt */
- public ushort v_signal; /* signal to send */
- public ushort v_state; /* vt bitmask */
- }
- public struct Sizes {
- public ushort v_rows; /* number of rows */
- public ushort v_cols; /* number of columns */
- public ushort v_scrollsize; /* number of lines of scrollback */
- }
- [StructLayout(LayoutKind.Sequential)]
- unsafe public struct KbsEntry {
- public byte kb_func;
- fixed byte kb_string[512];
-
- public string KbString {
- get {
- fixed(byte* bytes = kb_string) {
- int i = 0;
- List<byte> lb = new List<byte> ();
- while (i<512){
- byte b = (byte)*(bytes + i);
- if ((int)b == 0)
- break;
- lb.Add (b);
- i++;
- }
-
- string test = System.Text.Encoding.ASCII.GetString (lb.ToArray ());
-
- return test;
- }
-
- }
- }
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct KbEntry {
- public KbTable kb_table;
- public byte kb_index;
- public ushort kb_value;
-
- public byte ActionCode { get { return (byte)(kb_value & 0xff);}}
- public KtType KeyType { get { return (KtType)(kb_value>>8); }}
-
- public override string ToString ()
- {
- return string.Format ("KbEntry: {0} {1} {2}", kb_table, kb_index, kb_value);
- }
- }
- [Flags]public enum KtType : byte {
- Latin = 0x00, /* we depend on this being zero */
- Fn = 0x01,
- Spec = 0x02,
- Pad = 0x03,
- Dead = 0x04,
- Cons = 0x05,
- Cur = 0x06,
- Shift = 0x07,
- Meta = 0x08,
- Ascii = 0x09,
- Lock = 0x0a,
- Letter = 0x0b, /* symbol that can be acted upon by CapsLock */
- Slock = 0x0c,
- Dead2 = 0x0d,
- Brl = 0x0e
- }
-
- [Flags]public enum KbTable : byte {
- Normal = 0x00,
- Shift = 0x01,
- Alt = 0x02,
- AltShift= 0x03
- }
- public class VTControler : IDisposable {
- public int fd = -1;
-
- #region ctor
- public VTControler (string path = "/dev/tty") {
- fd = Libc.open (path, OpenFlags.ReadWrite);
- if (fd <= 0)
- throw new Exception ("VTControler: unable to open " + path);
- }
- #endregion
-
- /// <summary>set Graphic or Text mode for VT. </summary>
- public KDMode KDMode {
- get {
- KDMode m = 0;
- if (ioctl (fd, KDGETMODE, ref m) < 0)
- throw new Exception ("VTControler: failed to get current TTY mode");
- return m;
- }
- set {
- if (ioctl (fd, KDSETMODE, value) < 0)
- throw new Exception ("VTControler: failed to set current TTY mode");
- }
- }
- /// <summary>set AUTO or PROCESS mode for VT. </summary>
- public vt_mode VTMode {
- get {
- vt_mode m = new vt_mode();
- if (ioctl (fd, VT_GETMODE, ref m) < 0)
- throw new Exception ("VTControler: failed to get VTMode for current");
- return m;
- }
- set {
- if (ioctl (fd, VT_SETMODE, ref value) < 0)
- throw new Exception ("VTControler: failed to set VTMode for current VT");
- }
- }
- /// <summary>get/set keyboard mode. </summary>
- public KbdMode KbdMode {
- get {
- KbdMode m = 0;
- if (ioctl (fd, KDGKBMODE, ref m) < 0)
- throw new Exception ("VTControler: failed to get current keyboard mode");
- return m;
- }
- set {
- if (ioctl (fd, KDSKBMODE, (int)value) < 0)
- throw new Exception ("VTControler: failed to set current keyboard mode");
- }
- }
- /// <summary>
- /// Switchs to V.
- /// </summary>
- /// <param name="vt">Virtual Terminal to switch to</param>
- /// <param name="waitCompleted">If set to <c>true</c> wait until switch is completed.</param>
- public void SwitchTo (int vt, bool waitCompleted = true){
- if (ioctl (fd, VT_ACTIVATE, vt) < 0)
- throw new Exception ("VTControler: failed to activate TTY" + vt);
- if (waitCompleted) {
- if (ioctl (fd, VT_WAITACTIVE, vt) < 0)
- throw new Exception ("VTControler: error waiting for activation of TTY" + vt);
- }
- }
- public State State {
- get {
- State vtstats = new State ();
- if (ioctl (fd, VT_GETSTATE, ref vtstats) < 0)
- throw new Exception ("VirtualTerminal: unable to get TTY Stats");
- return vtstats;
- }
- }
- public int FirstAvailableVT {
- get {
- long freeVT = 0;
- ioctl (fd, VT_OPENQRY, ref freeVT);
- return (int)freeVT;
- }
- }
- public int CurrentVT {
- get {
- return (int)State.v_active;
- }
- }
-
- const int ACKACQ = 0x02;
-
- public void AcknoledgeSwitchRequest (){
- if (ioctl (fd, VT_RELDISP, ACKACQ)<0)
- throw new Exception ("VTControler: failed to acknowledge switch with VT_RELDISP");
- }
- public void AtachProcessTOTTY (int ttyNum){
- int ret =ioctl (fd, TIOCSCTTY, ttyNum);
- if (ret<0)
- throw new Exception (string.Format ("VTControler: failed to attach process to TTY {0}: {1}",ttyNum,ret));
- }
- public void DetachProcess () {
- if (ioctl (fd, TIOCNOTTY, 0)<0)
- throw new Exception ("VTControler: failed to dettach process from TTY");
- }
-
- public KbEntry GetKDBEntry (KbTable table, byte index){
- KbEntry ke = new KbEntry() { kb_table = table, kb_index = index};
- int ret = ioctl (fd, KDGKBENT, ref ke);
- if (ret < 0)
- throw new Exception ("VTControler: failed to get KDEntry: " + ret );
- return ke;
- }
- public string GetKbString (byte action_code){
- KbsEntry ke = new KbsEntry() { kb_func = action_code};
- int ret = ioctl (fd, KDGKBSENT, ref ke);
- if (ret < 0)
- throw new Exception ("VTControler: failed to get KDSEntry: " + ret );
- return ke.KbString;
- }
-
- #region IDisposable implementation
- ~VTControler(){
- Dispose (false);
- }
- public void Dispose ()
- {
- Dispose (true);
- GC.SuppressFinalize (this);
- }
- protected virtual void Dispose (bool disposing){
- if (fd > 0)
- Libc.close (fd);
- fd = -1;
- }
- #endregion
-
- #region IOCTLS constants
- const uint KDSETMODE = 0x4B3A; /* set text/graphics mode */
- const uint KDGETMODE = 0x4B3B; /* get current mode */
-
- const uint KDGKBMODE = 0x4B44; /* gets current keyboard mode */
- const uint KDSKBMODE = 0x4B45; /* sets current keyboard mode */
- const uint KDGKBENT = 0x4B46; /* gets one entry in translation table */
- const uint KDSKBENT = 0x4B47; /* sets one entry in translation table */
- const uint KDGKBSENT = 0x4B48; /* gets one function key string entry */
- const uint KDSKBSENT = 0x4B49; /* sets one function key string entry */
-
- const uint VT_OPENQRY = 0x5600; /* find available vt */
- const uint VT_GETMODE = 0x5601; /* get mode of active vt */
- const uint VT_SETMODE = 0x5602; /* set mode of active vt */
-
- const uint VT_GETSTATE = 0x5603; /* get global vt state info */
- const uint VT_SENDSIG = 0x5604; /* signal to send to bitmask of vts */
-
- const uint VT_RELDISP = 0x5605; /* release display */
-
- const uint VT_ACTIVATE = 0x5606; /* make vt active */
- const uint VT_WAITACTIVE= 0x5607; /* wait for vt active */
- const uint VT_DISALLOCATE= 0x5608; /* free memory associated to vt */
-
- const uint VT_RESIZE = 0x5609; /* set kernel's idea of screensize */
- const uint TIOCNOTTY = 0x5422; /* dettach process from tty */
- const uint TIOCSCTTY = 0x540E; /* attach process to tty */
- #endregion
-
- #region ioctl overrides
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref KbEntry entry);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref KbsEntry entry);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref KbdMode value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref long value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, int value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref int value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref State value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref SwitchMode value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, KDMode value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref KDMode value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, vt_mode value);
- [DllImport("libc")]
- static extern int ioctl(int d, uint request, ref vt_mode value);
- #endregion
- }
-}
\ No newline at end of file
<Command type="Execute" command="${TargetName}" workingdir="${SolutionDir}/build/${ProjectConfigName}" />
</CustomCommands>
</CustomCommands>
- <StartupObject>testDrm.Tests</StartupObject>
+ <StartupObject>testDrm.TestApp</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
- <Compile Include="src\Linux\Bindings\Drm.cs" />
- <Compile Include="src\Linux\Bindings\Gbm.cs" />
- <Compile Include="src\Linux\Bindings\Kms.cs" />
<Compile Include="src\Linux\Bindings\Libc.cs" />
<Compile Include="src\Linux\Bindings\LibInput.cs" />
<Compile Include="src\Linux\Bindings\Poll.cs" />
- <Compile Include="src\Linux\Bindings\Terminal.cs" />
<Compile Include="src\Linux\Bindings\Udev.cs" />
<Compile Include="src\BlittableValueType.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="src\MouseCursor.cs" />
<Compile Include="src\WindowIcon.cs" />
- <Compile Include="src\Linux\Bindings\Egl.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="src\Linux\TTY.cs" />
<Compile Include="src\Linux\Signal.cs" />
- <Compile Include="src\Linux\VT.cs" />
- <Compile Include="src\Linux\DRI\Connector.cs" />
- <Compile Include="src\Linux\DRI\Encoder.cs" />
- <Compile Include="src\Linux\DRI\Resources.cs" />
- <Compile Include="src\Linux\DRI\Crtc.cs" />
- <Compile Include="src\Linux\DRI\Plane.cs" />
- <Compile Include="src\Egl\EGL.cs" />
- <Compile Include="src\Egl\Surface.cs" />
- <Compile Include="src\Egl\Context.cs" />
- <Compile Include="src\Linux\GBM\Surface.cs" />
- <Compile Include="src\Linux\GBM\BufferObject.cs" />
- <Compile Include="src\Linux\GBM\Device.cs" />
<Compile Include="src\Application.cs" />
<Compile Include="Main.cs" />
- <Compile Include="src\Linux\DRI\PlaneResources.cs" />
- <Compile Include="src\Linux\DRI\DRIControler.cs" />
<Compile Include="tests.cs" />
<Compile Include="testLibInput.cs" />
<Compile Include="src\EVDEV\Device.cs" />
<Compile Include="src\Linux\Bindings\EvdevClass.cs" />
<Compile Include="defineToEnum.cs" />
<Compile Include="src\EVDEV\Enums.cs" />
+ <Compile Include="src\Linux\DRIControler.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<ItemGroup>
<Folder Include="src\" />
<Folder Include="ui\" />
- <Folder Include="src\Linux\DRI\" />
- <Folder Include="src\Egl\" />
- <Folder Include="src\Linux\GBM\" />
<Folder Include="src\EVDEV\" />
</ItemGroup>
<ItemGroup>
<Project>{C2980F9B-4798-4C05-99E2-E174810F7C7B}</Project>
<Name>Crow</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\DRI.net\DRI.net.csproj">
+ <Project>{0189EAEF-DCD4-42F8-A83A-2DEA82926671}</Project>
+ <Name>DRI.net</Name>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ui\menu.crow" />
using System.Runtime.InteropServices;
using System.Threading;
using Crow;
-using OpenTK.Platform.Linux;
using System.IO;
namespace testDrm
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
-using Crow.Linux;
using System.Threading;
using Linux;
using System.Runtime.InteropServices;
using Linux.Evdev;
using Linux.VT;
+using DRI.DRM;
+using DRI.DRM;
namespace testDrm
{
if (Kernel.signal (Signal.SIGINT, sigint_handler) < 0)
throw new Exception ("SIGINT handler registation failed");
- using (VT.VTControler master = new VT.VTControler ()) {
+ using (VTControler master = new VTControler ()) {
previousVT = master.CurrentVT;
appVT = master.FirstAvailableVT;
master.SwitchTo (appVT);
try {
- master.KDMode = VT.KDMode.GRAPHICS;
+ master.KDMode = KDMode.GRAPHICS;
} catch (Exception ex) {
Console.WriteLine (ex.ToString ());
}
Console.WriteLine (ex.ToString ());
}
- using (VT.VTControler master = new VT.VTControler ()) {
+ using (VTControler master = new VTControler ()) {
// try {
// master.KDMode = VT.KDMode.TEXT;
// } catch (Exception ex) {
static void tty_switch2(){
int previousVT = -1, appVT = -1;
- using(VT.VTControler master = new VT.VTControler()){
- VT.vt_mode m = master.VTMode;
+ using(VTControler master = new VTControler()){
+ vt_mode m = master.VTMode;
Console.WriteLine ("Startup:");
Console.WriteLine ("\tVT{0}\t- KDMode: {1}", master.CurrentVT, master.KDMode);
m = master.VTMode;
try {
- master.KDMode = VT.KDMode.GRAPHICS;
+ master.KDMode = KDMode.GRAPHICS;
//m.mode = VT.SwitchMode.AUTO;
//master.VTMode = m;
if (fd_gpu < 0)
throw new NotSupportedException("[DRI] Failed to open gpu");
- using (DRI.Resources resources = new DRI.Resources (fd_gpu)) {
- foreach (DRI.Connector e in resources.Connectors) {
+ using (Resources resources = new Resources (fd_gpu)) {
+ foreach (Connector e in resources.Connectors) {
Console.WriteLine (e.ToString ());
}
- foreach (DRI.Encoder e in resources.Encoders)
- Console.WriteLine (e.ToString ());
- foreach (DRI.Crtc e in resources.Crtcs)
+// foreach (DRM.Encoder e in resources.Encoders)
+// Console.WriteLine (e.ToString ());
+ foreach (Crtc e in resources.Crtcs)
Console.WriteLine (e.ToString ());
}