]> O.S.I.I.S - jp/crow.git/commitdiff
split Update steps
authorjpbruyere <jp.bruyere@hotmail.com>
Thu, 3 Mar 2016 09:46:42 +0000 (10:46 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 3 Mar 2016 09:46:42 +0000 (10:46 +0100)
src/Interface.cs

index 826885941da91ecf811508c9b76cd8d74caa767c..6ff7f34695668f6f8f0a30f363504e5076da92fb 100644 (file)
@@ -284,48 +284,75 @@ namespace Crow
 
 
                public void Update(){
-                       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 (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.Start ();
-                               #endif
-                               //Debug.WriteLine ("======= Layouting queue start =======");
-                               int queueCount = 0;
-                               LayoutingQueueItem lqi = null;
+                       }
+                       #if MEASURE_TIME
+                       guTime.Reset ();
+                       updateTime.Restart ();
+                       #endif
 
-                               lock (Interface.LayoutingQueue)
-                                       queueCount = Interface.LayoutingQueue.Count;
 
-                               while (queueCount > 0) {
-                                       lock (Interface.LayoutingQueue)
-                                               lqi = Interface.LayoutingQueue.Dequeue ();
-                                       if (lqi!=null)
-                                               lqi.ProcessLayouting ();
-                                       lock (Interface.LayoutingQueue)
-                                               queueCount = Interface.LayoutingQueue.Count;
-                               }
+                       processLayouting ();
 
+                       clippingRegistration ();
 
-                               #if MEASURE_TIME
-                               layoutTime.Stop ();
-                               #endif
+                       processDrawing ();
 
-                               //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
+                       #if MEASURE_TIME
+                       updateTime.Stop ();
+                       #endif
+                       //                      if (ToolTip.isVisible) {
+                       //                              ToolTip.panel.processkLayouting();
+                       //                              if (ToolTip.panel.layoutIsValid)
+                       //                                      ToolTip.panel.Paint(ref ctx);
+                       //                      }
+                       //                      Debug.WriteLine("INTERFACE: layouting: {0} ticks \t graphical update {1} ticks \t drawing {2} ticks",
+                       //                          layoutTime.ElapsedTicks,
+                       //                          guTime.ElapsedTicks,
+                       //                          drawingTime.ElapsedTicks);
+                       //                      Debug.WriteLine("INTERFACE: layouting: {0} ms \t graphical update {1} ms \t drawing {2} ms",
+                       //                          layoutTime.ElapsedMilliseconds,
+                       //                          guTime.ElapsedMilliseconds,
+                       //                          drawingTime.ElapsedMilliseconds);
+
+                       //                      Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",
+                       //                              updateTime.ElapsedTicks,
+                               //                              updateTime.ElapsedMilliseconds);
+               }
+               void processLayouting(){
+                       #if MEASURE_TIME
+                       layoutTime.Restart();
+                       #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 ();
+                               if (lqi!=null)
+                                       lqi.ProcessLayouting ();
+                               lock (Interface.LayoutingQueue)
+                                       queueCount = Interface.LayoutingQueue.Count;
+                       }
+                       #if MEASURE_TIME
+                       layoutTime.Stop ();
+                       #endif
+               }
+               void clippingRegistration(){
+                       //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
+                       lock (Interface.CurrentInterface.RenderMutex) {
                                GraphicObject[] gotr = null;
                                gotr = new GraphicObject[gobjsToRedraw.Count];
                                gobjsToRedraw.CopyTo (gotr);
@@ -335,42 +362,42 @@ namespace Crow
                                        try {
                                                p.IsQueuedForRedraw = false;
                                                p.Parent.RegisterClip (p.LastPaintedSlot);
-                                               p.Parent.RegisterClip (p.getSlot());
+                                               p.Parent.RegisterClip (p.getSlot ());
                                        } catch (Exception ex) {
                                                Debug.WriteLine ("Error Register Clip: " + ex.ToString ());
                                        }
                                }
+                       }
+               }
+               void processDrawing(){
+                       #if MEASURE_TIME
+                       drawingTime.Restart();
+                       #endif
+                       using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
+                               using (ctx = new Context (surf)){
 
-                               #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)){
-
-
-                                               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 ();
+                                       if (clipping.count > 0) {
+                                               //Link.draw (ctx);
+                                               clipping.clearAndClip(ctx);
 
-                                                               p.Paint (ref 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 ();
 
-                                                               ctx.Restore ();
-                                                       }
+                                                       p.Paint (ref ctx);
 
-                                                       #if DEBUG_CLIP_RECTANGLE
-                                                       clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
-                                                       #endif
+                                                       ctx.Restore ();
+                                               }
 
+                                               #if DEBUG_CLIP_RECTANGLE
+                                               clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
+                                               #endif
+                                               lock (Interface.CurrentInterface.RenderMutex) {
                                                        if (IsDirty)
                                                                DirtyRect += clipping.Bounds;
                                                        else
@@ -381,35 +408,17 @@ 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 ();
                                                }
-
-                                               #if MEASURE_TIME
-                                               drawingTime.Stop ();
-                                               #endif
-                                               //surf.WriteToPng (@"/mnt/data/test.png");
+                                               clipping.Reset ();
                                        }
+                                       //surf.WriteToPng (@"/mnt/data/test.png");
                                }
-                       //                      if (ToolTip.isVisible) {
-                       //                              ToolTip.panel.processkLayouting();
-                       //                              if (ToolTip.panel.layoutIsValid)
-                       //                                      ToolTip.panel.Paint(ref ctx);
-                       //                      }
-                       //                      Debug.WriteLine("INTERFACE: layouting: {0} ticks \t graphical update {1} ticks \t drawing {2} ticks",
-                       //                          layoutTime.ElapsedTicks,
-                       //                          guTime.ElapsedTicks,
-                       //                          drawingTime.ElapsedTicks);
-                       //                      Debug.WriteLine("INTERFACE: layouting: {0} ms \t graphical update {1} ms \t drawing {2} ms",
-                       //                          layoutTime.ElapsedMilliseconds,
-                       //                          guTime.ElapsedMilliseconds,
-                       //                          drawingTime.ElapsedMilliseconds);
-
-                       //                      Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",
-                       //                              updateTime.ElapsedTicks,
-                               //                              updateTime.ElapsedMilliseconds);
                        }
+                       #if MEASURE_TIME
+                       drawingTime.Stop ();
+                       #endif
                }
+
                public Rectangles clipping {
                        get { return _redrawClip; }
                        set { _redrawClip = value; }
@@ -466,14 +475,17 @@ namespace Crow
 
 
                public void ProcessResize(Rectangle bounds){
-                       clientRectangle = bounds;
+                       lock (RenderMutex) {
+                               clientRectangle = bounds;
 
-                       int stride = 4 * ClientRectangle.Width;
-                       int bmpSize = Math.Abs (stride) * ClientRectangle.Height;
-                       bmp = new byte[bmpSize];
+                               int stride = 4 * ClientRectangle.Width;
+                               int bmpSize = Math.Abs (stride) * ClientRectangle.Height;
+                               bmp = new byte[bmpSize];
 
-                       foreach (GraphicObject g in GraphicObjects)
-                               g.RegisterForLayouting (LayoutingType.All);
+                               foreach (GraphicObject g in GraphicObjects)
+                                       g.RegisterForLayouting (LayoutingType.All);
+                               clipping.AddRectangle (clientRectangle);
+                       }
                }
 
                XCursor cursor = XCursor.Default;