]> O.S.I.I.S - jp/crow.git/commitdiff
lock Interface when update
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 1 Mar 2016 12:58:35 +0000 (13:58 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 1 Mar 2016 12:58:35 +0000 (13:58 +0100)
src/Interface.cs

index d82516b0c3fa196480fb7d4c3373416378667ca8..36ac681ded82abd848689d30b60ca12956e9b71e 100644 (file)
@@ -43,7 +43,7 @@ namespace Crow
                public LoaderDelegatePrototype LoadInterfaceDelegate;
 
                #region CTOR
-               static Interface(){                     
+               static Interface(){
                        Interface.LoadCursors ();
                }
                public Interface(){
@@ -106,7 +106,7 @@ namespace Crow
                                try {
                                        stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
                                } catch{}
-                               if (stream == null)//try to find ressource in Crow assembly                             
+                               if (stream == null)//try to find ressource in Crow assembly
                                        stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId);
                                if (stream == null)
                                        throw new Exception ("Resource not found: " + path);
@@ -282,93 +282,92 @@ namespace Crow
 
 
                public void Update(){
-                       if (mouseRepeatCount > 0) {
-                               int mc = mouseRepeatCount;
-                               mouseRepeatCount -= mc;
-                               for (int i = 0; i < mc; i++) {
-                                       FocusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true));
+                       lock (Interface.CurrentInterface.RenderMutex) {
+                               if (mouseRepeatCount > 0) {
+                                       int mc = mouseRepeatCount;
+                                       mouseRepeatCount -= mc;
+                                       for (int i = 0; i < mc; i++) {
+                                               FocusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true));
+                                       }
                                }
-                       }
-                       #if MEASURE_TIME
-                       layoutTime.Reset ();
-                       guTime.Reset ();
-                       drawingTime.Reset ();
-                       updateTime.Restart ();
-                       #endif
+                               #if MEASURE_TIME
+                               layoutTime.Reset ();
+                               guTime.Reset ();
+                               drawingTime.Reset ();
+                               updateTime.Restart ();
+                               #endif
+
+                               #if MEASURE_TIME
+                               layoutTime.Start ();
+                               #endif
+                               //Debug.WriteLine ("======= Layouting queue start =======");
+                               int queueCount = 0;
+                               LayoutingQueueItem lqi = null;
 
-                       #if MEASURE_TIME
-                       layoutTime.Start ();
-                       #endif
-                       //Debug.WriteLine ("======= Layouting queue start =======");
-                       int queueCount = 0;
-                       LayoutingQueueItem lqi = null;
-
-                       lock (Interface.LayoutingQueue)
-                               queueCount = Interface.LayoutingQueue.Count;
-                       
-                       while (queueCount > 0) {
-                               lock (Interface.LayoutingQueue)
-                                       lqi = Interface.LayoutingQueue.Dequeue ();                              
-                               lqi.ProcessLayouting ();
                                lock (Interface.LayoutingQueue)
-                                       queueCount = Interface.LayoutingQueue.Count;                            
-                       }
+                                       queueCount = Interface.LayoutingQueue.Count;
+
+                               while (queueCount > 0) {
+                                       lock (Interface.LayoutingQueue)
+                                               lqi = Interface.LayoutingQueue.Dequeue ();
+                                       lqi.ProcessLayouting ();
+                                       lock (Interface.LayoutingQueue)
+                                               queueCount = Interface.LayoutingQueue.Count;
+                               }
 
 
-                       #if MEASURE_TIME
-                       layoutTime.Stop ();
-                       #endif
+                               #if MEASURE_TIME
+                               layoutTime.Stop ();
+                               #endif
 
-                       //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
-                       //final redraw clips should be added only when layout is completed among parents,
-                       //that's why it take place in a second pass
-                       GraphicObject[] gotr = null;
-                       lock (Interface.CurrentInterface.RenderMutex) {
+                               //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
+                               //final redraw clips should be added only when layout is completed among parents,
+                               //that's why it take place in a second pass
+                               GraphicObject[] gotr = null;
                                gotr = new GraphicObject[gobjsToRedraw.Count];
                                gobjsToRedraw.CopyTo (gotr);
                                gobjsToRedraw.Clear ();
-                       }
-                       foreach (GraphicObject p in gotr) {
-                               try {
-                                       p.IsQueuedForRedraw = false;
-                                       p.Parent.RegisterClip (p.LastPaintedSlot);
-                                       p.Parent.RegisterClip (p.getSlot());
-                               } catch (Exception ex) {
-                                       Debug.WriteLine ("Error Register Clip: " + ex.ToString ());
+
+                               foreach (GraphicObject p in gotr) {
+                                       try {
+                                               p.IsQueuedForRedraw = false;
+                                               p.Parent.RegisterClip (p.LastPaintedSlot);
+                                               p.Parent.RegisterClip (p.getSlot());
+                                       } catch (Exception ex) {
+                                               Debug.WriteLine ("Error Register Clip: " + ex.ToString ());
+                                       }
                                }
-                       }
 
-                       #if MEASURE_TIME
-                       updateTime.Stop ();
-                       drawingTime.Start ();
-                       #endif
+                               #if MEASURE_TIME
+                               updateTime.Stop ();
+                               drawingTime.Start ();
+                               #endif
 
-                       using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
-                               using (ctx = new Context (surf)){
+                               using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
+                                       using (ctx = new Context (surf)){
 
 
-                                       if (clipping.count > 0) {
-                                               //Link.draw (ctx);
-                                               clipping.clearAndClip(ctx);
+                                               if (clipping.count > 0) {
+                                                       //Link.draw (ctx);
+                                                       clipping.clearAndClip(ctx);
 
-                                               for (int i = GraphicObjects.Count -1; i >= 0 ; i--){
-                                                       GraphicObject p = GraphicObjects[i];
-                                                       if (!p.Visible)
-                                                               continue;
-                                                       if (!clipping.intersect (p.Slot))
-                                                               continue;
-                                                       ctx.Save ();
+                                                       for (int i = GraphicObjects.Count -1; i >= 0 ; i--){
+                                                               GraphicObject p = GraphicObjects[i];
+                                                               if (!p.Visible)
+                                                                       continue;
+                                                               if (!clipping.intersect (p.Slot))
+                                                                       continue;
+                                                               ctx.Save ();
 
-                                                       p.Paint (ref ctx);
+                                                               p.Paint (ref ctx);
 
-                                                       ctx.Restore ();
-                                               }
+                                                               ctx.Restore ();
+                                                       }
 
-                                               #if DEBUG_CLIP_RECTANGLE
-                                               clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
-                                               #endif
+                                                       #if DEBUG_CLIP_RECTANGLE
+                                                       clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
+                                                       #endif
 
-                                               lock (RenderMutex) {
                                                        if (IsDirty)
                                                                DirtyRect += clipping.Bounds;
                                                        else
@@ -379,17 +378,16 @@ namespace Crow
                                                        DirtyRect.Top = Math.Max (0, DirtyRect.Top);
                                                        DirtyRect.Width = Math.Min (ClientRectangle.Width - DirtyRect.Left, DirtyRect.Width);
                                                        DirtyRect.Height = Math.Min (ClientRectangle.Height - DirtyRect.Top, DirtyRect.Height);
+
+                                                       clipping.Reset ();
                                                }
 
-                                               clipping.Reset ();
+                                               #if MEASURE_TIME
+                                               drawingTime.Stop ();
+                                               #endif
+                                               //surf.WriteToPng (@"/mnt/data/test.png");
                                        }
-
-                                       #if MEASURE_TIME
-                                       drawingTime.Stop ();
-                                       #endif
-                                       //surf.WriteToPng (@"/mnt/data/test.png");
                                }
-                       }
                        //                      if (ToolTip.isVisible) {
                        //                              ToolTip.panel.processkLayouting();
                        //                              if (ToolTip.panel.layoutIsValid)
@@ -406,7 +404,8 @@ namespace Crow
 
                        //                      Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",
                        //                              updateTime.ElapsedTicks,
-                       //                              updateTime.ElapsedMilliseconds);
+                               //                              updateTime.ElapsedMilliseconds);
+                       }
                }
                public Rectangles clipping {
                        get { return _redrawClip; }