-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18476 from ramezgerges/composition_path_clipping_…
…linux perf: reduce SKPaint and SKPath allocations
- Loading branch information
Showing
13 changed files
with
162 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Path_Clipping.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Page | ||
x:Class="UITests.Windows_UI_Xaml_Shapes.Path_Clipping" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:UITests.Windows_UI_Xaml_Shapes" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel> | ||
<TextBlock Text="The two icons below should not be the same (the first one should be clipped)." /> | ||
<Border Height="16" HorizontalAlignment="Stretch" /> | ||
<ScrollViewer Height="30" x:Name="sv"> | ||
<Path Fill="Red" Data="m 0,0 c -0.639,0 -1.276,0.243 -1.765,0.729 -0.977,0.974 -0.98,2.557 -0.006,3.535 L 16.925,23.032 -1.768,41.725 c -0.976,0.976 -0.976,2.559 0,3.535 0.977,0.976 2.559,0.976 3.536,0 L 22.225,24.803 c 0.975,-0.975 0.976,-2.555 0.004,-3.532 L 1.771,0.736 C 1.283,0.245 0.642,0 0,0" /> | ||
</ScrollViewer> | ||
<TextBlock Text="------------" /> | ||
<Path Fill="Red" Data="m 0,0 c -0.639,0 -1.276,0.243 -1.765,0.729 -0.977,0.974 -0.98,2.557 -0.006,3.535 L 16.925,23.032 -1.768,41.725 c -0.976,0.976 -0.976,2.559 0,3.535 0.977,0.976 2.559,0.976 3.536,0 L 22.225,24.803 c 0.975,-0.975 0.976,-2.555 0.004,-3.532 L 1.771,0.736 C 1.283,0.245 0.642,0 0,0" /> | ||
</StackPanel> | ||
</Page> |
15 changes: 15 additions & 0 deletions
15
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Path_Clipping.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Uno.UI.Samples.Controls; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace UITests.Windows_UI_Xaml_Shapes | ||
{ | ||
[Sample("Shapes", IsManualTest = true)] | ||
public sealed partial class Path_Clipping : Page | ||
{ | ||
public Path_Clipping() | ||
{ | ||
this.InitializeComponent(); | ||
Loaded += (_, _) => sv.ScrollToVerticalOffset(9999); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#nullable enable | ||
|
||
using SkiaSharp; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Uno.Disposables; | ||
using SKPaint = SkiaSharp.SKPaint; | ||
|
||
namespace Microsoft.UI.Composition | ||
{ | ||
internal static class SkiaHelper | ||
{ | ||
private static readonly ObjectPool<SKPaint> _paintPool = new(() => new SKPaint(), 8); | ||
private static readonly ObjectPool<SKPath> _pathPool = new(() => new SKPath(), 8); | ||
|
||
public static DisposableStruct<SKPath> GetTempSKPath(out SKPath path) | ||
{ | ||
path = _pathPool.Allocate(); | ||
// Note the difference between Rewind and Reset | ||
// https://api.skia.org/classSkPath.html#a8dc858ee4c95a59b3dd4bdd3f7b85fdc : "Use rewind() instead of reset() if SkPath storage will be reused and performance is critical." | ||
path.Rewind(); | ||
return new DisposableStruct<SKPath>(p => _pathPool.Free(p), path); | ||
} | ||
|
||
public static DisposableStruct<SKPaint> GetTempSKPaint(out SKPaint paint) | ||
{ | ||
paint = _paintPool.Allocate(); | ||
// https://api.skia.org/classSkPaint.html#a6c7118c97a0e8819d75aa757afbc4c49 | ||
// "This is equivalent to replacing SkPaint with the result of SkPaint()." | ||
paint.Reset(); | ||
return new DisposableStruct<SKPaint>(p => _paintPool.Free(p), paint); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.