From 8d385b053423c16e18d02467bdd54be17c3b42aa Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 27 May 2017 10:16:57 +0200 Subject: [PATCH] showcase test --- CrowIDE/CrowIDE.csproj | 3 - Tests/InterfaceControler.cs | 2 +- Tests/Tests.csproj | 2 +- testDrm/Main.cs | 4 + testDrm/Showcase.cs | 210 ++++++ testDrm/TestCrow.cs | 31 +- testDrm/src/BlittableValueType.cs | 291 -------- testDrm/src/DRMContext.cs | 835 ----------------------- testDrm/src/DisplayResolution.cs | 232 ------- testDrm/src/Linux/Bindings/EvdevClass.cs | 16 +- testDrm/src/Linux/DRIControler.cs | 2 + testDrm/src/MouseCursor.cs | 135 ---- testDrm/src/WindowIcon.cs | 91 --- testDrm/testDrm.csproj | 19 +- testDrm/ui/perfMeasures.crow | 2 +- testDrm/ui/showcase.crow | 58 ++ 16 files changed, 307 insertions(+), 1626 deletions(-) create mode 100644 testDrm/Showcase.cs delete mode 100644 testDrm/src/BlittableValueType.cs delete mode 100644 testDrm/src/DRMContext.cs delete mode 100644 testDrm/src/DisplayResolution.cs delete mode 100644 testDrm/src/MouseCursor.cs delete mode 100644 testDrm/src/WindowIcon.cs create mode 100755 testDrm/ui/showcase.crow diff --git a/CrowIDE/CrowIDE.csproj b/CrowIDE/CrowIDE.csproj index 4aae4fce..c18bc528 100644 --- a/CrowIDE/CrowIDE.csproj +++ b/CrowIDE/CrowIDE.csproj @@ -70,9 +70,6 @@ src\Application.cs - - src\BlittableValueType.cs - src\Bindings\EvdevClass.cs diff --git a/Tests/InterfaceControler.cs b/Tests/InterfaceControler.cs index 4d988c10..869c3896 100644 --- a/Tests/InterfaceControler.cs +++ b/Tests/InterfaceControler.cs @@ -162,7 +162,7 @@ namespace Crow while (true) { CrowInterface.Update (); - //Thread.Sleep (1); + Thread.Sleep (3); } } diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 04344a40..9eb845a1 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -27,7 +27,7 @@ prompt 4 false - DEBUG;TRACE;MEASURE_TIME + DEBUG;TRACE;MEASURE_TIME0 $(SolutionDir)build\obj\$(Configuration) $(SolutionDir)build\$(Configuration) diff --git a/testDrm/Main.cs b/testDrm/Main.cs index eb15fcc3..45a95d63 100644 --- a/testDrm/Main.cs +++ b/testDrm/Main.cs @@ -219,7 +219,9 @@ namespace testDrm int width = 19; int height = 19; using (Cairo.ImageSurface img = new Cairo.ImageSurface (Cairo.Format.Argb32, gpu.Width, gpu.Height)) { + #if MEASURE_TIME glDrawMeasure.StartCycle (); + #endif using (Cairo.Context ctx = new Cairo.Context (img)) { for (int x = 100; x < 800; x += 20) { for (int y = 100; y < 800; y += 20) { @@ -229,7 +231,9 @@ namespace testDrm } } } + #if MEASURE_TIME glDrawMeasure.StopCycle (); + #endif using (Cairo.Context ctx = new Cairo.Context (cairoSurf)) { ctx.SetSourceSurface (img, 0, 0); ctx.Paint (); diff --git a/testDrm/Showcase.cs b/testDrm/Showcase.cs new file mode 100644 index 00000000..3cc1c720 --- /dev/null +++ b/testDrm/Showcase.cs @@ -0,0 +1,210 @@ +// +// UIEditor.cs +// +// Author: +// Jean-Philippe Bruyère +// +// 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 Crow; +using System.IO; +using System.Collections.Generic; +using System.Reflection; +using System.Linq; + +namespace Tests +{ + class Showcase : Application, IValueChange + { + [STAThread] + static void Main () + { + try { + using (Showcase crowApp = new Showcase ()) + crowApp.Run (); + } catch (Exception ex) { + Console.WriteLine (ex.ToString ()); + } + } + + #region IValueChange implementation + public event EventHandler ValueChanged; + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } + #endregion + + + public Command CMDViewPerf, CMDViewCfg, CMDViewTest0, CMDOpen; + + public Showcase () : base () { + CMDViewPerf = new Command(new Action(() => Load ("#testDrm.ui.perfMeasures.crow").DataSource = this)) { Caption = "Performances"}; + CMDViewCfg = new Command(new Action(() => Load ("#testDrm.ui.2.crow").DataSource = this)) { Caption = "Configuration"}; + CMDViewTest0 = new Command(new Action(() => Load ("#testDrm.ui.0.crow").DataSource = this)) { Caption = "Test view 0"}; + CMDOpen = new Command(new Action(() => { + lock (CrowInterface.UpdateMutex) CrowInterface.AddWidget(new FileDialog());})) { Caption = "Open"}; + + GraphicObject g = Load ("#testDrm.ui.showcase.crow"); + g.DataSource = this; + crowContainer = g.FindByName ("CrowContainer") as Container; + //I set an empty object as datasource at this level to force update when new + //widgets are added to the interface + crowContainer.DataSource = new object (); + } + + Container crowContainer; + + + void Dv_SelectedItemChanged (object sender, SelectionChangeEventArgs e) + { + FileSystemInfo fi = e.NewValue as FileSystemInfo; + if (fi == null) + return; + lock (CrowInterface.UpdateMutex) { + GraphicObject g = CrowInterface.Load (fi.FullName); + crowContainer.SetChild (g); + g.DataSource = this; + } + + string source = ""; + using (Stream s = new FileStream (fi.FullName, FileMode.Open)) { + using (StreamReader sr = new StreamReader (s)) { + source = sr.ReadToEnd (); + } + } + NotifyValueChanged ("source", source); + } + + void Tb_TextChanged (object sender, TextChangeEventArgs e) + { + GraphicObject g = null; + try { + lock (CrowInterface.UpdateMutex) { + Instantiator inst = null; + using (MemoryStream ms = new MemoryStream (System.Text.Encoding.Unicode.GetBytes (e.Text))){ + inst = new Instantiator (ms); + } + g = inst.CreateInstance (CrowInterface); + crowContainer.SetChild (g); + + } + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine (ex.ToString ()); + } + g.DataSource = this; + } + + #region Test values for Binding + public int intValue = 500; + DirectoryInfo curDir = new DirectoryInfo (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); + //DirectoryInfo curDir = new DirectoryInfo (@"/mnt/data/Images"); + public FileSystemInfo[] CurDirectory { + get { return curDir.GetFileSystemInfos (); } + } + public int IntValue { + get { + return intValue; + } + set { + intValue = value; + NotifyValueChanged ("IntValue", intValue); + } + } + void onSpinnerValueChange(object sender, ValueChangeEventArgs e){ + if (e.MemberName != "Value") + return; + intValue = Convert.ToInt32(e.NewValue); + } + void change_alignment(object sender, EventArgs e){ + RadioButton rb = sender as RadioButton; + if (rb == null) + return; + NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption)); + } + public IList List2 = new List(new string[] + { + "string1", + "string2", + "string3", + // "string4", + // "string5", + // "string6", + // "string7", + // "string8", + // "string8", + // "string8", + // "string8", + // "string8", + // "string8", + // "string9" + } + ); + public IList TestList2 { + set{ + List2 = value; + NotifyValueChanged ("TestList2", testList); + } + get { return List2; } + } + IList testList = Color.ColorDic.ToList(); + public IList TestList { + set{ + testList = value; + NotifyValueChanged ("TestList", testList); + } + get { return testList; } + } + string curSources = ""; + public string CurSources { + get { return curSources; } + set { + if (value == curSources) + return; + curSources = value; + NotifyValueChanged ("CurSources", curSources); + } + } + bool boolVal = true; + public bool BoolVal { + get { return boolVal; } + set { + if (boolVal == value) + return; + boolVal = value; + NotifyValueChanged ("BoolVal", boolVal); + } + } + + #endregion + + void OnClear (object sender, MouseButtonEventArgs e) => TestList = null; + + void OnLoadList (object sender, MouseButtonEventArgs e) => TestList = Color.ColorDic.ToList(); + void onQuitClick(object send, Crow.MouseButtonEventArgs e) + { + Running = false; + } + } + + +} \ No newline at end of file diff --git a/testDrm/TestCrow.cs b/testDrm/TestCrow.cs index 78b76eee..cfacae83 100644 --- a/testDrm/TestCrow.cs +++ b/testDrm/TestCrow.cs @@ -25,20 +25,37 @@ // THE SOFTWARE. using System; using Crow; +using System.Runtime.InteropServices; namespace testDrm { public class TestCrow { - static void Main(){ - Rectangle bounds = new Rectangle(0,0,1024,768); - Interface iface = new Interface(); - iface.ProcessResize (bounds); + const string lib = "/home/jp/devel/testsharedlib/bin/Debug/libcrow.so"; - iface.LoadInterface ("#testDrm.ui.go.crow"); + [DllImport(lib)] + unsafe static extern Rectangle* allocate(); - while (true) - iface.Update (); + [DllImport(lib)] + public static extern void update (int w, int h); + + + unsafe static Rectangle* rect; + + unsafe static void Main(){ + rect = allocate(); + update (150, 160); + Console.WriteLine (rect->Height); + rect->Height = 200; + Console.WriteLine (rect->Height); +// Rectangle bounds = new Rectangle(0,0,1024,768); +// Interface iface = new Interface(); +// iface.ProcessResize (bounds); +// +// iface.LoadInterface ("#testDrm.ui.go.crow"); +// +// while (true) +// iface.Update (); } } } diff --git a/testDrm/src/BlittableValueType.cs b/testDrm/src/BlittableValueType.cs deleted file mode 100644 index 81ce16ae..00000000 --- a/testDrm/src/BlittableValueType.cs +++ /dev/null @@ -1,291 +0,0 @@ -#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 - - /// - /// Checks whether the specified type parameter is a blittable value type. - /// - /// - /// A blittable value type is a struct that only references other value types recursively, - /// which allows it to be passed to unmanaged code directly. - /// - public static class BlittableValueType - { - #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 - - /// - /// Gets the size of the type in bytes or 0 for non-blittable types. - /// - /// - /// This property returns 0 for non-blittable types. - /// - public static int Stride { get { return stride; } } - - #region Check - - /// - /// Checks whether the current typename T is blittable. - /// - /// True if T is blittable; false otherwise. - public static bool Check() - { - return Check(Type); - } - - /// - /// Checks whether type is a blittable value type. - /// - /// A System.Type to check. - /// True if T is blittable; false otherwise. - 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 - - /// - /// Checks whether the specified type parameter is a blittable value type. - /// - /// - /// A blittable value type is a struct that only references other value types recursively, - /// which allows it to be passed to unmanaged code directly. - /// - public static class BlittableValueType - { - #region Check - - /// - /// Checks whether type is a blittable value type. - /// - /// An instance of the type to check. - /// True if T is blittable; false otherwise. - public static bool Check(T type) - { - return BlittableValueType.Check(); - } - - /// - /// Checks whether type is a blittable value type. - /// - /// An instance of the type to check. - /// True if T is blittable; false otherwise. - [CLSCompliant(false)] - public static bool Check(T[] type) - { - return BlittableValueType.Check(); - } - - /// - /// Checks whether type is a blittable value type. - /// - /// An instance of the type to check. - /// True if T is blittable; false otherwise. - [CLSCompliant(false)] - public static bool Check(T[,] type) - { - return BlittableValueType.Check(); - } - - /// - /// Checks whether type is a blittable value type. - /// - /// An instance of the type to check. - /// True if T is blittable; false otherwise. - [CLSCompliant(false)] - public static bool Check(T[, ,] type) - { - return BlittableValueType.Check(); - } - - /// - /// Checks whether type is a blittable value type. - /// - /// An instance of the type to check. - /// True if T is blittable; false otherwise. - [CLSCompliant(false)] - public static bool Check(T[][] type) - { - return BlittableValueType.Check(); - } - - #endregion - - #region StrideOf - - /// - /// Returns the size of the specified value type in bytes or 0 if the type is not blittable. - /// - /// The value type. Must be blittable. - /// An instance of the value type. - /// An integer, specifying the size of the type in bytes. - /// Occurs when type is not blittable. - public static int StrideOf(T type) - { - if (!Check(type)) - throw new ArgumentException("type"); - - return BlittableValueType.Stride; - } - - /// - /// Returns the size of a single array element in bytes or 0 if the element is not blittable. - /// - /// The value type. - /// An instance of the value type. - /// An integer, specifying the size of the type in bytes. - /// Occurs when type is not blittable. - [CLSCompliant(false)] - public static int StrideOf(T[] type) - { - if (!Check(type)) - throw new ArgumentException("type"); - - return BlittableValueType.Stride; - } - - /// - /// Returns the size of a single array element in bytes or 0 if the element is not blittable. - /// - /// The value type. - /// An instance of the value type. - /// An integer, specifying the size of the type in bytes. - /// Occurs when type is not blittable. - [CLSCompliant(false)] - public static int StrideOf(T[,] type) - { - if (!Check(type)) - throw new ArgumentException("type"); - - return BlittableValueType.Stride; - } - - /// - /// Returns the size of a single array element in bytes or 0 if the element is not blittable. - /// - /// The value type. - /// An instance of the value type. - /// An integer, specifying the size of the type in bytes. - /// Occurs when type is not blittable. - [CLSCompliant(false)] - public static int StrideOf(T[, ,] type) - { - if (!Check(type)) - throw new ArgumentException("type"); - - return BlittableValueType.Stride; - } - - #endregion - } - - #endregion -} diff --git a/testDrm/src/DRMContext.cs b/testDrm/src/DRMContext.cs deleted file mode 100644 index b9451952..00000000 --- a/testDrm/src/DRMContext.cs +++ /dev/null @@ -1,835 +0,0 @@ -// -// DRMDevice.cs -// -// Author: -// Jean-Philippe Bruyère -// -// 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 OpenTK; -using OpenTK.Platform.Linux; -using System.IO.Compression; - -namespace Linux -{ - - internal class DRMContext : IDisposable - { - Stopwatch drmTimeOut; - - public Interface CrowInterface; - int fd_gpu = 0; - - IntPtr gbm_device, gbm_surface, egl_display, egl_config, egl_surface, egl_ctx; - - ModeInfo originalMode, currentMode; - public int width, height; - - volatile bool run = true; - - public IntPtr Connector, Crtc, Encoder; - unsafe ModeCrtc* saved_crtc; - unsafe ModeConnector* pConnector { get { return (ModeConnector*)Connector; } } - unsafe ModeCrtc* pCrtc { get { return (ModeCrtc*)Crtc; } } - unsafe ModeEncoder* pEncoder { get { return (ModeEncoder*)Encoder; } } - - Cairo.EGLDevice cairoDev; - Cairo.GLSurface cairoSurf; - - Dictionary keymap; - - int previousVT = 0, appVT; - - public DRMContext(string gpu_path = "/dev/dri/card0"){ - drmTimeOut = new Stopwatch(); - - DestroyFB = HandleDestroyFB; - DestroyFBPtr = Marshal.GetFunctionPointerForDelegate(DestroyFB); - PageFlip = HandlePageFlip; - PageFlipPtr = Marshal.GetFunctionPointerForDelegate(PageFlip); - - gbm_device = IntPtr.Zero; - egl_display = IntPtr.Zero; - - fd_gpu = Libc.open(gpu_path, OpenFlags.ReadWrite | OpenFlags.CloseOnExec); - if (fd_gpu < 0) - throw new NotSupportedException("[KMS] Failed to open gpu"); - Console.WriteLine("[KMS] GPU '{0}' opened as fd:{1}", gpu_path, fd_gpu); - - initDrm (); - - initGbm (); - - setNewMode (); - - initEgl (); - - initCairo (); - - initInput (); - } - - #region init - unsafe void initDrm(){ - ModeRes* resources = (ModeRes*)Drm.ModeGetResources(fd_gpu); - if (resources == null) - throw new NotSupportedException("[KMS] Drm.ModeGetResources failed."); - - ModeConnector* connector = null; - for (int i = 0; i < resources->count_connectors; i++) { - connector = (ModeConnector*)Drm.ModeGetConnector (fd_gpu, *(resources->connectors + i)); - if (connector != null) { - if (connector->connection == ModeConnection.Connected && connector->count_encoders > 0) - break; - Drm.ModeFreeConnector ((IntPtr)connector); - connector = null; - } - } - if (connector == null) - throw new NotSupportedException("[KMS] No connected screen found"); - - Connector = (IntPtr)connector; - Encoder = Drm.ModeGetEncoder (fd_gpu, connector->encoder_id); - Crtc = Drm.ModeGetCrtc(fd_gpu, pEncoder->crtc_id); - saved_crtc = (ModeCrtc*) Drm.ModeGetCrtc (fd_gpu, pEncoder->crtc_id); - - originalMode = pCrtc->mode; - width = 1600; - height = 900; - - // Console.WriteLine ("[DRM]: current mode = {0} X {1} at {2} Hz", width, height, currentMode.vrefresh); - } - void initGbm (){ - gbm_device = Gbm.CreateDevice(fd_gpu); - if (gbm_device == IntPtr.Zero) - throw new NotSupportedException("[GBM] Failed to create GBM device"); - - gbm_surface = Gbm.CreateSurface(gbm_device, width, height, SurfaceFormat.ARGB8888, SurfaceFlags.Rendering | SurfaceFlags.Scanout); - if (gbm_surface == IntPtr.Zero) - throw new NotSupportedException("[GBM] Failed to create GBM surface for rendering"); - } - - void setNewMode (){ - //118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync - //currentMode = pCrtc->mode; - currentMode.clock = 118250; - currentMode.hdisplay = 1600; - currentMode.hsync_start = 1696; - currentMode.hsync_end = 1856; - currentMode.htotal = 2112; - currentMode.vdisplay = 900; - currentMode.vsync_start = 903; - currentMode.vsync_end = 908; - currentMode.vtotal = 934; - currentMode.flags |= (uint)ModeFlags.NHSYNC; - currentMode.flags |= (uint)ModeFlags.PVSYNC; - // byte[] tmp = System.Text.Encoding.ASCII.GetBytes ("1600x900"); - // for (int i = 0; i < tmp.Length; i++) { - // currentMode.name [i] = (sbyte)tmp [i]; - // } - - unsafe - { - pCrtc->mode = currentMode; - ModeInfo* mode = (ModeInfo*)Marshal.AllocHGlobal (sizeof(ModeInfo));// pConnector->modes; - *mode = currentMode; - int connector_id = pConnector->connector_id; - int crtc_id = pEncoder->crtc_id; - BufferObject bo = Gbm.CreateBuffer( - gbm_device, width, height, SurfaceFormat.ARGB8888, SurfaceFlags.Scanout); - int nfb = getFbFromBo (bo); - int ret = Drm.ModeSetCrtc (fd_gpu, crtc_id, nfb, 0, 0, &connector_id, 1, mode); - - if (ret != 0) - Console.WriteLine("[KMS] Drm.ModeSetCrtc failed. Error: " + ret); - } - // width = currentMode.hdisplay; - // height = currentMode.vdisplay; - } - - unsafe void initEgl () { - int major, minor; - IntPtr[] configs = new IntPtr[1]; - - int[] contextAttrib = new int[] { - Egl.CONTEXT_CLIENT_VERSION, 2, - Egl.NONE - }; - int[] attribList = 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; - - egl_display = Egl.GetDisplay(gbm_device); - - if (egl_display == IntPtr.Zero) - throw new NotSupportedException("[KMS] Failed to create EGL display"); - Console.WriteLine("[EGL] EGL display {0:x} created successfully", egl_display); - - if (!Egl.Initialize(egl_display, out major, out minor)) - throw new NotSupportedException("[EGL] Failed to initialize EGL display. Error code: " + Egl.GetError()); - - if (!Egl.BindAPI (RenderApi.GL)) - throw new NotSupportedException("[EGL] Failed to bind EGL Api: " + Egl.GetError()); - - Console.WriteLine ("[EGL] Version: " + Marshal.PtrToStringAuto (Egl.QueryString (egl_display, Egl.VERSION))); - Console.WriteLine ("[EGL] Vendor: " + Marshal.PtrToStringAuto (Egl.QueryString (egl_display, Egl.VENDOR))); - Console.WriteLine ("[EGL] Extensions: " + Marshal.PtrToStringAuto (Egl.QueryString (egl_display, Egl.EXTENSIONS))); - Console.WriteLine (" " + Marshal.PtrToStringAuto (Egl.QueryString(IntPtr.Zero, Egl.EXTENSIONS))); - - if (!Egl.ChooseConfig(egl_display, attribList, configs, configs.Length, out num_configs) || num_configs == 0) - throw new NotSupportedException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); - - egl_config = configs[0]; - egl_ctx = Egl.CreateContext(egl_display, egl_config, IntPtr.Zero, contextAttrib); - egl_surface = Egl.CreateWindowSurface(egl_display, egl_config, gbm_surface, IntPtr.Zero); - - if (egl_surface==IntPtr.Zero) - throw new NotSupportedException(String.Format("[EGL] Failed to create window surface, error {0}.", Egl.GetError())); - - // See what we really got - int r, g, b, a, d, s, sample_buffers, samples; - IntPtr active_config = configs[0]; - - Egl.GetConfigAttrib(egl_display, active_config, Egl.RED_SIZE, out r); - Egl.GetConfigAttrib(egl_display, active_config, Egl.GREEN_SIZE, out g); - Egl.GetConfigAttrib(egl_display, active_config, Egl.BLUE_SIZE, out b); - Egl.GetConfigAttrib(egl_display, active_config, Egl.ALPHA_SIZE, out a); - Egl.GetConfigAttrib(egl_display, active_config, Egl.DEPTH_SIZE, out d); - Egl.GetConfigAttrib(egl_display, active_config, Egl.STENCIL_SIZE, out s); - Egl.GetConfigAttrib(egl_display, active_config, Egl.SAMPLE_BUFFERS, out sample_buffers); - Egl.GetConfigAttrib(egl_display, active_config, Egl.SAMPLES, out samples); - Console.WriteLine ("EGL context: {0},{1},{2},{3} depth={4} stencil={5} samples={6} sample buffers={7}", - r, g, b, a, d, s, samples, sample_buffers); - - - if (!Egl.MakeCurrent(egl_display, egl_surface, egl_surface, egl_ctx)) - throw new NotSupportedException(string.Format("Failed to make context {0} current. Error: {1}", gbm_surface, Egl.GetError())); - } - - void initCairo (){ - cairoDev = new Cairo.EGLDevice (egl_display, egl_ctx); - - cairoSurf = new Cairo.GLSurface (cairoDev, egl_surface, 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."); - } - #endregion - - #region cursor - BufferObject boMouseCursor = BufferObject.Zero; - - internal void updateCursor (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; - } - - if (boMouseCursor != BufferObject.Zero) - Gbm.DestroyBuffer (boMouseCursor); - - boMouseCursor = Gbm.CreateBuffer (gbm_device, (int)width, (int)height, - SurfaceFormat.ARGB8888, SurfaceFlags.Cursor64x64 | SurfaceFlags.Write); - - if (boMouseCursor == BufferObject.Zero) - { - Debug.Print("[DRM] Failed to create buffer for mouse cursor."); - return; - } - - // 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.Write(cursor_data); - - unsafe { - Drm.SetCursor (fd_gpu, pEncoder->crtc_id, - boMouseCursor.Handle, boMouseCursor.Width, boMouseCursor.Height, (int)cursor.Xhot, (int)cursor.Yhot); - } - } - #endregion - - int getFbFromBo (BufferObject bo){ - int width = bo.Width; - int height = bo.Height; - int bpp = 32; - int depth = 24; - int stride = bo.Stride; - int hndBO = bo.Handle; - - int fb; - int ret = Drm.ModeAddFB (fd_gpu, width, height,(byte)depth, (byte)bpp, stride, hndBO, out fb); - if (ret != 0) - throw new Exception ("[DRM]: ModeAddFB failed."); - bo.SetUserData ((IntPtr)fb, DestroyFBPtr); - return fb; - } - - public void Run(){ - BufferObject bo; - int fb; - - PollFD fds = new PollFD(); - fds.fd = fd_gpu; - fds.events = PollFlags.In; - - EventContext evctx = new EventContext(); - evctx.version = EventContext.Version; - evctx.page_flip_handler = PageFlipPtr; - - int timeout = -1;//block ? -1 : 0; - - using (Cairo.Context ctx = new Cairo.Context (cairoSurf)) { - ctx.Rectangle (0, 0, width, height); - ctx.SetSourceRGB (0, 0, 0); - ctx.Fill (); - } - - cairoSurf.SwapBuffers (); - - bo = Gbm.LockFrontBuffer (gbm_surface); - fb = getFbFromBo (bo); - - SetScanoutRegion (fb); - drmTimeOut.Restart(); - - while (run && drmTimeOut.ElapsedMilliseconds < 10000){ - BufferObject next_bo; - bool update = false; - - if (updateMousePos) { - lock (Sync) { - updateMousePos = false; - unsafe { - Drm.MoveCursor (fd_gpu, pEncoder->crtc_id, MouseX-8, MouseY-4); - } - } - } - - if (Monitor.TryEnter (CrowInterface.RenderMutex)) { - if (CrowInterface.IsDirty) { - CrowInterface.IsDirty = false; - update = true; - using (Cairo.Context ctx = new Cairo.Context (cairoSurf)) { - using (Cairo.Surface d = new Cairo.ImageSurface (CrowInterface.dirtyBmp, Cairo.Format.Argb32, - width, height, width * 4)) { - ctx.SetSourceSurface (d, 0, 0); - ctx.Operator = Cairo.Operator.Source; - ctx.Paint (); - } - } - } - Monitor.Exit (CrowInterface.RenderMutex); - } - - if (!update) - continue; - update = false; - - cairoSurf.Flush (); - cairoSurf.SwapBuffers (); - - if (Gbm.HasFreeBuffers (gbm_surface) == 0) - throw new Exception ("[GBM]: Out of free buffers."); - - next_bo = Gbm.LockFrontBuffer (gbm_surface); - if (next_bo == BufferObject.Zero) - throw new Exception ("[GBM]: Failed to lock front buffer."); - - fb = getFbFromBo (next_bo); - - unsafe{ - int is_flip_queued = 1; - - while (Drm.ModePageFlip (fd_gpu, pEncoder->crtc_id, fb, PageFlipFlags.FlipEvent, ref is_flip_queued) < 0) { - //Console.WriteLine ("[DRM] Failed to enqueue framebuffer flip."); - continue; - } - - 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) - Drm.HandleEvent (fd_gpu, ref evctx); - else - break; - Thread.Sleep (1); - } - if (is_flip_queued != 0) - Console.WriteLine ("flip canceled"); - - Gbm.ReleaseBuffer (gbm_surface, bo); - //Drm.ModeRmFB(fd_gpu, fb); - - bo = next_bo; - next_bo = BufferObject.Zero; - - } - } - } - - #region rendering - - - - // We only support a SwapInterval of 0 (immediate) - // or 1 (vsynced). - // Todo: add support for SwapInterval of -1 (adaptive). - // This requires a small change in WaitFlip(). - int swap_interval=0; - - readonly IntPtr PageFlipPtr; - readonly PageFlipCallback PageFlip; - - readonly IntPtr DestroyFBPtr; - readonly DestroyUserDataCallback DestroyFB; - - void HandlePageFlip(int fd, int sequence, int tv_sec, int tv_usec, ref int user_data) - { - user_data = 0; - } - - - void HandleDestroyFB(BufferObject bo, IntPtr data) - { - Console.WriteLine ("DestroyFB"); - IntPtr gbm = bo.Device; - int fb = data.ToInt32(); - - if (fb != 0) - Drm.ModeRmFB(fd_gpu, fb); - } - - void SetScanoutRegion(int buffer) - { - unsafe - { - ModeInfo* mode = pConnector->modes; - int connector_id = pConnector->connector_id; - int crtc_id = pEncoder->crtc_id; - - int ret = Drm.ModeSetCrtc (fd_gpu, crtc_id, buffer, 0, 0, &connector_id, 1, mode); - - if (ret != 0) - Debug.Print("[KMS] Drm.ModeSetCrtc{0}, {1}, {2} failed. Error: {3}", - fd_gpu, crtc_id, buffer, ret); - Console.WriteLine ("scanout region set: {0}x{1}", mode->hdisplay, mode->vdisplay); - } - } - #endregion - - #region IDisposable implementation - public void Dispose () - { - cairoDev.Release (); - cairoSurf.Dispose (); - cairoDev.Dispose (); - - // if (fb != 0) - // Drm.ModeRmFB (fd_gpu, fb); - // if (bo != BufferObject.Zero) - // Gbm.ReleaseBuffer (gbm_surface, bo); - // if (next_fb != 0) - // Drm.ModeRmFB (fd_gpu, next_fb); - // if (next_bo != BufferObject.Zero) - // Gbm.ReleaseBuffer (gbm_surface, next_bo); - - if (Egl.GetCurrentContext () == egl_ctx) { - Console.WriteLine ("destroying context"); - Egl.DestroyContext (egl_display, egl_ctx); - }else - Console.WriteLine ("not current"); - - cairoDev.Dispose (); - - unsafe{ - Drm.ModeSetCrtc (fd_gpu, saved_crtc->crtc_id, saved_crtc->buffer_id, - saved_crtc->x, saved_crtc->y, &pConnector->connector_id, 1, &saved_crtc->mode); - Drm.ModeFreeCrtc ((IntPtr)saved_crtc); - } - - Drm.ModeFreeCrtc (Crtc); - Drm.ModeFreeConnector(Connector); - Drm.ModeFreeEncoder(Encoder); - Libc.close(fd_gpu); - -// using(VTControler master = new VTControler()){ -// master.CurrentMode = TTY.Mode.TEXT; -// if (master.CurrentVT != previousVT) { -// master.SwitchTo (previousVT); -// } -// } - } - #endregion - - #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.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) - { - 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(GetMouse(device), LibInput.GetPointerEvent(pevent)); - // break; - // - case InputEventType.PointerButton: - handlePointerButton (LibInput.GetPointerEvent(pevent)); - break; - - case InputEventType.PointerMotion: - handlePointerMotion (LibInput.GetPointerEvent(pevent)); - break; - - // case InputEventType.PointerMotionAbsolute: - // HandlePointerMotionAbsolute(GetMouse(device), 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 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 == ButtonState.Pressed) - CrowInterface.ProcessMouseButtonDown (but); - else - CrowInterface.ProcessMouseButtonUp (but); - } - - KeyModifiers curModifiers = KeyModifiers.None; - - void handleKeyboard(KeyboardEvent e) - { - return; - 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 - } -} - - - - diff --git a/testDrm/src/DisplayResolution.cs b/testDrm/src/DisplayResolution.cs deleted file mode 100644 index 43419408..00000000 --- a/testDrm/src/DisplayResolution.cs +++ /dev/null @@ -1,232 +0,0 @@ -#region --- License --- -/* Licensed under the MIT/X11 license. - * Copyright (c) 2006-2008 the OpenTK team. - * This notice may not be removed. - * See license.txt for licensing detailed licensing details. - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; -#if !MINIMAL -using System.Drawing; -#endif - -namespace OpenTK -{ - /// Contains information regarding a monitor's display resolution. - public class DisplayResolution - { - Rectangle bounds; - int bits_per_pixel; - float refresh_rate; - - #region --- Constructors --- - - internal DisplayResolution() { } - - #region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate) - - // Creates a new DisplayResolution object for the primary DisplayDevice. - internal DisplayResolution(int x, int y, int width, int height, int bitsPerPixel, float refreshRate) - { - // Refresh rate may be zero, since this information may not be available on some platforms. - if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero."); - if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero."); - if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero."); - if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero."); - - this.bounds = new Rectangle(x, y, width, height); - this.bits_per_pixel = bitsPerPixel; - this.refresh_rate = refreshRate; - } - - #endregion - - #region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device) - -#if false - - /// - /// Creates a new DisplayResolution object for the specified DisplayDevice. - /// - /// The requested width in pixels. - /// The requested height in pixels. - /// The requested bits per pixel in bits. - /// The requested refresh rate in hertz. - /// OpenTK will select the closest match between all available resolutions on the specified DisplayDevice. - /// - public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device) - { - // Refresh rate may be zero, since this information may not be available on some platforms. - if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero."); - if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero."); - if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero."); - if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero."); - if (device == null) throw new ArgumentNullException("DisplayDevice", "Must be a valid DisplayDevice"); - - DisplayResolution res = device.SelectResolution(width, height, bitsPerPixel, refreshRate); - - this.width = res.width; - this.height = res.height; - this.bits_per_pixel = res.bits_per_pixel; - this.refresh_rate = res.refresh_rate; - } -#endif - #endregion - - #endregion - - #region --- Public Methods --- - - #region Bounds - - /// - /// Gets a System.Drawing.Rectangle that contains the bounds of this display device. - /// - [Obsolete("This property will return invalid results if a monitor changes resolution. Use DisplayDevice.Bounds instead.")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public Rectangle Bounds - { - get { return bounds; } - } - - #endregion - - #region public int Width - - /// Gets a System.Int32 that contains the width of this display in pixels. - public int Width - { - get { return bounds.Width; } - internal set { bounds.Width = value; } - } - - #endregion - - #region public int Height - - /// Gets a System.Int32 that contains the height of this display in pixels. - public int Height - { - get { return bounds.Height; } - internal set { bounds.Height = value; } - } - - #endregion - - #region public int BitsPerPixel - - /// Gets a System.Int32 that contains number of bits per pixel of this display. Typical values include 8, 16, 24 and 32. - public int BitsPerPixel - { - get { return bits_per_pixel; } - internal set { bits_per_pixel = value; } - } - - #endregion - - #region public float RefreshRate - - /// - /// Gets a System.Single representing the vertical refresh rate of this display. - /// - public float RefreshRate - { - get { return refresh_rate; } - internal set { refresh_rate = value; } - } - - #endregion - - #endregion - - #region --- Overrides --- - - #region public override string ToString() - - /// - /// Returns a System.String representing this DisplayResolution. - /// - /// A System.String representing this DisplayResolution. - public override string ToString() - { - #pragma warning disable 612,618 - return String.Format("{0}x{1}@{2}Hz", Bounds, bits_per_pixel, refresh_rate); - #pragma warning restore 612,618 - } - - #endregion - - #region public override bool Equals(object obj) - - /// Determines whether the specified resolutions are equal. - /// The System.Object to check against. - /// True if the System.Object is an equal DisplayResolution; false otherwise. - public override bool Equals(object obj) - { - if (obj == null) return false; - if (this.GetType() == obj.GetType()) - { - DisplayResolution res = (DisplayResolution)obj; - return - Width == res.Width && - Height == res.Height && - BitsPerPixel == res.BitsPerPixel && - RefreshRate == res.RefreshRate; - } - - return false; - } - - #endregion - - #region public override int GetHashCode() - - /// Returns a unique hash representing this resolution. - /// A System.Int32 that may serve as a hash code for this resolution. - public override int GetHashCode() - { - #pragma warning disable 612,618 - return Bounds.GetHashCode() ^ bits_per_pixel ^ refresh_rate.GetHashCode(); - #pragma warning restore 612,618 - } - - #endregion - - #endregion - - #region --- Operator Overloads --- - - /// - /// Compares two instances for equality. - /// - /// The first instance. - /// The second instance. - /// True, if left equals right; false otherwise. - public static bool operator== (DisplayResolution left, DisplayResolution right) - { - if (((object)left) == null && ((object)right) == null) - return true; - else if ((((object)left) == null && ((object)right) != null) || - (((object)left) != null && ((object)right) == null)) - return false; - return left.Equals(right); - } - - /// - /// Compares two instances for inequality. - /// - /// The first instance. - /// The second instance. - /// True, if left does not equal right; false otherwise. - public static bool operator !=(DisplayResolution left, DisplayResolution right) - { - return !(left == right); - } - - #endregion - } -} diff --git a/testDrm/src/Linux/Bindings/EvdevClass.cs b/testDrm/src/Linux/Bindings/EvdevClass.cs index 4cbd61c9..06e9cdfc 100644 --- a/testDrm/src/Linux/Bindings/EvdevClass.cs +++ b/testDrm/src/Linux/Bindings/EvdevClass.cs @@ -386,21 +386,7 @@ namespace Linux.oldEvDev 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.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) diff --git a/testDrm/src/Linux/DRIControler.cs b/testDrm/src/Linux/DRIControler.cs index 3fc3935e..cb2794f2 100644 --- a/testDrm/src/Linux/DRIControler.cs +++ b/testDrm/src/Linux/DRIControler.cs @@ -172,6 +172,8 @@ namespace Linux.DRI { gbmDev = new GBM.Device (fd_gpu); eglctx = new EGL.Context (gbmDev); + Console.WriteLine (eglctx.Extensions); + Console.WriteLine (eglctx.OffScreenExtensions); try { if (defaultConfiguration ()) Console.WriteLine ("default config ok"); diff --git a/testDrm/src/MouseCursor.cs b/testDrm/src/MouseCursor.cs deleted file mode 100644 index df8cd0cf..00000000 --- a/testDrm/src/MouseCursor.cs +++ /dev/null @@ -1,135 +0,0 @@ -#region License -// -// Cursor.cs -// -// Author: -// Stefanos A. -// -// Copyright (c) 2006-2014 Stefanos Apostolopoulos -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -#endregion - -using System; - -namespace OpenTK -{ - /// - /// Represents a predefined or custom mouse cursor. - /// - public sealed class MouseCursor : WindowIcon - { - static readonly MouseCursor default_cursor = new MouseCursor(); - static readonly MouseCursor empty_cursor = new MouseCursor( - 0, 0, 16, 16, new byte[16 * 16 * 4]); - - int x; - int y; - - MouseCursor() - { - } - - /// - /// Initializes a new instance from a - /// contiguous array of BGRA pixels. - /// Each pixel is composed of 4 bytes, representing B, G, R and A values, - /// respectively. For correct antialiasing of translucent cursors, - /// the B, G and R components should be premultiplied with the A component: - /// - /// B = (byte)((B * A) / 255) - /// G = (byte)((G * A) / 255) - /// R = (byte)((R * A) / 255) - /// - /// - /// The x-coordinate of the cursor hotspot, in the range [0, width] - /// The y-coordinate of the cursor hotspot, in the range [0, height] - /// The width of the cursor data, in pixels. - /// The height of the cursor data, in pixels. - /// - /// A byte array representing the cursor image, - /// laid out as a contiguous array of BGRA pixels. - /// - public MouseCursor(int hotx, int hoty, int width, int height, byte[] data) - : base(width, height, data) - { - if (hotx < 0 || hotx >= Width || hoty < 0 || hoty >= Height) - throw new ArgumentOutOfRangeException(); - - x = hotx; - y = hoty; - } - - /// - /// Initializes a new instance from a - /// contiguous array of BGRA pixels. - /// Each pixel is composed of 4 bytes, representing B, G, R and A values, - /// respectively. For correct antialiasing of translucent cursors, - /// the B, G and R components should be premultiplied with the A component: - /// - /// B = (byte)((B * A) / 255) - /// G = (byte)((G * A) / 255) - /// R = (byte)((R * A) / 255) - /// - /// - /// The x-coordinate of the cursor hotspot, in the range [0, width] - /// The y-coordinate of the cursor hotspot, in the range [0, height] - /// The width of the cursor data, in pixels. - /// The height of the cursor data, in pixels. - /// - /// A pointer to the cursor image, laid out as a contiguous array of BGRA pixels. - /// - public MouseCursor(int hotx, int hoty, int width, int height, IntPtr data) - : base(width, height, data) - { - if (hotx < 0 || hotx >= Width || hoty < 0 || hoty >= Height) - throw new ArgumentOutOfRangeException(); - - x = hotx; - y = hoty; - } - - internal int X { get { return x; } } - internal int Y { get { return y; } } - - /// - /// Gets the default mouse cursor for this platform. - /// - public static MouseCursor Default - { - get - { - return default_cursor; - } - } - - /// - /// Gets an empty (invisible) mouse cursor. - /// - public static MouseCursor Empty - { - get - { - return empty_cursor; - } - } - } -} - diff --git a/testDrm/src/WindowIcon.cs b/testDrm/src/WindowIcon.cs deleted file mode 100644 index 53d2d1f8..00000000 --- a/testDrm/src/WindowIcon.cs +++ /dev/null @@ -1,91 +0,0 @@ -#region License -// -// WindowIcon.cs -// -// Author: -// Stefanos A. -// -// 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 -{ - /// - /// Stores a window icon. A window icon is defined - /// as a 2-dimensional buffer of RGBA values. - /// - public class WindowIcon - { - byte[] data; - int width; - int height; - - /// \internal - /// - /// Initializes a new instance of the class. - /// - internal protected WindowIcon() - { - } - - WindowIcon(int width, int height) - { - if (width < 0 || width > 256 || height < 0 || height > 256) - throw new ArgumentOutOfRangeException(); - - this.width = width; - this.height = height; - } - - internal WindowIcon(int width, int height, byte[] data) - : this(width, height) - { - if (data == null) - throw new ArgumentNullException(); - if (data.Length < Width * Height * 4) - throw new ArgumentOutOfRangeException(); - - this.data = data; - } - - internal WindowIcon(int width, int height, IntPtr data) - : this(width, height) - { - if (data == IntPtr.Zero) - throw new ArgumentNullException(); - - // We assume that width and height are correctly set. - // If they are not, we will read garbage and probably - // crash. - this.data = new byte[width * height * 4]; - Marshal.Copy(data, this.data, 0, this.data.Length); - } - - internal byte[] Data { get { return data; } } - internal int Width { get { return width; } } - internal int Height { get { return height; } } - } -} - diff --git a/testDrm/testDrm.csproj b/testDrm/testDrm.csproj index 9a8d4291..27db51e6 100644 --- a/testDrm/testDrm.csproj +++ b/testDrm/testDrm.csproj @@ -19,13 +19,13 @@ - testDrm.TestApp + testDrm.TestCrow true full false - DEBUG;MEASURE_TIME; + DEBUG; prompt 4 true @@ -37,7 +37,7 @@ - false + true full @@ -55,14 +55,6 @@ - - Code - - - Code - - - @@ -75,6 +67,7 @@ + @@ -113,8 +106,6 @@ PreserveNewest - - - + \ No newline at end of file diff --git a/testDrm/ui/perfMeasures.crow b/testDrm/ui/perfMeasures.crow index 57c97202..efeac653 100755 --- a/testDrm/ui/perfMeasures.crow +++ b/testDrm/ui/perfMeasures.crow @@ -1,4 +1,4 @@ - + diff --git a/testDrm/ui/showcase.crow b/testDrm/ui/showcase.crow new file mode 100755 index 00000000..bf3ea8a3 --- /dev/null +++ b/testDrm/ui/showcase.crow @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.47.3