Browse Source
Merge pull request #6032 from MarchingCube/use-immutable-data
Use immutable data to limit allocations.
pull/6039/head
Jumar Macato
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
13 additions and
7 deletions
-
src/Avalonia.Controls/ExperimentalAcrylicBorder.cs
-
src/Avalonia.Controls/Presenters/TextPresenter.cs
-
src/Avalonia.Controls/TickBar.cs
-
src/Avalonia.Controls/Utils/BorderRenderHelper.cs
|
|
|
@ -3,6 +3,7 @@ using Avalonia.Layout; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Platform; |
|
|
|
using System; |
|
|
|
using Avalonia.Media.Immutable; |
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
@ -90,7 +91,7 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_borderRenderHelper.Render(context, Bounds.Size, new Thickness(), CornerRadius, new SolidColorBrush(Material.FallbackColor), null, default); |
|
|
|
_borderRenderHelper.Render(context, Bounds.Size, new Thickness(), CornerRadius, new ImmutableSolidColorBrush(Material.FallbackColor), null, default); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -6,6 +6,7 @@ using Avalonia.Metadata; |
|
|
|
using Avalonia.Threading; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.Media.Immutable; |
|
|
|
|
|
|
|
namespace Avalonia.Controls.Presenters |
|
|
|
{ |
|
|
|
@ -366,24 +367,26 @@ namespace Avalonia.Controls.Presenters |
|
|
|
|
|
|
|
if (caretBrush is null) |
|
|
|
{ |
|
|
|
var backgroundColor = (Background as SolidColorBrush)?.Color; |
|
|
|
var backgroundColor = (Background as ISolidColorBrush)?.Color; |
|
|
|
if (backgroundColor.HasValue) |
|
|
|
{ |
|
|
|
byte red = (byte)~(backgroundColor.Value.R); |
|
|
|
byte green = (byte)~(backgroundColor.Value.G); |
|
|
|
byte blue = (byte)~(backgroundColor.Value.B); |
|
|
|
|
|
|
|
caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); |
|
|
|
caretBrush = new ImmutableSolidColorBrush(Color.FromRgb(red, green, blue)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
caretBrush = Brushes.Black; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (_caretBlink) |
|
|
|
{ |
|
|
|
var (p1, p2) = GetCaretPoints(); |
|
|
|
context.DrawLine( |
|
|
|
new Pen(caretBrush, 1), |
|
|
|
new ImmutablePen(caretBrush, 1), |
|
|
|
p1, p2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using Avalonia.Collections; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Media.Immutable; |
|
|
|
using Avalonia.Utilities; |
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
|
@ -295,7 +296,7 @@ namespace Avalonia.Controls |
|
|
|
endPoint = pt; |
|
|
|
} |
|
|
|
|
|
|
|
var pen = new Pen(Fill, 1.0d); |
|
|
|
var pen = new ImmutablePen(Fill?.ToImmutable(), 1.0d); |
|
|
|
|
|
|
|
// Is it Vertical?
|
|
|
|
if (Placement == TickBarPlacement.Left || Placement == TickBarPlacement.Right) |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Media.Immutable; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Utilities; |
|
|
|
|
|
|
|
@ -114,9 +115,9 @@ namespace Avalonia.Controls.Utils |
|
|
|
var borderThickness = _borderThickness.Top; |
|
|
|
IPen pen = null; |
|
|
|
|
|
|
|
if (borderThickness > 0) |
|
|
|
if (borderBrush != null && borderThickness > 0) |
|
|
|
{ |
|
|
|
pen = new Pen(borderBrush, borderThickness); |
|
|
|
pen = new ImmutablePen(borderBrush.ToImmutable(), borderThickness); |
|
|
|
} |
|
|
|
|
|
|
|
var rect = new Rect(_size); |
|
|
|
|