From 5ea4d03f077f830e6101463e8692856a1f0f9efe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Thu, 18 Mar 2021 17:20:28 +0100 Subject: [PATCH] drawing optimisation:group double drawing solved, Region.Reset() --- Crow/src/Mono.Cairo/Region.cs | 6 ++++++ Crow/src/Widgets/Group.cs | 19 ++++++------------- Crow/src/Widgets/PrivateContainer.cs | 3 +-- Crow/src/Widgets/Widget.cs | 20 +++++++++++--------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Crow/src/Mono.Cairo/Region.cs b/Crow/src/Mono.Cairo/Region.cs index 5e8d8d60..f2c111d7 100644 --- a/Crow/src/Mono.Cairo/Region.cs +++ b/Crow/src/Mono.Cairo/Region.cs @@ -192,5 +192,11 @@ namespace Crow.Cairo { return NativeMethods.cairo_region_xor_rectangle (Handle, ref rectangle); } + public void Reset () { + if (IsEmpty) + return; + NativeMethods.cairo_region_destroy (Handle); + handle = NativeMethods.cairo_region_create (); + } } } diff --git a/Crow/src/Widgets/Group.cs b/Crow/src/Widgets/Group.cs index 69fc614e..5f6a97f8 100644 --- a/Crow/src/Widgets/Group.cs +++ b/Crow/src/Widgets/Group.cs @@ -309,12 +309,8 @@ namespace Crow } protected override void UpdateCache (Context ctx) { - Rectangle rb = Slot + Parent.ClientRectangle.Position; - - - Context gr = new Context (bmp); - if (!Clipping.IsEmpty) { + Context gr = new Context (bmp); for (int i = 0; i < Clipping.NumRectangles; i++) gr.Rectangle(Clipping.GetRectangle(i)); gr.ClipPreserve(); @@ -348,14 +344,11 @@ namespace Crow gr.Rectangle(Clipping.GetRectangle(i)); gr.Stroke ();*/ #endif - } - gr.Dispose (); - - ctx.SetSource (bmp, rb.X, rb.Y); - ctx.Paint (); - - Clipping.Dispose(); - Clipping = new Region (); + gr.Dispose (); + Clipping.Reset (); + }/*else + Console.WriteLine("GROUP REPAINT WITH EMPTY CLIPPING");*/ + paintCache (ctx, Slot + Parent.ClientRectangle.Position); } #endregion diff --git a/Crow/src/Widgets/PrivateContainer.cs b/Crow/src/Widgets/PrivateContainer.cs index bb0bf531..6bdff7da 100644 --- a/Crow/src/Widgets/PrivateContainer.cs +++ b/Crow/src/Widgets/PrivateContainer.cs @@ -224,8 +224,7 @@ namespace Crow ctx.SetSource (bmp, rb.X, rb.Y); ctx.Paint (); - Clipping.Dispose(); - Clipping = new Region (); + Clipping.Reset (); } #endregion diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 1553dab4..4c35c153 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -1810,14 +1810,11 @@ namespace Crow onDraw (gr); } - IsDirty = false; + IsDirty = false; DbgLogger.EndEvent (DbgEvtType.GORecreateCache); } - protected virtual void UpdateCache(Context ctx){ - DbgLogger.StartEvent(DbgEvtType.GOUpdateCache, this); - - Rectangle rb = Slot + Parent.ClientRectangle.Position; + protected void paintCache(Context ctx, Rectangle rb) { if (clearBackground) { ctx.Operator = Operator.Clear; ctx.Rectangle (rb); @@ -1827,8 +1824,11 @@ namespace Crow ctx.SetSource (bmp, rb.X, rb.Y); ctx.Paint (); - Clipping.Dispose (); - Clipping = new Region (); + } + protected virtual void UpdateCache(Context ctx){ + DbgLogger.StartEvent(DbgEvtType.GOUpdateCache, this); + paintCache (ctx, Slot + Parent.ClientRectangle.Position); + Clipping.Reset (); DbgLogger.EndEvent (DbgEvtType.GOUpdateCache); } /// Chained painting routine on the parent context of the actual cached version @@ -1866,9 +1866,11 @@ namespace Crow } if (cacheEnabled) { - if (IsDirty) + if (IsDirty) { RecreateCache (); - UpdateCache (ctx); + paintCache (ctx, Slot + Parent.ClientRectangle.Position); + }else + UpdateCache (ctx); if (!IsEnabled) paintDisabled (ctx, Slot + Parent.ClientRectangle.Position); } else { -- 2.47.3