From: Jean-Philippe Bruyère Date: Sun, 13 Aug 2017 14:45:33 +0000 (+0200) Subject: dont back cache in byte array X-Git-Tag: v0.9.5-beta~210 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=a068b75def006a4722d8026f05399bc258ab0d3f;p=jp%2Fcrow.git dont back cache in byte array --- diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 0db8fb54..284e4877 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -137,7 +137,7 @@ namespace Crow /// Prevent requeuing multiple times the same widget public bool IsQueueForRedraw = false; /// drawing Cache, if null, a redraw is done, cached or not - public byte[] bmp; + public Surface bmp; public bool IsDirty = true; /// /// This size is computed on each child' layout changes. @@ -1116,33 +1116,27 @@ namespace Crow /// this trigger the effective drawing routine protected virtual void RecreateCache () { - int stride = 4 * Slot.Width; - - int bmpSize = Math.Abs (stride) * Slot.Height; - bmp = new byte[bmpSize]; IsDirty = false; - using (ImageSurface draw = - new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, stride)) { - using (Context gr = new Context (draw)) { - gr.Antialias = Interface.Antialias; - onDraw (gr); - } - draw.Flush (); + if (bmp != null) + bmp.Dispose (); + bmp = new ImageSurface (Format.Argb32, Slot.Width, Slot.Height); + using (Context gr = new Context (bmp)) { + gr.Antialias = Interface.Antialias; + onDraw (gr); } + bmp.Flush (); } protected virtual void UpdateCache(Context ctx){ Rectangle rb = Slot + Parent.ClientRectangle.Position; - using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { - if (clearBackground) { - ctx.Save (); - ctx.Operator = Operator.Clear; - ctx.Rectangle (rb); - ctx.Fill (); - ctx.Restore (); - } - ctx.SetSourceSurface (cache, rb.X, rb.Y); - ctx.Paint (); + if (clearBackground) { + ctx.Save (); + ctx.Operator = Operator.Clear; + ctx.Rectangle (rb); + ctx.Fill (); + ctx.Restore (); } + ctx.SetSourceSurface (bmp, rb.X, rb.Y); + ctx.Paint (); //Clipping.clearAndClip (ctx); Clipping.Reset(); } diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 549ca219..de6d3e40 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -235,35 +235,35 @@ namespace Crow { Rectangle rb = Slot + Parent.ClientRectangle.Position; - using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { - Context gr = new Context (cache); - - if (Clipping.count > 0) { - Clipping.clearAndClip (gr); - base.onDraw (gr); - - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - - lock (Children) { - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (Clipping.intersect (c.Slot + ClientRectangle.Position)) - c.Paint (ref gr); - } - } - #if DEBUG_CLIP_RECTANGLE - Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); - #endif + Context gr = new Context (bmp); + + if (Clipping.count > 0) { + Clipping.clearAndClip (gr); + base.onDraw (gr); + + //clip to client zone + CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); + gr.Clip (); + + lock (Children) { + foreach (GraphicObject c in Children) { + if (!c.Visible) + continue; + if (Clipping.intersect (c.Slot + ClientRectangle.Position)) + c.Paint (ref gr); + } } - gr.Dispose (); - ctx.SetSourceSurface (cache, rb.X, rb.Y); - ctx.Paint (); + #if DEBUG_CLIP_RECTANGLE + Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); + #endif } + gr.Dispose (); + + ctx.SetSourceSurface (bmp, rb.X, rb.Y); + ctx.Paint (); + Clipping.Reset(); } #endregion diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 4076b5ec..d018bd77 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -179,21 +179,18 @@ namespace Crow { Rectangle rb = Slot + Parent.ClientRectangle.Position; - using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { - Context gr = new Context (cache); + Context gr = new Context (bmp); - if (Clipping.count > 0) { - Clipping.clearAndClip (gr); + if (Clipping.count > 0) { + Clipping.clearAndClip (gr); - onDraw (gr); - } - - gr.Dispose (); - - ctx.SetSourceSurface (cache, rb.X, rb.Y); - ctx.Paint (); + onDraw (gr); } - Clipping.Reset(); + + gr.Dispose (); + + ctx.SetSourceSurface (bmp, rb.X, rb.Y); + ctx.Paint (); } #endregion