shader.SetMVP (projection);
GL.ActiveTexture (TextureUnit.Texture0);
GL.BindTexture (TextureTarget.Texture2D, texID);
- lock (CrowInterface.RenderMutex) {
+ if (Monitor.TryEnter(CrowInterface.RenderMutex)) {
if (CrowInterface.IsDirty) {
GL.TexSubImage2D (TextureTarget.Texture2D, 0,
CrowInterface.DirtyRect.Left, CrowInterface.DirtyRect.Top,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, CrowInterface.dirtyBmp);
CrowInterface.IsDirty = false;
}
+ Monitor.Exit (CrowInterface.RenderMutex);
}
quad.Render (BeginMode.TriangleStrip);
GL.BindTexture(TextureTarget.Texture2D, 0);
d += c.Slot.Height + Spacing;
}
}
- bmp = null;
+ IsDirty = true;
}
GraphicObject stretchedGO = null;
public override bool UpdateLayout (LayoutingType layoutType)
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
- if (RegisteredLayoutings == LayoutingType.None && bmp == null)
+ if (RegisteredLayoutings == LayoutingType.None && IsDirty)
CurrentInterface.EnqueueForRepaint (this);
return true;
newW = Math.Min (newW, stretchedGO.MaximumSize.Width);
if (newW != stretchedGO.Slot.Width) {
stretchedGO.Slot.Width = newW;
- stretchedGO.bmp = null;
+ stretchedGO.IsDirty = true;
#if DEBUG_LAYOUTING
Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
#endif
newH = Math.Min (newH, stretchedGO.MaximumSize.Height);
if (newH != stretchedGO.Slot.Height) {
stretchedGO.Slot.Height = newH;
- stretchedGO.bmp = null;
+ stretchedGO.IsDirty = true;
#if DEBUG_LAYOUTING
Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString());
#endif
public object Tag;
/// <summary>drawing Cache, if null, a redraw is done, cached or not</summary>
public byte[] bmp;
+ public bool IsDirty = true;
/// <summary>
/// This size is computed on each child' layout changes.
/// In stacking widget, it is used to compute the remaining space for the stretched
NotifyValueChanged ("MouseRepeat", mouseRepeat);
}
}
+ bool clearBackground = false;
[XmlAttributeAttribute()][DefaultValue("Transparent")]
public virtual Fill Background {
get { return background; }
set {
if (background == value)
return;
+ clearBackground = false;
if (value == null)
return;
background = value;
NotifyValueChanged ("Background", background);
RegisterForRedraw ();
+ if (background is SolidColor) {
+ if ((Background as SolidColor).Equals (Color.Clear))
+ clearBackground = true;
+ }
}
}
[XmlAttributeAttribute()][DefaultValue("White")]
#region Queuing
public virtual void RegisterClip(Rectangle clip){
- if (CacheEnabled && bmp != null)
+ if (CacheEnabled && !IsDirty)
Clipping.AddRectangle (clip + ClientRectangle.Position);
if (Parent != null)
Parent.RegisterClip (clip + Slot.Position + ClientRectangle.Position);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RegisterForGraphicUpdate ()
{
- bmp = null;
+ IsDirty = true;
if (Width.IsFit || Height.IsFit)
RegisterForLayouting (LayoutingType.Sizing);
else if (RegisteredLayoutings == LayoutingType.None)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RegisterForRedraw ()
{
- bmp = null;
+ IsDirty = true;
if (RegisteredLayoutings == LayoutingType.None)
CurrentInterface.EnqueueForRepaint (this);
}
if (LastSlots.X == Slot.X)
break;
- bmp = null;
+ IsDirty = true;
OnLayoutChanges (layoutType);
if (LastSlots.Y == Slot.Y)
break;
- bmp = null;
+ IsDirty = true;
OnLayoutChanges (layoutType);
if (LastSlots.Width == Slot.Width)
break;
- bmp = null;
+ IsDirty = true;
OnLayoutChanges (layoutType);
if (LastSlots.Height == Slot.Height)
break;
- bmp = null;
+ IsDirty = true;
OnLayoutChanges (layoutType);
}
//if no layouting remains in queue for item, registre for redraw
- if (this.registeredLayoutings == LayoutingType.None && bmp == null)
+ if (this.registeredLayoutings == LayoutingType.None && IsDirty)
CurrentInterface.EnqueueForRepaint (this);
return true;
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)) {
}
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)) {
- //TODO:improve equality test for basic color and Fill
- if (this.Background is SolidColor) {
- if ((this.Background as SolidColor).Equals (Color.Clear)) {
+ 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 (cacheEnabled) {
- if (bmp == null)
+ if (IsDirty)
RecreateCache ();
UpdateCache (ctx);
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
- if (RegisteredLayoutings == LayoutingType.None && bmp == null)
+ if (RegisteredLayoutings == LayoutingType.None && IsDirty)
CurrentInterface.EnqueueForRepaint (this);
return true;
}
//if no layouting remains in queue for item, registre for redraw
- if (RegisteredLayoutings == LayoutingType.None && bmp == null)
+ if (RegisteredLayoutings == LayoutingType.None && IsDirty)
CurrentInterface.EnqueueForRepaint (this);
return true;
dy += c.Slot.Height + Spacing;
}
}
- bmp = null;
+ IsDirty = true;
}
public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
{
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
- if (RegisteredLayoutings == LayoutingType.None && bmp == null)
+ if (RegisteredLayoutings == LayoutingType.None && IsDirty)
CurrentInterface.EnqueueForRepaint (this);
return true;
public string Clipboard;//TODO:use object instead for complex copy paste
public void EnqueueForRepaint(GraphicObject g)
{
-// if (g.RegisteredLayoutings != LayoutingType.None)
-// return;
- ILayoutable l = g;
-// while (l.Parent != null)
-// l = l.Parent;
-// if (!(l is Interface))
-// return;
-
lock (DrawingQueue) {
if (g.IsQueueForRedraw)
return;
#if MEASURE_TIME
clippingTime.Restart ();
#endif
- lock (DrawingQueue) {
- while (DrawingQueue.Count > 0) {
- GraphicObject g = DrawingQueue.Dequeue ();
- g.IsQueueForRedraw = false;
- g.Parent.RegisterClip (g.LastPaintedSlot);
- if (g.getSlot () != g.LastPaintedSlot)
- g.Parent.RegisterClip (g.getSlot ());
- }
+ GraphicObject g = null;
+ while (DrawingQueue.Count > 0) {
+ lock (DrawingQueue)
+ g = DrawingQueue.Dequeue ();
+ g.IsQueueForRedraw = false;
+ g.Parent.RegisterClip (g.LastPaintedSlot);
+ if (g.getSlot () != g.LastPaintedSlot)
+ g.Parent.RegisterClip (g.getSlot ());
}
+
#if MEASURE_TIME
clippingTime.Stop ();
#endif
#endif
using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
using (ctx = new Context (surf)){
-
-
if (clipping.count > 0) {
//Link.draw (ctx);
clipping.clearAndClip(ctx);