Author: toshok
Date: 2006-10-11 10:40:04 -0400 (Wed, 11 Oct 2006)
New Revision: 66554
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PaintEventArgs.cs
Log:
* Control.cs: switch to using an "invalid_region" to track which
parts of the image buffer need updating. This is more code than
the simple fix from r66532. That version just attempted to always
fill the entire buffer on redraw, which turns out to be
inefficient when invalidating small rectangles. This version
simply adds the invalid rectangle to the invalid region. When we
get any WM_PAINT message we see if it can be filled using the
image buffer, and if it can't (if the paint event's clip rectangle
is visible in the invalid region) we first fill the image buffer.
So, the image buffer is still a cache, we just fill it lazily.
* PaintEventArgs.cs: remove the SetClipRectangle method, we don't
need it any longer.
2006-10-11 Chris Toshok <[EMAIL PROTECTED]>
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2006-10-11 14:15:06 UTC (rev 66553)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2006-10-11 14:40:04 UTC (rev 66554)
@@ -1,5 +1,21 @@
2006-10-11 Chris Toshok <[EMAIL PROTECTED]>
+ * Control.cs: switch to using an "invalid_region" to track which
+ parts of the image buffer need updating. This is more code than
+ the simple fix from r66532. That version just attempted to always
+ fill the entire buffer on redraw, which turns out to be
+ inefficient when invalidating small rectangles. This version
+ simply adds the invalid rectangle to the invalid region. When we
+ get any WM_PAINT message we see if it can be filled using the
+ image buffer, and if it can't (if the paint event's clip rectangle
+ is visible in the invalid region) we first fill the image buffer.
+ So, the image buffer is still a cache, we just fill it lazily.
+
+ * PaintEventArgs.cs: remove the SetClipRectangle method, we don't
+ need it any longer.
+
+2006-10-11 Chris Toshok <[EMAIL PROTECTED]>
+
* XplatUIX11.cs (SetWindowPos): we need to update both position as
well as size after calling XMoveResizeWindow. This keeps us from
ignoring future SetWindowPos calls. Fixes the disappearing
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2006-10-11 14:15:06 UTC (rev 66553)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2006-10-11 14:40:04 UTC (rev 66554)
@@ -118,7 +118,7 @@
private Graphics dc_mem; //
Graphics context for double buffering
private GraphicsState dc_state; //
Pristine graphics context to reset after paint code alters dc_mem
private Bitmap bmp_mem; //
Bitmap for double buffering control
- private bool needs_redraw = true;
+ private Region invalid_region;
private ControlBindingsCollection data_bindings;
@@ -773,6 +773,10 @@
bmp_mem=null;
}
+ if (invalid_region!=null) {
+ invalid_region.Dispose();
+ invalid_region=null;
+ }
if (this.InvokeRequired) {
if (Application.MessageLoop) {
this.BeginInvokeInternal(new
MethodInvoker(DestroyHandle), null, true);
@@ -921,6 +925,12 @@
dc_state = dc_mem.Save();
}
+ private void ImageBufferNeedsRedraw () {
+ if (invalid_region != null)
+ invalid_region.Dispose();
+ invalid_region = new Region (ClientRectangle);
+ }
+
private Bitmap ImageBuffer {
get {
if (bmp_mem==null) {
@@ -947,7 +957,7 @@
bmp_mem = new Bitmap (width, height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
dc_mem = Graphics.FromImage (bmp_mem);
- needs_redraw = true;
+ ImageBufferNeedsRedraw ();
}
internal void InvalidateBuffers ()
@@ -960,7 +970,7 @@
dc_mem = null;
bmp_mem = null;
- needs_redraw = true;
+ ImageBufferNeedsRedraw ();
}
internal static void SetChildColor(Control parent) {
@@ -3327,7 +3337,6 @@
}
public void Update() {
- needs_redraw = true;
if (IsHandleCreated) {
XplatUI.UpdateWindow(window.Handle);
}
@@ -3971,7 +3980,7 @@
return;
}
- if (!needs_redraw) {
+ if (invalid_region != null &&
!invalid_region.IsVisible (paint_event.ClipRectangle)) {
// Just blit the previous image
paint_event.Graphics.DrawImage
(ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle,
GraphicsUnit.Pixel);
XplatUI.PaintEventEnd(Handle,
true);
@@ -4005,7 +4014,7 @@
paint_event.SetClipRectangle (old_clip_rect);
dc.DrawImage
(ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle,
GraphicsUnit.Pixel);
paint_event.SetGraphics
(dc);
- needs_redraw = false;
+ invalid_region.Exclude
(paint_event.ClipRectangle);
}
XplatUI.PaintEventEnd(Handle, true);
@@ -4452,7 +4461,20 @@
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnInvalidated(InvalidateEventArgs e) {
- needs_redraw = true;
+ // should this block be here? seems like it
+ // would be more at home in
+ // NotifyInvalidated..
+ if (e.InvalidRect == ClientRectangle) {
+ ImageBufferNeedsRedraw ();
+ }
+ else {
+ // we need this Inflate call here so
+ // that the border of the rectangle is
+ // considered Visible (the
+ // invalid_region.IsVisible call) in
+ // the WM_PAINT handling below.
+ invalid_region.Union
(Rectangle.Inflate(e.InvalidRect, 1,1));
+ }
if (Invalidated!=null) Invalidated(this, e);
}
@@ -4705,8 +4727,6 @@
}
}
- needs_redraw = true;
-
if (VisibleChanged!=null) VisibleChanged(this, e);
// We need to tell our kids
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PaintEventArgs.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PaintEventArgs.cs
2006-10-11 14:15:06 UTC (rev 66553)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PaintEventArgs.cs
2006-10-11 14:40:04 UTC (rev 66554)
@@ -77,14 +77,6 @@
return res;
}
- internal Rectangle SetClipRectangle (Rectangle r)
- {
- Rectangle res = clip_rectangle;
- clip_rectangle = r;
-
- return res;
- }
-
#region Protected Instance Methods
~PaintEventArgs() {
Dispose(false);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches