]> O.S.I.I.S - jp/crow.git/commitdiff
tests with a c library for speed up
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 31 May 2017 14:20:05 +0000 (16:20 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 31 May 2017 14:20:05 +0000 (16:20 +0200)
14 files changed:
Crow.csproj
Crow.sln
src/CompilerServices/CompilerServices.cs
src/Crow.Native/LibCrow.cs [new file with mode: 0644]
src/Crow.Native/crow_object_t.cs [new file with mode: 0644]
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/TabView.cs
src/GraphicObjects/Wrapper.cs
src/Interface.cs
src/LayoutingQueueItem.cs
testDrm/TestCrow.cs
testDrm/testDrm.csproj
testDrm/ui/go.crow

index 767868b8120352491a88a978523827632e5dc1b8..f3c088682439711f70a489e6c37ccbf9441d7b20 100644 (file)
     <Compile Include="src\Mono.Cairo\EGLDevice.cs" />
     <Compile Include="src\Mono.Cairo\DRMDevice.cs" />
     <Compile Include="src\Mono.Cairo\DRMSurface.cs" />
+    <Compile Include="src\Crow.Native\crow_object_t.cs" />
+    <Compile Include="src\Crow.Native\LibCrow.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Folder Include="src\rsvg\" />
     <Folder Include="src\IML\" />
     <Folder Include="Icons\" />
+    <Folder Include="src\Crow.Native\" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Images\Icons\updown.svg" />
index aad0db277efd4a3727d2f2ca752e9f89d91802fd..446bb1ddc77fe7ce4915afc9c7e01c766656e98c 100644 (file)
--- 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
index 82f828179b0283ed2e1dbebe3996ca49f65dcca9..04cf80076b5122d6bfdeb74ebab9e3c924c2cfc9 100644 (file)
@@ -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<GraphicObject>).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 (file)
index 0000000..3b031ad
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// LibCrow.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.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 (file)
index 0000000..5d8fb1b
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// crow_object_t.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.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;
+               /// <summary>if true, content has to be recreated</summary>
+               public byte IsDirty;
+               public byte InClippingPool;
+               public IntPtr Clipping;
+               public LayoutingType RegisteredLayoutings;
+               /// <summary>
+               /// Current size and position computed during layouting pass
+               /// </summary>
+               public Rectangle Slot;
+               public Size ContentSize;
+               /// <summary>
+               /// keep last slot components for each layouting pass to track
+               /// changes and trigger update of other component accordingly
+               /// </summary>
+               public Rectangle LastSlot;
+               /// <summary>
+               /// 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
+               /// </summary>
+               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
index 8004e9503760bb8b83fddb1973f94aa9c72fad72..065019d039ec1b72212b526547637743a56d9ea1 100644 (file)
@@ -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
index f8069337a6c2f183fd0f39a040fe53bd66881ff6..9907810c1f97a16f63ea1fe93ff3cee130f5ac8a 100644 (file)
@@ -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;
-               /// <summary>
-               /// Current size and position computed during layouting pass
-               /// </summary>
-               public Rectangle Slot;
-               /// <summary>
-               /// keep last slot components for each layouting pass to track
-               /// changes and trigger update of other component accordingly
-               /// </summary>
-               public Rectangle LastSlot;
-               /// <summary>
-               /// 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
-               /// </summary>
-               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<ValueChangeEventArgs> 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
 
                /// <summary>
@@ -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;
                /// <summary>drawing Cache bitmap</summary>
                public byte[] bmp;
-               /// <summary>if true, content has to be recreated</summary>
-               public bool IsDirty = true;
+
                /// <summary>
                /// 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
                /// <summary>
                /// Parent in the graphic tree, used for rendering and layouting
                /// </summary>
-               [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
                /// <summary> Loads the default values from XML attributes default </summary>
-               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<Style> styling,
                        out string expression){
@@ -922,55 +898,20 @@ namespace Crow
                /// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary>
                public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){
                }
-               public virtual bool ArrangeChildren { get { return false; } }
-               public virtual void RegisterForLayouting(LayoutingType layoutType){
-                       if (Parent == null)
-                               return;
-                       lock (CurrentInterface.LayoutMutex) {
-                               //prevent queueing same LayoutingType for this
-                               layoutType &= (~RegisteredLayoutings);
-
-                               if (layoutType == LayoutingType.None)
-                                       return;
-                               //dont set position for stretched item
-                               if (Width == Measure.Stretched)
-                                       layoutType &= (~LayoutingType.X);
-                               if (Height == Measure.Stretched)
-                                       layoutType &= (~LayoutingType.Y);
 
-                               if (!ArrangeChildren)
-                                       layoutType &= (~LayoutingType.ArrangeChildren);
-
-                               //apply constraints depending on parent type
-                               Parent.ChildrenLayoutingConstraints (ref layoutType);
-
-//                             //prevent queueing same LayoutingType for this
-//                             layoutType &= (~RegisteredLayoutings);
-
-                               if (layoutType == LayoutingType.None)
-                                       return;
-
-                               //enqueue LQI LayoutingTypes separately
-                               if (layoutType.HasFlag (LayoutingType.Width))
-                                       CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this));
-                               if (layoutType.HasFlag (LayoutingType.Height))
-                                       CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this));
-                               if (layoutType.HasFlag (LayoutingType.X))
-                                       CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this));
-                               if (layoutType.HasFlag (LayoutingType.Y))
-                                       CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this));
-                               if (layoutType.HasFlag (LayoutingType.ArrangeChildren))
-                                       CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this));
-                       }
+               unsafe public virtual void RegisterForLayouting(LayoutingType layoutType){
+                       LibCrow.crow_object_register_layouting (this.nativeHnd, layoutType);
                }
 
                /// <summary> trigger dependant sizing component update </summary>
                public virtual void OnLayoutChanges(LayoutingType  layoutType)
                {
                        #if DEBUG_LAYOUTING
-                       CurrentInterface.currentLQI.Slot = LastSlots;
-                       CurrentInterface.currentLQI.NewSlot = Slot;
-                       Debug.WriteLine ("\t\t{0} => {1}",LastSlots,Slot);
+//                     CurrentInterface.currentLQI.Slot = LastSlots;
+//                     CurrentInterface.currentLQI.NewSlot = Slot;
+                       unsafe{
+                       Debug.WriteLine ("\t\t{0} => {1}", nativeHnd->LastSlot, nativeHnd->Slot);
+                       }
                        #endif
 
                        switch (layoutType) {
@@ -980,8 +921,13 @@ namespace Crow
                        case LayoutingType.Height:
                                RegisterForLayouting (LayoutingType.Y);
                                break;
+                       case LayoutingType.X:
+                               Console.WriteLine (Name);
+                               break;
                        }
-                       LayoutChanged.Raise (this, new LayoutingEventArgs (layoutType));
+
+
+                       //LayoutChanged.Raise (this, new LayoutingEventArgs (layoutType));
                }
                internal protected void raiseLayoutChanged(LayoutingEventArgs e){
                        LayoutChanged.Raise (this, e);
@@ -993,40 +939,23 @@ namespace Crow
                /// met and LQI has to be re-queued</returns>
                unsafe public virtual bool UpdateLayout (LayoutingType layoutType)
                {
+                       if (LibCrow.crow_object_do_layout (nativeHnd, layoutType)==0)
+                               return false;
+                       
                        //unset bit, it would be reset if LQI is re-queued
-                       RegisteredLayoutings &= (~layoutType);
+                       //RegisteredLayoutings &= (~layoutType);
 
                        switch (layoutType) {
-                       case LayoutingType.X:
-                               if (Left == 0) {
-
-                                       if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width) ||
-                                           RegisteredLayoutings.HasFlag (LayoutingType.Width))
-                                               return false;
-
-                                       switch (HorizontalAlignment) {
-                                       case HorizontalAlignment.Left:
-                                               nativeHnd->Slot.X = 0;
-                                               break;
-                                       case HorizontalAlignment.Right:
-                                               nativeHnd->Slot.X = Parent.ClientRectangle.Width - nativeHnd->Slot.Width;
-                                               break;
-                                       case HorizontalAlignment.Center:
-                                               nativeHnd->Slot.X = Parent.ClientRectangle.Width / 2 - nativeHnd->Slot.Width / 2;
-                                               break;
-                                       }
-                               } else
-                                       nativeHnd->Slot.X = Left;
-                               
-                               if (nativeHnd->LastSlot.X == nativeHnd->Slot.X)
-                                       break;
-
-                               IsDirty = true;
-
-                               OnLayoutChanges (layoutType);
-
-                               nativeHnd->LastSlot.X = nativeHnd->Slot.X;
-                               break;
+//                     case LayoutingType.X:                           
+//                             if (nativeHnd->LastSlot.X == nativeHnd->Slot.X)
+//                                     break;
+//
+//                             IsDirty = true;
+//
+//                             OnLayoutChanges (layoutType);
+//
+//                             nativeHnd->LastSlot.X = nativeHnd->Slot.X;
+//                             break;
                        case LayoutingType.Y:
                                if (Top == 0) {
 
@@ -1396,7 +1325,7 @@ namespace Crow
                                return;
                        Clipping.Dispose ();
                        unsafe{
-                               DestroyGO (nativeHnd);
+                               LibCrow.crow_object_destroy (nativeHnd);
                        }
                        disposed = true;
                }
index 93338fc2e7f16bdded268d657b08bce882762034..83e859eae950e34d831038629182fb91d41c1e40 100644 (file)
@@ -114,7 +114,6 @@ namespace Crow
                        else
                                SelectedTab = selectedTab;
                }
-               public override bool ArrangeChildren { get { return true; } }
                unsafe public override bool UpdateLayout (LayoutingType layoutType)
                {
                        RegisteredLayoutings &= (~layoutType);
index e22b922dc96df2ab8ae5f8fd82c535aad647c37f..cecf321adf57b87516a17e673571b102ddefaf18 100644 (file)
@@ -199,8 +199,8 @@ namespace Crow
                public override void OnLayoutChanges (LayoutingType layoutType)
                {
                        #if DEBUG_LAYOUTING
-                       CurrentInterface.currentLQI.Slot = LastSlots;
-                       CurrentInterface.currentLQI.Slot = Slot;
+//                     CurrentInterface.currentLQI.Slot = LastSlots;
+//                     CurrentInterface.currentLQI.Slot = Slot;
                        #endif
                        switch (layoutType) {
                        case LayoutingType.Width:
index 6887c7dd035a74dd7cdeac06635edff43a83f81e..390ecd660586b83c9f1c83a0a436f51f1c551974 100644 (file)
@@ -35,6 +35,7 @@ using System.Xml;
 using System.Xml.Serialization;
 using Cairo;
 using System.Globalization;
+using Crow.Native;
 
 namespace Crow
 {
@@ -63,8 +64,13 @@ namespace Crow
                        FontRenderingOptions.HintStyle = HintStyle.Medium;
                        FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb;
                }
-               public Interface(){
+               public Interface() : base (true){
                        CurrentInterface = this;
+                       layoutingCtx = LibCrow.crow_context_create ();
+                       unsafe {
+                               nativeHnd = LibCrow.crow_object_create ();
+                       }
+
                        CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
                }
                #endregion
@@ -105,6 +111,7 @@ namespace Crow
                internal static Interface CurrentInterface;
                internal Stopwatch clickTimer = new Stopwatch();
                internal GraphicObject eligibleForDoubleClick = null;
+               internal IntPtr layoutingCtx = IntPtr.Zero;
                #endregion
 
                #region Events
@@ -142,10 +149,6 @@ namespace Crow
                /// Store loaded resources instances shared among controls to reduce memory footprint
                /// </summary>
                public Dictionary<string,object> Ressources = new Dictionary<string, object>();
-               /// <summary>The Main layouting queue.</summary>
-               public Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem> ();
-               /// <summary>Store discarded lqi between two updates</summary>
-               public Queue<LayoutingQueueItem> DiscardQueue;
                /// <summary>Main drawing queue, holding layouted controls</summary>
                public Queue<GraphicObject> DrawingQueue = new Queue<GraphicObject>();
                public string Clipboard;//TODO:use object instead for complex copy paste
@@ -274,11 +277,11 @@ namespace Crow
                /// not added to the GraphicTree</summary>
                public GraphicObject Load (string path)
                {
-                       try {
+                       //try {
                                return GetInstantiator (path).CreateInstance (this);
-                       } catch (Exception ex) {
-                               throw new Exception ("Error loading <" + path + ">:", ex);
-                       }
+                       //} catch (Exception ex) {
+                       //      throw new Exception ("Error loading <" + path + ">:", ex);
+                       //}
                }
                /// <summary>Fetch it from cache or create it</summary>
                public static Instantiator GetInstantiator(string path){
@@ -453,24 +456,10 @@ namespace Crow
                        #if MEASURE_TIME
                        layoutingMeasure.StartCycle();
                        #endif
-
                        if (Monitor.TryEnter (LayoutMutex)) {
-                               DiscardQueue = new Queue<LayoutingQueueItem> ();
-                               //Debug.WriteLine ("======= Layouting queue start =======");
-                               LayoutingQueueItem lqi;
-                               while (LayoutingQueue.Count > 0) {
-                                       lqi = LayoutingQueue.Dequeue ();
-                                       #if DEBUG_LAYOUTING
-                                       currentLQI = lqi;
-                                       curLQIsTries.Add(currentLQI);
-                                       #endif
-                                       lqi.ProcessLayouting ();
-                               }
-                               LayoutingQueue = DiscardQueue;
+                               LibCrow.crow_context_process_layouting (layoutingCtx);
                                Monitor.Exit (LayoutMutex);
-                               DiscardQueue = null;
                        }
-
                        #if MEASURE_TIME
                        layoutingMeasure.StopCycle();
                        #endif
@@ -482,14 +471,7 @@ namespace Crow
                        #if MEASURE_TIME
                        clippingMeasure.StartCycle();
                        #endif
-                       GraphicObject g = null;
-                       while (DrawingQueue.Count > 0) {
-                               lock (DrawingQueue)
-                                       g = DrawingQueue.Dequeue ();
-                               lock (g)
-                                       g.ClippingRegistration ();
-                       }
-
+                       LibCrow.crow_context_process_layouting (layoutingCtx);
                        #if MEASURE_TIME
                        clippingMeasure.StopCycle();
                        #endif
@@ -661,6 +643,10 @@ namespace Crow
 
                public void ProcessResize(Rectangle bounds){
                        lock (UpdateMutex) {
+                               unsafe {
+                                       nativeHnd->Slot.Width = bounds.Width;
+                                       nativeHnd->Slot.Height = bounds.Height;
+                               }
                                clientRectangle = bounds;
                                int stride = 4 * ClientRectangle.Width;
                                int bmpSize = Math.Abs (stride) * ClientRectangle.Height;
@@ -892,7 +878,6 @@ namespace Crow
                public override void RegisterClip(Rectangle r){
                        clipping.UnionRectangle (r);
                }
-               public override bool ArrangeChildren { get { return false; }}
                public override void RegisterForLayouting (LayoutingType layoutType) { }
                public override bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); }
                public override Rectangle ContextCoordinates (Rectangle r) { return r;}
@@ -913,10 +898,18 @@ namespace Crow
                }
                public override Measure Height {
                        set { throw new NotImplementedException (); }
-                       get { return clientRectangle.Height;    }
+                       get { return clientRectangle.Height; }
                }
                public override bool MouseIsIn (Point m) => true;
 
+               #if DEBUG
+               public void DumpTo (string path) {
+                       using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
+                               surf.WriteToPng (path);
+                       }
+               }
+               #endif
+
                #if MEASURE_TIME
                public PerformanceMeasure clippingMeasure = new PerformanceMeasure("Clipping", 100);
                public PerformanceMeasure layoutingMeasure = new PerformanceMeasure("Layouting", 100);
@@ -933,8 +926,24 @@ namespace Crow
                //              }
                public LayoutingQueueItem currentLQI;
                #else
-               public List<LQIList> LQIs = null;//still create the var for CrowIDE
+               //public List<LQIList> LQIs = null;//still create the var for CrowIDE
                #endif
+               bool disposed = false;
+               protected override void Dispose (bool disposing)
+               {
+                       if (disposed)
+                               return;
+
+                       if (disposing) {
+                               clipping.Dispose ();
+                       }
+
+                       LibCrow.crow_context_destroy (layoutingCtx);
+
+                       disposed = true;
+
+                       base.Dispose (disposing);
+               }
        }
 }
 
index 7914072000c8f39ca1ed53ddf96a7a829a069681..8bc2550be805b05b78bf5324a3fb5535350cd596 100644 (file)
@@ -45,128 +45,5 @@ namespace Crow
                ArrangeChildren = 0x10,
                All = 0xFF
        }
-
-       /// <summary>
-       /// Element class of the LayoutingQueue
-       /// </summary>
-       [StructLayout(LayoutKind.Sequential)]
-       public struct LayoutingQueueItem
-       {
-               /// <summary> Instance of widget to be layouted</summary>
-               public GraphicObject Layoutable;
-               /// <summary> Bitfield containing the element of the layout to performs (x|y|width|height)</summary>
-               public LayoutingType LayoutType;
-               /// <summary> Unsuccessfull UpdateLayout and requeueing count </summary>
-               public int LayoutingTries, DiscardCount;
-
-               #if DEBUG_LAYOUTING
-               public Stopwatch LQITime;
-               public GraphicObject graphicObject {
-                       get { return Layoutable as GraphicObject; }
-               }
-               public string Name {
-                       get { return graphicObject.Name; }
-               }
-               public string FullName {
-                       get { return graphicObject.ToString(); }
-               }
-               public Measure Width {
-                       get { return graphicObject.Width; }
-               }
-               public Measure Height {
-                       get { return graphicObject.Height; }
-               }
-               public Rectangle Slot, NewSlot;
-               #endif
-
-               #region CTOR
-               public LayoutingQueueItem (LayoutingType _layoutType, GraphicObject _graphicObject)
-               {                       
-                       LayoutType = _layoutType;
-                       Layoutable = _graphicObject;
-                       Layoutable.RegisteredLayoutings |= LayoutType;
-                       LayoutingTries = 0;
-                       DiscardCount = 0;
-                       #if DEBUG_LAYOUTING
-                       LQITime = new Stopwatch();
-                       Slot = Rectangle.Empty;
-                       NewSlot = Rectangle.Empty;
-                       Debug.WriteLine ("\tRegister => " + this.ToString ());
-                       #endif
-               }
-               #endregion
-
-
-               public void ProcessLayouting()
-               {
-                       if (Layoutable.Parent == null) {//TODO:improve this
-                               //cancel layouting for object without parent, maybe some were in queue when
-                               //removed from a listbox
-                               #if DEBUG_LAYOUTING
-                               Debug.WriteLine ("ERROR: processLayouting, no parent for: " + this.ToString ());
-                               #endif
-                               return;
-                       }
-                       #if DEBUG_LAYOUTING
-                       LQITime.Start();
-                       Debug.WriteLine ("=> " + this.ToString ());
-                       #endif
-                       LayoutingTries++;
-                       if (!Layoutable.UpdateLayout (LayoutType)) {
-                               #if DEBUG_LAYOUTING
-                               Debug.WriteLine ("\t\tRequeued");
-                               #endif
-                               if (LayoutingTries < Interface.MaxLayoutingTries) {
-                                       Layoutable.RegisteredLayoutings |= LayoutType;
-                                       Layoutable.CurrentInterface.LayoutingQueue.Enqueue (this);
-                               } else if (DiscardCount < Interface.MaxDiscardCount) {
-                                       #if DEBUG_LAYOUTING
-                                       Debug.WriteLine ("\t\tDiscarded");
-                                       #endif
-                                       LayoutingTries = 0;
-                                       DiscardCount++;
-                                       Layoutable.RegisteredLayoutings |= LayoutType;
-                                       Layoutable.CurrentInterface.DiscardQueue.Enqueue (this);
-                               }
-                               #if DEBUG_LAYOUTING
-                               else
-                                       Debug.WriteLine ("\tDELETED    => " + this.ToString ());
-                               #endif
-                       }
-                       #if DEBUG_LAYOUTING
-                       else{
-                               if (LayoutingTries > 2 || DiscardCount > 0)
-                                       Debug.WriteLine (this.ToString ());
-                       }
-                       LQITime.Stop();
-                       #endif
-               }
-
-               public static implicit operator GraphicObject(LayoutingQueueItem queueItem)
-               {
-                       return queueItem.Layoutable as GraphicObject;
-               }
-               public static implicit operator LayoutingType(LayoutingQueueItem lqi)
-               {
-                       return lqi.LayoutType;
-               }
-               public override string ToString ()
-               {
-                       #if DEBUG_LAYOUTING
-                       return string.Format ("{2};{3};{4} {1}->{0}", LayoutType,Layoutable.ToString(),
-                               LayoutingTries,DiscardCount,LQITime.ElapsedTicks);
-                       #else
-                       return string.Format ("{2};{3} {1}->{0}", LayoutType,Layoutable.ToString(),
-                               LayoutingTries, DiscardCount);
-                       #endif
-               }
-       }
-       public class LQIList : List<LayoutingQueueItem>{
-//             #if DEBUG_LAYOUTING
-//             public List<LayoutingQueueItem> GetRootLQIs(){
-//                     return this.Where (lqi => lqi.wasTriggeredBy == null).ToList ();
-//             }
-//             #endif
-       }
 }
 
index 3eaa2656f09b471e64ec054d4dc660b35c29e001..17e3353a933e7b2e568abf311175fdb8684687b5 100644 (file)
@@ -27,51 +27,46 @@ using System;
 using Crow;
 using System.Runtime.InteropServices;
 using System.Diagnostics;
+using System.Runtime.CompilerServices;
 
 namespace testDrm
 {
        public class TestCrow
        {
+               //const string lib = "/mnt/data2/devel/crow/libcrow/bin/Debug/libcrow.so";
                const string lib = "/home/jp/devel/testsharedlib/bin/Debug/libcrow.so";
 
-               [DllImport(lib)]
-               unsafe static extern Rectangle* allocate();
+               [StructLayout(LayoutKind.Sequential)]
+               public struct testStruct {
+                       public object instance;
+                       public int a;
+                       public int b;
+               }
 
-               [DllImport(lib)]
-               public static extern void update (int w, int h);
+               public class testClass {
+                       public string alpha = "this is a test string";
+                       public int a = 10,b=20;
+               }
 
+               [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern void testAppDomain();
 
-               unsafe static Rectangle* rect;
+               [DllImport(lib, CallingConvention = CallingConvention.Cdecl)]
+               internal static extern int gimmePI (ref testStruct t);
 
-               unsafe static void Main(){
-                       const int count = 10000;
-                       rect = allocate();
-                       Console.WriteLine ("function update");
-                       Stopwatch sw = Stopwatch.StartNew ();
-                       for (int i = 0; i < count; i++) {
-                               update (150, 160);      
-                       }
-                       sw.Stop ();
-                       Console.WriteLine ("{0} updates in {1} ticks and {2} ms", count, sw.ElapsedTicks, sw.ElapsedMilliseconds);
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern int gimme (ref testStruct t);
 
-                       Console.WriteLine ("field update");
-                       sw.Restart ();
-                       for (int i = 0; i < count; i++) {
-                               rect->Height = 200;
-                               rect->Width = 250;
-                       }
-                       sw.Stop ();
-                       Console.WriteLine ("{0} updates in {1} ticks and {2} ms", count, sw.ElapsedTicks, sw.ElapsedMilliseconds);
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern object UnsafeGetValue (object obj);
 
-                       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 ();
+               static void Main(){
+                       using (Interface iface = new Interface ()) {
+                               iface.ProcessResize (new Rectangle (0, 0, 1024, 768));
+                               iface.LoadInterface ("#testDrm.ui.go.crow");
+                               iface.Update ();
+                               iface.DumpTo ("/home/jp/test.png");
+                       }
                }
        }
 }
index 2cf19157770df3992b0f7ab90bd41cfb3d51dcc9..c53ef6c297049694da874f1768d21b7ad5b983e9 100644 (file)
@@ -19,7 +19,7 @@
         <Command type="Execute" command="${TargetName}" workingdir="${SolutionDir}/build/${ProjectConfigName}" />
       </CustomCommands>
     </CustomCommands>
-    <StartupObject>testDrm.TestApp</StartupObject>
+    <StartupObject>testDrm.TestCrow</StartupObject>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <Externalconsole>true</Externalconsole>
     <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath>
-    <OutputPath>$(SolutionDir)build\Debug</OutputPath>
+    <OutputPath>$(SolutionDir)build\$(Configuration)</OutputPath>
     <CustomCommands>
       <CustomCommands>
-        <Command type="BeforeExecute" command="sudo setcap CAP_SYS_ADMIN=+ep ${TargetName}" workingdir="${SolutionDir}/build/${ProjectConfigName}" />
-        <Command type="Execute" command="${TargetName}" workingdir="${SolutionDir}/build/${ProjectConfigName}" pauseExternalConsole="True" />
+        <Command type="Execute" command="${TargetName}" workingdir="${SolutionDir}/build/${ProjectConfigName}" externalConsole="True" pauseExternalConsole="True" />
       </CustomCommands>
     </CustomCommands>
-    <Externalconsole>true</Externalconsole>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>full</DebugType>
@@ -47,7 +46,7 @@
     <ConsolePause>false</ConsolePause>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath>
-    <OutputPath>$(SolutionDir)build\Release</OutputPath>
+    <OutputPath>$(SolutionDir)build\$(Configuration)</OutputPath>
   </PropertyGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>
index c3eda9ccb79013f676ad13c7c23ae49155f2e330..7f42e136cb08eb34e21091c8acebacc88702bc95 100755 (executable)
@@ -1,2 +1,2 @@
 <?xml version="1.0"?>
-<GraphicObject Width="200" Height="200" Background="Mantis"/>
\ No newline at end of file
+<GraphicObject Width="Stretched" Height="Stretched" Background="Mantis"/>
\ No newline at end of file