From: jpbruyere Date: Wed, 31 May 2017 14:20:05 +0000 (+0200) Subject: tests with a c library for speed up X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=335cbb6d7a4409a0a85dd5b65a38afc47ab549e4;p=jp%2Fcrow.git tests with a c library for speed up --- diff --git a/Crow.csproj b/Crow.csproj index 767868b8..f3c08868 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -212,6 +212,8 @@ + + @@ -241,6 +243,7 @@ + diff --git a/Crow.sln b/Crow.sln index aad0db27..446bb1dd 100644 --- a/Crow.sln +++ b/Crow.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testDrm", "testDrm\testDrm. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DRI.net", "..\DRI.net\DRI.net.csproj", "{0189EAEF-DCD4-42F8-A83A-2DEA82926671}" EndProject +Project("{2857B73E-F847-4B02-9238-064979017E93}") = "libcrow", "..\libcrow\libcrow.cproj", "{6CD55032-B8D6-4238-AA91-F9145E1217D4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -20,21 +22,22 @@ Global EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0189EAEF-DCD4-42F8-A83A-2DEA82926671}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0189EAEF-DCD4-42F8-A83A-2DEA82926671}.Debug|Any CPU.Build.0 = Debug|Any CPU {0189EAEF-DCD4-42F8-A83A-2DEA82926671}.Release|Any CPU.ActiveCfg = Release|Any CPU {0189EAEF-DCD4-42F8-A83A-2DEA82926671}.Release|Any CPU.Build.0 = Release|Any CPU {4B57740A-75FB-4978-A8E8-8B1793B7474F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4B57740A-75FB-4978-A8E8-8B1793B7474F}.Debug|Any CPU.Build.0 = Debug|Any CPU {4B57740A-75FB-4978-A8E8-8B1793B7474F}.Release|Any CPU.ActiveCfg = Release|Any CPU {4B57740A-75FB-4978-A8E8-8B1793B7474F}.Release|Any CPU.Build.0 = Release|Any CPU + {6CD55032-B8D6-4238-AA91-F9145E1217D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CD55032-B8D6-4238-AA91-F9145E1217D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CD55032-B8D6-4238-AA91-F9145E1217D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CD55032-B8D6-4238-AA91-F9145E1217D4}.Release|Any CPU.Build.0 = Release|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.Build.0 = Release|Any CPU {A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.Build.0 = Debug|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.Build.0 = Release|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 82f82817..04cf8007 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -79,7 +79,7 @@ namespace Crow internal static FieldInfo miSetCurIface = typeof(GraphicObject).GetField ("currentInterface", BindingFlags.NonPublic | BindingFlags.Instance); internal static MethodInfo miFindByName = typeof (GraphicObject).GetMethod ("FindByName"); internal static MethodInfo miGetGObjItem = typeof(List).GetMethod("get_Item", new Type[] { typeof(Int32) }); - internal static MethodInfo miLoadDefaultVals = typeof (GraphicObject).GetMethod ("loadDefaultValues"); + internal static MethodInfo miLoadDefaultVals = typeof (GraphicObject).GetMethod ("loadDefaultValues", BindingFlags.NonPublic | BindingFlags.Instance); internal static PropertyInfo piStyle = typeof (GraphicObject).GetProperty ("Style"); internal static MethodInfo miGetLogicalParent = typeof(GraphicObject).GetProperty("LogicalParent").GetGetMethod(); internal static MethodInfo miGetDataSource = typeof(GraphicObject).GetProperty("DataSource").GetGetMethod (); diff --git a/src/Crow.Native/LibCrow.cs b/src/Crow.Native/LibCrow.cs new file mode 100644 index 00000000..3b031adf --- /dev/null +++ b/src/Crow.Native/LibCrow.cs @@ -0,0 +1,57 @@ +// +// LibCrow.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.Runtime.InteropServices; + +namespace Crow.Native +{ + internal static class LibCrow + { + #region PINVOKE + const string lib = "libcrow"; + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern IntPtr crow_context_create (); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern void crow_context_destroy (IntPtr ctx); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern void crow_context_process_layouting (IntPtr layCtx); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern void crow_context_process_clipping (IntPtr ctx); + + [DllImport(lib)] + unsafe internal static extern crow_object_t* crow_object_create(); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern void crow_object_destroy(crow_object_t* go); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern void crow_object_set_type (crow_object_t* go, CrowType objType); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern byte crow_object_do_layout (crow_object_t* go, LayoutingType layout); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + unsafe internal static extern void crow_object_register_layouting (crow_object_t* go, LayoutingType layout); + #endregion + } +} + diff --git a/src/Crow.Native/crow_object_t.cs b/src/Crow.Native/crow_object_t.cs new file mode 100644 index 00000000..5d8fb1b7 --- /dev/null +++ b/src/Crow.Native/crow_object_t.cs @@ -0,0 +1,86 @@ +// +// crow_object_t.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.Runtime.InteropServices; +using System; + +namespace Crow.Native { + public enum CrowType : byte { + Simple, + Container, + Group, + Stack + } + + [StructLayout(LayoutKind.Sequential)] + unsafe public struct crow_object_t { + public CrowType TypeObj; + public IntPtr Context; + public int ChildrenCount; + public crow_object_t* Parent; + public crow_object_t** Children; + public int Left; + public int Top; + public Measure Width; + public Measure Height; + public int Margin; + public Size MinimumSize; + public Size MaximumSize; + public byte Visible; + /// if true, content has to be recreated + public byte IsDirty; + public byte InClippingPool; + public IntPtr Clipping; + public LayoutingType RegisteredLayoutings; + /// + /// Current size and position computed during layouting pass + /// + public Rectangle Slot; + public Size ContentSize; + /// + /// keep last slot components for each layouting pass to track + /// changes and trigger update of other component accordingly + /// + public Rectangle LastSlot; + /// + /// keep last slot painted on screen to clear traces if moved or resized + /// TODO: we should ensure the whole parsed widget tree is the last painted + /// version to clear effective oldslot if parents have been moved or resized. + /// IDEA is to add a ScreenCoordinates function that use only lastPaintedSlots + /// + public Rectangle LastPaintedSlot; + public VerticalAlignment VerticalAlignment; + public HorizontalAlignment HorizontalAlignment; + public IntPtr bmp; + + public IntPtr MeasureRawSize; + public IntPtr UpdateLayout; + public IntPtr OnLayoutChanged; + public IntPtr OnChildLayoutChanged; + public IntPtr ChildrenLayoutingConstraints; + public IntPtr OnDraw; + + } +} \ No newline at end of file diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 8004e950..065019d0 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -67,7 +67,6 @@ namespace Crow #endregion #region GraphicObject Overrides - public override bool ArrangeChildren { get { return true; } } public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) { //Prevent child repositionning in the direction of stacking diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index f8069337..9907810c 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -36,65 +36,20 @@ using System.Linq; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; +using Crow.Native; namespace Crow { - [StructLayout(LayoutKind.Sequential)] - unsafe public struct NativeGO { - public NativeGO* Parent; - public int Left; - public int Top; - public Measure Width; - public Measure Height; - public int Margin; - public Size MinimumSize; - public Size MaximumSize; - byte visible; - public LayoutingType RegisteredLayoutings; - /// - /// Current size and position computed during layouting pass - /// - public Rectangle Slot; - /// - /// keep last slot components for each layouting pass to track - /// changes and trigger update of other component accordingly - /// - public Rectangle LastSlot; - /// - /// keep last slot painted on screen to clear traces if moved or resized - /// TODO: we should ensure the whole parsed widget tree is the last painted - /// version to clear effective oldslot if parents have been moved or resized. - /// IDEA is to add a ScreenCoordinates function that use only lastPaintedSlots - /// - public Rectangle LastPaintedSlot; - public VerticalAlignment VerticalAlignment; - public HorizontalAlignment HorizontalAlignment; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void LayoutChangedCallBack (LayoutingType lt); - unsafe public bool Visible { - get { return visible > 0; } - set { - if (value) - visible = 1; - else - visible = 0; - } - } - } public class GraphicObject : IValueChange, IDisposable { - #region PINVOKE - const string lib = "/home/jp/devel/testsharedlib/bin/Debug/libcrow.so"; - [DllImport(lib)] - unsafe static extern NativeGO* CreateGO(); - [DllImport(lib)] - unsafe static extern void DestroyGO(NativeGO* go); - #endregion - internal static ulong currentUid = 0; internal ulong uid = 0; - unsafe internal NativeGO* nativeHnd; + unsafe internal crow_object_t* nativeHnd; #region IValueChange implementation public event EventHandler ValueChanged; @@ -109,13 +64,18 @@ namespace Crow public GraphicObject () { unsafe { - nativeHnd = CreateGO (); + nativeHnd = LibCrow.crow_object_create (); + LibCrow.crow_object_set_type (nativeHnd, CrowType.Simple); + nativeHnd->Context = Interface.CurrentInterface.layoutingCtx; + //nativeHnd->OnLayoutChanged = Marshal.GetFunctionPointerForDelegate((LayoutChangedCallBack)OnLayoutChanges); } #if DEBUG uid = currentUid; currentUid++; #endif } + internal protected GraphicObject (bool isInterface){ + } #endregion /// @@ -124,6 +84,7 @@ namespace Crow public virtual void Initialize(){ if (currentInterface == null) currentInterface = Interface.CurrentInterface; + loadDefaultValues (); } #region private fields @@ -157,8 +118,7 @@ namespace Crow public bool IsQueueForRedraw = false; /// drawing Cache bitmap public byte[] bmp; - /// if true, content has to be recreated - public bool IsDirty = true; + /// /// This size is computed on each child' layout changes. /// In stacking widget, it is used to compute the remaining space for the stretched @@ -176,7 +136,7 @@ namespace Crow /// /// Parent in the graphic tree, used for rendering and layouting /// - [XmlIgnore]public virtual GraphicObject Parent { + [XmlIgnore]unsafe public virtual GraphicObject Parent { get { return parent; } set { if (parent == value) @@ -184,7 +144,10 @@ namespace Crow DataSourceChangeEventArgs e = new DataSourceChangeEventArgs (parent, value); lock (this) { parent = value; - //nativeHnd->Parent = value?.nativeHnd; + if (parent == null) + nativeHnd->Parent = null; + else + nativeHnd->Parent = value.nativeHnd; } onParentChanged (this, e); @@ -569,12 +532,15 @@ namespace Crow } [XmlAttributeAttribute][DefaultValue(true)] public virtual bool Visible { - get { unsafe { return nativeHnd->Visible;} } + get { unsafe { return nativeHnd->Visible>0;} } set { if (value == Visible) return; unsafe { - nativeHnd->Visible = value; + if (value) + nativeHnd->Visible = 1; + else + nativeHnd->Visible = 0; } RegisterForLayouting (LayoutingType.Sizing); @@ -585,6 +551,16 @@ namespace Crow NotifyValueChanged ("Visible", Visible); } } + [XmlIgnore]unsafe public bool IsDirty { + get { return nativeHnd->IsDirty>0; } + set { + if (value) + nativeHnd->IsDirty = 1; + else + nativeHnd->IsDirty = 0; + } + } + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool IsEnabled { get { return isEnabled; } @@ -686,7 +662,7 @@ namespace Crow #region Default and Style Values loading /// Loads the default values from XML attributes default - public void loadDefaultValues() + internal void loadDefaultValues() { #if DEBUG_LOAD Debug.WriteLine ("LoadDefValues for " + this.ToString ()); @@ -799,12 +775,12 @@ namespace Crow il.Emit(OpCodes.Ret); #endregion - try { + //try { Interface.DefaultValuesLoader[styleKey] = (Interface.LoaderInvoker)dm.CreateDelegate(typeof(Interface.LoaderInvoker)); Interface.DefaultValuesLoader[styleKey] (this); - } catch (Exception ex) { - throw new Exception ("Error applying style <" + styleKey + ">:", ex); - } +// } catch (Exception ex) { +// throw new Exception ("Error applying style <" + styleKey + ">:", ex); +// } } bool getDefaultEvent(EventInfo ei, List