Skip to content
Browse files

Warn in debug output when non-frozen brushes are used in AvalonEdit.

  • Loading branch information...
1 parent 0305d64 commit 03c220d8f46828627446354c9bd45400ec45fbdb @dgrunwald dgrunwald committed Nov 28, 2010
View
4 src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
@@ -362,7 +362,9 @@ public static T PopOrDefault<T>(this Stack<T> stack)
public static Brush ToBrush(this Color color)
{
- return new SolidColorBrush(color);
+ var b = new SolidColorBrush(color);
+ b.Freeze();
+ return b;
}
}
}
View
13 src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
@@ -778,12 +778,13 @@ protected override Size MeasureOverride(Size availableSize)
TextRunProperties CreateGlobalTextRunProperties()
{
- return new GlobalTextRunProperties {
- typeface = this.CreateTypeface(),
- fontRenderingEmSize = FontSize,
- foregroundBrush = (Brush)GetValue(Control.ForegroundProperty),
- cultureInfo = CultureInfo.CurrentCulture
- };
+ var p = new GlobalTextRunProperties();
+ p.typeface = this.CreateTypeface();
+ p.fontRenderingEmSize = FontSize;
+ p.foregroundBrush = (Brush)GetValue(Control.ForegroundProperty);
+ ExtensionMethods.CheckIsFrozen(p.foregroundBrush);
+ p.cultureInfo = CultureInfo.CurrentCulture;
+ return p;
}
VisualLineTextParagraphProperties CreateParagraphProperties(TextRunProperties defaultTextRunProperties)
View
5 ...braries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineElementTextRunProperties.cs
@@ -6,6 +6,7 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
+using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Rendering
{
@@ -76,6 +77,7 @@ object ICloneable.Clone()
/// </summary>
public void SetBackgroundBrush(Brush value)
{
+ ExtensionMethods.CheckIsFrozen(value);
backgroundBrush = value;
}
@@ -143,6 +145,7 @@ public void SetFontRenderingEmSize(double value)
/// </summary>
public void SetForegroundBrush(Brush value)
{
+ ExtensionMethods.CheckIsFrozen(value);
foregroundBrush = value;
}
@@ -177,6 +180,7 @@ public void SetTypeface(Typeface value)
/// </summary>
public void SetTextDecorations(TextDecorationCollection value)
{
+ ExtensionMethods.CheckIsFrozen(value);
textDecorations = value;
}
@@ -196,6 +200,7 @@ public void SetTextDecorations(TextDecorationCollection value)
/// </summary>
public void SetTextEffects(TextEffectCollection value)
{
+ ExtensionMethods.CheckIsFrozen(value);
textEffects = value;
}
}
View
11 src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ExtensionMethods.cs
@@ -3,14 +3,12 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
-using System.Windows.Threading;
using System.Xml;
-using ICSharpCode.AvalonEdit.Document;
-
namespace ICSharpCode.AvalonEdit.Utils
{
static class ExtensionMethods
@@ -187,5 +185,12 @@ public static Rect ToWpf(this System.Drawing.Rectangle rect)
return new Rect(rect.Location.ToWpf(), rect.Size.ToWpf());
}
#endregion
+
+ [Conditional("DEBUG")]
+ public static void CheckIsFrozen(Freezable f)
+ {
+ if (f != null && !f.IsFrozen)
+ Debug.WriteLine("Performance warning: Not frozen: " + f.ToString());
+ }
}
}

0 comments on commit 03c220d

Please sign in to comment.
Something went wrong with that request. Please try again.