From 9d381671ec0b1266448eddbf4c4935cdc7d23a9f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Tue, 4 Dec 2018 14:09:07 +0100 Subject: docking save/restore; use image surfaces as cache for graphic object instead of backend similar which blink too much --- src/debug/DbgEventTypeColors.cs | 77 +++++++++++++++++++++++++++ src/debug/DbgLogViewer.cs | 113 ++++++++++++++++++++++------------------ src/debug/DebugLogger.cs | 8 ++- 3 files changed, 145 insertions(+), 53 deletions(-) create mode 100644 src/debug/DbgEventTypeColors.cs (limited to 'src/debug') diff --git a/src/debug/DbgEventTypeColors.cs b/src/debug/DbgEventTypeColors.cs new file mode 100644 index 00000000..e0881182 --- /dev/null +++ b/src/debug/DbgEventTypeColors.cs @@ -0,0 +1,77 @@ +// +// DbgEventTypeColors.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 Cairo; +using System.Linq; + +namespace Crow +{ + #if DEBUG_LOG + public class DbgEventTypeColors : GraphicObject + { + protected override void onDraw (Context gr) + { + base.onDraw (gr); + + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + gr.FontOptions = Interface.FontRenderingOptions; + gr.Antialias = Interface.Antialias; + + DbgEvtType[] types = DbgLogViewer.colors.Keys.ToArray (); + Color[] colors = DbgLogViewer.colors.Values.ToArray (); + + Rectangle r = ClientRectangle; + FontExtents fe = gr.FontExtents; + + double penY = fe.Height + r.Top; + double penX = (double)r.Left; + + + for (int i = 0; i < types.Length; i++) { + string n = types [i].ToString(); + Color c = colors[i]; + Foreground.SetAsSource (gr); + + gr.MoveTo (penX + 25.0, penY - fe.Descent); + gr.ShowText (n); + + Rectangle rc = new Rectangle((int)penX, (int)(penY - fe.Height), 20, (int)fe.Height); + rc.Inflate (-2); + gr.Rectangle (rc); + gr.StrokePreserve (); + + gr.SetSourceColor (c); + gr.Fill (); + + penY += fe.Height; + + } + } + } + #endif +} + diff --git a/src/debug/DbgLogViewer.cs b/src/debug/DbgLogViewer.cs index 7c8a1bdf..6124d6f9 100644 --- a/src/debug/DbgLogViewer.cs +++ b/src/debug/DbgLogViewer.cs @@ -34,8 +34,12 @@ namespace Crow { public class DbgLogViewer : ScrollingObject { + public static Dictionary colors; + + public static Configuration colorsConf = new Configuration("dbgcolor.conf"); + #region debug viewer private classes - class DbgData { + public class DbgData { public int objInstanceNum; public LayoutingType layout; public LayoutingQueueItem.Result result; @@ -44,7 +48,7 @@ namespace Crow objInstanceNum = _obj; } } - class DbgEvent { + public class DbgEvent { public long begin, end; public DbgEvtType type; public DbgData data = null; @@ -99,7 +103,19 @@ namespace Crow } #endregion + public static void reloadColors () { + colors = new Dictionary(); + foreach (string n in colorsConf.Names) { + DbgEvtType t = (DbgEvtType)Enum.Parse (typeof(DbgEvtType), n); + Color c = colorsConf.Get (n); + colors.Add (t, c); + } + + } #region CTOR + static DbgLogViewer() { + reloadColors (); + } protected DbgLogViewer () : base(){} public DbgLogViewer (Interface iface) : base(iface){} #endregion @@ -156,8 +172,13 @@ namespace Crow void storeEvent (DbgEvent evt) { if (evt.data == null)//global events events.Add (evt); - else - objs.Where (o => o.instanceNum == evt.data.objInstanceNum).FirstOrDefault ().events.Add (evt); + else { + DbgGo go = objs.Where (o => o.instanceNum == evt.data.objInstanceNum).FirstOrDefault (); + if (go == null) + Console.WriteLine ("Unknown instance: " + evt.data.objInstanceNum); + else + go.events.Add (evt); + } } void loadDebugFile() { @@ -289,50 +310,7 @@ namespace Crow } } - Crow.Color getObjEventColor (DbgEvent evt) { - if (evt.type.HasFlag (DbgEvtType.GOLayouting)) { - if (evt.type == DbgEvtType.GOProcessLayouting) { - switch (evt.data.result) { - case LayoutingQueueItem.Result.Success: - return Crow.Color.Green; - case LayoutingQueueItem.Result.Deleted: - return Crow.Color.Red; - case LayoutingQueueItem.Result.Discarded: - return Crow.Color.DarkRed; - case LayoutingQueueItem.Result.Requeued: - return Crow.Color.Orange; - } - } else if (evt.type == DbgEvtType.GOProcessLayoutingWithNoParent) - return Color.IndianRed; - else - return Crow.Color.Blue; - } - switch (evt.type) { - case DbgEvtType.GOClassCreation: - return Color.GhostWhite; - case DbgEvtType.GOInitialization: - return Color.Cyan; - case DbgEvtType.GOClippingRegistration: - return Color.Cyan; - case DbgEvtType.GORegisterClip: - return Color.Cyan; - case DbgEvtType.GORegisterForGraphicUpdate: - return Color.Cyan; - case DbgEvtType.GOEnqueueForRepaint: - return Color.Cyan; - case DbgEvtType.GODraw: - return Color.Cyan; - case DbgEvtType.GORecreateCache: - return Color.Cyan; - case DbgEvtType.GOUpdateCacheAndPaintOnCTX: - return Color.Cyan; - case DbgEvtType.GOPaint: - return Color.Cyan; - case DbgEvtType.GONewDataSource: - return Color.Cyan; - } - return Crow.Color.RebeccaPurple; - } + protected override void onDraw (Cairo.Context gr) { @@ -341,7 +319,7 @@ namespace Crow gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; + gr.Antialias = Cairo.Antialias.None; if (objs == null) return; @@ -353,13 +331,19 @@ namespace Crow double penY = topMargin + ClientRectangle.Top; for (int i = 0; i < visibleLines; i++) { + if (i + ScrollY >= objs.Count) + break; DbgGo g = objs [i + ScrollY]; + foreach (DbgEvent evt in g.events) { + + if (evt.end - minTicks <= ScrollX) continue; if (evt.begin - minTicks > ScrollX + visibleTicks) break; + double x = xScale * (evt.begin - minTicks - ScrollX) ; double w = Math.Max (Math.Max(2.0, 2.0 * xScale), (double)(evt.end - evt.begin) * xScale); if (x < 0.0) { @@ -373,11 +357,32 @@ namespace Crow //if (x + w > cb.Right) // continue; - gr.SetSourceColor (getObjEventColor (evt)); + Color c = Color.Black; + + if (evt.type == DbgEvtType.GOProcessLayouting) { + switch (evt.data.result) { + case LayoutingQueueItem.Result.Success: + c = Crow.Color.Green; + break; + case LayoutingQueueItem.Result.Deleted: + c = Crow.Color.Red; + break; + case LayoutingQueueItem.Result.Discarded: + c = Crow.Color.OrangeRed; + break; + case LayoutingQueueItem.Result.Requeued: + c = Crow.Color.Orange; + break; + } + } else if (colors.ContainsKey (evt.type)) + c = colors [evt.type]; + else + System.Diagnostics.Debugger.Break (); + + gr.SetSourceColor (c); gr.Rectangle (x, penY, w, fe.Height); gr.Fill (); - } penY += fe.Height; @@ -458,7 +463,9 @@ namespace Crow gr.MoveTo (x- 0.5 * te.Width, penY - gr.FontExtents.Descent); gr.SetSourceColor (Crow.Color.Jet); gr.ShowText (s); + } + } public override void Paint (ref Cairo.Context ctx) { @@ -569,7 +576,9 @@ namespace Crow if (selStart >= 0 && IFace.Mouse.IsButtonDown(MouseButton.Left)) selEnd = currentTick; - RegisterForRedraw (); + if (RegisteredLayoutings == LayoutingType.None && !IsDirty) + IFace.EnqueueForRepaint (this); + } public override void onMouseDown (object sender, MouseButtonEventArgs e) { diff --git a/src/debug/DebugLogger.cs b/src/debug/DebugLogger.cs index 18e4ae19..38cbc2af 100644 --- a/src/debug/DebugLogger.cs +++ b/src/debug/DebugLogger.cs @@ -65,6 +65,11 @@ namespace Crow GOUpdateCacheAndPaintOnCTX = 0x020c, GOPaint = 0x020d, GONewDataSource = 0x020e, + GOLock = 0x0800, + GOLockUpdate = 0x0a01, + GOLockClipping = 0x0a02, + GOLockRender = 0x0a03, + GOLockLayouting = 0x0a04, } /// @@ -162,7 +167,8 @@ namespace Crow s.WriteLine ("[Events]"); foreach (DbgEvent e in events) - s.WriteLine (e.ToString ()); + if (e != null) + s.WriteLine (e.ToString ()); } } } -- cgit v1.3.1-4-g156e