]> O.S.I.I.S - jp/crow.git/commitdiff
drawing optimisation:group double drawing solved, Region.Reset()
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 18 Mar 2021 16:20:28 +0000 (17:20 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 18 Mar 2021 16:20:28 +0000 (17:20 +0100)
Crow/src/Mono.Cairo/Region.cs
Crow/src/Widgets/Group.cs
Crow/src/Widgets/PrivateContainer.cs
Crow/src/Widgets/Widget.cs

index 5e8d8d607e75bdc431ee6c5d536c10a4b6ca6d03..f2c111d7f0cd5fb8e07efd175abbe2377d737114 100644 (file)
@@ -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 ();                  
+               }
        }
 }
index 69fc614e2677a07073dbb992175b123ba2bcd1b8..5f6a97f816ddf4d83bf773c81f436f2af4ccac22 100644 (file)
@@ -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
 
index bb0bf53199886a472d11e2eda85aa25a4784099d..6bdff7da3369a053afce4e904b24c58665931b98 100644 (file)
@@ -224,8 +224,7 @@ namespace Crow
 
                        ctx.SetSource (bmp, rb.X, rb.Y);
                        ctx.Paint ();
-                       Clipping.Dispose();
-                       Clipping = new Region ();
+                       Clipping.Reset ();                      
                }
                #endregion
 
index 1553dab4147fcd71ca3babc64f14cf5cb9bc51a6..4c35c153a298eb0637a84cc8c1d48beca2202a9f 100644 (file)
@@ -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);
                }
                /// <summary> 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 {