Skip to content

Commit

Permalink
Speed-up Border rendering by avoiding useless pass during size alloca…
Browse files Browse the repository at this point in the history
…tion (dotnet#24844)

* Speed-up Border rendering by avoiding useless pass during size allocation

* User `BorderHandler.PlatformArrange` instead of `SizeAllocated`
  • Loading branch information
albyrock87 authored Oct 17, 2024
1 parent 51e8735 commit c177617
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/Controls/src/Core/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,15 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
{
base.OnPropertyChanged(propertyName);

if (propertyName == HeightProperty.PropertyName ||
propertyName == StrokeThicknessProperty.PropertyName ||
propertyName == StrokeShapeProperty.PropertyName ||
propertyName == WidthProperty.PropertyName)
if (propertyName == StrokeThicknessProperty.PropertyName || propertyName == StrokeShapeProperty.PropertyName)
{
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
UpdateStrokeShape();
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
}
else if (propertyName == StrokeDashArrayProperty.PropertyName)
{
Handler?.UpdateValue(nameof(IBorderStroke.StrokeDashPattern));
}
}

void OnStrokeDashArrayChanged(object? sender, NotifyCollectionChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#nullable enable
override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#nullable enable
#nullable enable
16 changes: 16 additions & 0 deletions src/Core/src/Handlers/Border/BorderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using PlatformView = System.Object;
#endif

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Handlers
{
/// <summary>
Expand Down Expand Up @@ -40,6 +42,8 @@ public partial class BorderHandler : IBorderHandler
public static CommandMapper<IBorderView, BorderHandler> CommandMapper = new(ViewCommandMapper)
{
};

private Size _lastSize;

public BorderHandler() : base(Mapper, CommandMapper)
{
Expand All @@ -60,6 +64,18 @@ public BorderHandler(IPropertyMapper? mapper, CommandMapper? commandMapper)

PlatformView IBorderHandler.PlatformView => PlatformView;

/// <inheritdoc />
public override void PlatformArrange(Rect rect)
{
base.PlatformArrange(rect);

if (_lastSize != rect.Size)
{
_lastSize = rect.Size;
UpdateValue(nameof(IBorderStroke.Shape));
}
}

/// <summary>
/// Maps the abstract <see cref="IView.Background"/> property to the platform-specific implementations.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
3 changes: 2 additions & 1 deletion src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
override Microsoft.Maui.Platform.MauiCALayer.AddAnimation(CoreAnimation.CAAnimation! animation, string? key) -> void
*REMOVED*override Microsoft.Maui.Handlers.BorderHandler.ConnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
*REMOVED*override Microsoft.Maui.Handlers.BorderHandler.ConnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
override Microsoft.Maui.Platform.MauiCALayer.AddAnimation(CoreAnimation.CAAnimation! animation, string? key) -> void
*REMOVED*override Microsoft.Maui.Handlers.BorderHandler.ConnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
1 change: 1 addition & 0 deletions src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
1 change: 1 addition & 0 deletions src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
1 change: 1 addition & 0 deletions src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
1 change: 1 addition & 0 deletions src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void

0 comments on commit c177617

Please sign in to comment.