aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2017-08-26 04:57:51 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2017-08-26 04:57:51 +0200
commitdde48ba7c6017539b5d8a4539030bea0715b0374 (patch)
treef9e4b463244aac9bf1cf2d5bfb3473b22b3a0bbc /src
parent5f68cf21b47b88e4e1de7fed7bd9b8b56b5dfa3d (diff)
test texture surface backend with sdl and xcbTestXCBandSDL
Diffstat (limited to 'src')
-rw-r--r--src/GraphicObjects/GraphicObject.cs2
-rw-r--r--src/Interface.cs116
-rw-r--r--src/Mono.Cairo/ImageSurface.cs8
-rw-r--r--src/Mono.Cairo/Surface.cs2
4 files changed, 63 insertions, 65 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 41738802..f593b099 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -1120,7 +1120,7 @@ namespace Crow
IsDirty = false;
if (bmp != null)
bmp.Dispose ();
- bmp = new ImageSurface (Format.Argb32, Slot.Width, Slot.Height);
+ bmp = CurrentInterface.bmp.CreateSimilar(Content.ColorAlpha, Slot.Width, Slot.Height);
using (Context gr = new Context (bmp)) {
gr.Antialias = Interface.Antialias;
onDraw (gr);
diff --git a/src/Interface.cs b/src/Interface.cs
index adcb2830..f79d7a2e 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -124,9 +124,9 @@ namespace Crow
/// <summary>Graphic Tree of this interface</summary>
public List<GraphicObject> GraphicTree = new List<GraphicObject>();
/// <summary>Interface's resulting bitmap</summary>
- public byte[] bmp;
+ public Surface bmp;
/// <summary>resulting bitmap limited to last redrawn part</summary>
- public byte[] dirtyBmp;
+ public Surface dirtyBmp;
/// <summary>True when host has to repaint Interface</summary>
public bool IsDirty = false;
/// <summary>Coordinate of the dirty bmp on the original bmp</summary>
@@ -500,64 +500,62 @@ namespace Crow
#if MEASURE_TIME
drawingMeasure.StartCycle();
#endif
- using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
- using (ctx = new Context (surf)){
- if (!clipping.IsEmpty) {
- for (int i = 0; i < clipping.NumRectangles; i++)
- ctx.Rectangle(clipping.GetRectangle(i));
- ctx.ClipPreserve();
- ctx.Operator = Operator.Clear;
- ctx.Fill();
- ctx.Operator = Operator.Over;
+ using (ctx = new Context (bmp)){
+ if (!clipping.IsEmpty) {
- for (int i = GraphicTree.Count -1; i >= 0 ; i--){
- GraphicObject p = GraphicTree[i];
- if (!p.Visible)
- continue;
- if (clipping.Contains (p.Slot) == RegionOverlap.Out)
- continue;
+ for (int i = 0; i < clipping.NumRectangles; i++)
+ ctx.Rectangle(clipping.GetRectangle(i));
+ ctx.ClipPreserve();
+ ctx.Operator = Operator.Clear;
+ ctx.Fill();
+ ctx.Operator = Operator.Over;
- ctx.Save ();
- p.Paint (ref ctx);
- ctx.Restore ();
- }
+ for (int i = GraphicTree.Count -1; i >= 0 ; i--){
+ GraphicObject p = GraphicTree[i];
+ if (!p.Visible)
+ continue;
+ if (clipping.Contains (p.Slot) == RegionOverlap.Out)
+ continue;
- #if DEBUG_CLIP_RECTANGLE
- clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
- #endif
- lock (RenderMutex) {
-// Array.Copy (bmp, dirtyBmp, bmp.Length);
+ ctx.Save ();
+ p.Paint (ref ctx);
+ ctx.Restore ();
+ }
- IsDirty = true;
- if (IsDirty)
- DirtyRect += clipping.Extents;
- else
- DirtyRect = clipping.Extents;
+ #if DEBUG_CLIP_RECTANGLE
+ clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
+ #endif
+ lock (RenderMutex) {
+// Array.Copy (bmp, dirtyBmp, bmp.Length);
- DirtyRect.Left = Math.Max (0, DirtyRect.Left);
- 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);
- DirtyRect.Width = Math.Max (0, DirtyRect.Width);
- DirtyRect.Height = Math.Max (0, DirtyRect.Height);
+ IsDirty = true;
+ if (IsDirty)
+ DirtyRect += clipping.Extents;
+ else
+ DirtyRect = clipping.Extents;
- if (DirtyRect.Width > 0 && DirtyRect.Height >0) {
- dirtyBmp = new byte[4 * DirtyRect.Width * DirtyRect.Height];
- for (int y = 0; y < DirtyRect.Height; y++) {
- Array.Copy (bmp,
- ((DirtyRect.Top + y) * ClientRectangle.Width * 4) + DirtyRect.Left * 4,
- dirtyBmp, y * DirtyRect.Width * 4, DirtyRect.Width * 4);
- }
+ DirtyRect.Left = Math.Max (0, DirtyRect.Left);
+ 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);
+ DirtyRect.Width = Math.Max (0, DirtyRect.Width);
+ DirtyRect.Height = Math.Max (0, DirtyRect.Height);
- } else
- IsDirty = false;
- }
- clipping.Dispose ();
- clipping = new Region ();
+ if (DirtyRect.Width > 0 && DirtyRect.Height >0) {
+ dirtyBmp?.Dispose ();
+ dirtyBmp = bmp.CreateSimilar (Content.ColorAlpha, DirtyRect.Width, DirtyRect.Height);
+ using (Context dctx = new Context (dirtyBmp)) {
+ dctx.SetSourceSurface (bmp, DirtyRect.Left, DirtyRect.Top);
+ dctx.Paint ();
+ }
+ } else
+ IsDirty = false;
}
- //surf.WriteToPng (@"/mnt/data/test.png");
+ clipping.Dispose ();
+ clipping = new Region ();
}
+ //bmp.WriteToPng (@"/mnt/data/test.png");
}
#if MEASURE_TIME
drawingMeasure.StopCycle();
@@ -659,19 +657,10 @@ namespace Crow
}
#endregion
- public void ProcessResize(Rectangle bounds){
- lock (UpdateMutex) {
- clientRectangle = bounds;
- int stride = 4 * ClientRectangle.Width;
- int bmpSize = Math.Abs (stride) * ClientRectangle.Height;
- bmp = new byte[bmpSize];
- dirtyBmp = new byte[bmpSize];
-
- foreach (GraphicObject g in GraphicTree)
- g.RegisterForLayouting (LayoutingType.All);
-
- RegisterClip (clientRectangle);
- }
+ public void ProcessResize(){
+ foreach (GraphicObject g in GraphicTree)
+ g.RegisterForLayouting (LayoutingType.All);
+ RegisterClip (clientRectangle);
}
#region Mouse and Keyboard Handling
@@ -906,6 +895,7 @@ namespace Crow
public Rectangle ClientRectangle {
get { return clientRectangle; }
+ set { clientRectangle = value; }
}
public Interface HostContainer {
get { return this; }
diff --git a/src/Mono.Cairo/ImageSurface.cs b/src/Mono.Cairo/ImageSurface.cs
index 98143fe8..f109718b 100644
--- a/src/Mono.Cairo/ImageSurface.cs
+++ b/src/Mono.Cairo/ImageSurface.cs
@@ -100,5 +100,13 @@ namespace Cairo {
public int Stride {
get { return NativeMethods.cairo_image_surface_get_stride (Handle); }
}
+
+ public override Surface CreateSimilar (Content content, int width, int height)
+ {
+ IntPtr p = NativeMethods.cairo_surface_create_similar (
+ this.Handle, content, width, height);
+
+ return new Cairo.ImageSurface (p, true);
+ }
}
}
diff --git a/src/Mono.Cairo/Surface.cs b/src/Mono.Cairo/Surface.cs
index d38b7555..cdf26d10 100644
--- a/src/Mono.Cairo/Surface.cs
+++ b/src/Mono.Cairo/Surface.cs
@@ -114,7 +114,7 @@ namespace Cairo {
}
- public Cairo.Surface CreateSimilar (
+ public virtual Cairo.Surface CreateSimilar (
Cairo.Content content, int width, int height)
{
IntPtr p = NativeMethods.cairo_surface_create_similar (