-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows] Fix performance issue using Shadows #18337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jsuarezruiz
wants to merge
42
commits into
main
Choose a base branch
from
fix-18205
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
2fac694
Fix shadows perf issues on Windows
jsuarezruiz 3670485
Fix shadow with clipped views
jsuarezruiz 2cb1c4c
Added more tests
jsuarezruiz c298d5a
More changes
jsuarezruiz 43d751b
Changes in ShadowExtensions
jsuarezruiz 0c0755b
More changes
jsuarezruiz 4e819a9
More changes
jsuarezruiz a295f42
More changes
jsuarezruiz 2ac51e9
Updated test
jsuarezruiz 53c95af
Updated test
jsuarezruiz f53996b
Updated snapshot
jsuarezruiz 5845cac
Updated test
jsuarezruiz 08b6d15
Fix build error
jsuarezruiz 872bb6c
Merge branch 'main' into fix-18205
jsuarezruiz 5d7c443
Merge branch 'main' into fix-18205
jsuarezruiz a47b833
Merge branch 'main' into fix-18205
jsuarezruiz b12e282
Merge branch 'main' into fix-18205
jsuarezruiz 7a3d90f
Fixes the build
jsuarezruiz 8e40516
Merge branch 'main' into fix-18205
jsuarezruiz 37bc0a5
More fixes
jsuarezruiz c1e73b3
Merge branch 'main' into fix-18205
jsuarezruiz 40f3783
Merge branch 'main' into fix-18205
jsuarezruiz ba066df
Merge branch 'main' into fix-18205
jsuarezruiz 41b7a9d
Merge branch 'main' into fix-18205
jsuarezruiz acce651
Update WrapperView.cs
jsuarezruiz 7356397
More changes
jsuarezruiz 8b22f84
Merge branch 'main' into fix-18205
jsuarezruiz 710365e
Fix test path
jsuarezruiz 9d50db7
Fix wrong namespace
jsuarezruiz f01d721
Merge branch 'main' into fix-18205
jsuarezruiz bc5a06d
Fix build error
jsuarezruiz 66da9cb
Updated test
jsuarezruiz 1780640
More changes
jsuarezruiz 87ce964
Added pending snapshot
jsuarezruiz 2011139
Updated snapshots
jsuarezruiz 6823f8b
Merge branch 'main' into fix-18205
jsuarezruiz 9aa9385
fixed nits
mattleibow 4adf5a8
Merge branch 'main' into fix-18205
mattleibow b03f828
less clutter in the namespace
mattleibow 3e5fc68
Merge branch 'main' into fix-18205
jfversluis 97cfbb1
Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18…
jfversluis 98e73ad
Update snapshots
jfversluis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
src/Controls/samples/Controls.Sample/Pages/Core/ShadowGalleries/ShadowBenchmark.cs
This file contains hidden or 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,117 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Graphics; | ||
|
|
||
| namespace Maui.Controls.Sample.Pages | ||
| { | ||
| public class ShadowBenchmark : ContentPage | ||
| { | ||
| event Action timerUpdateEvent; | ||
|
|
||
| public ShadowBenchmark() | ||
| { | ||
| Title = "Shadow Benchmark"; | ||
|
|
||
| double fps = 60; | ||
|
|
||
| var timer = Dispatcher.CreateTimer(); | ||
| timer.Interval = TimeSpan.FromSeconds(1 / fps); | ||
| double time = 0; | ||
| DateTime currentTickDateTime = DateTime.Now; | ||
| double deltaTime = 0; | ||
|
|
||
| timer.Tick += delegate | ||
mattleibow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| deltaTime = (DateTime.Now - currentTickDateTime).TotalSeconds; | ||
| currentTickDateTime = DateTime.Now; | ||
| time += deltaTime; | ||
| timerUpdateEvent?.Invoke(); | ||
| }; | ||
|
|
||
| timer.Start(); | ||
|
|
||
| AbsoluteLayout rootAbs = new AbsoluteLayout(); | ||
| Content = rootAbs; | ||
|
|
||
| Label fpsLabel = new Label | ||
| { | ||
| BackgroundColor = Colors.Black, | ||
| TextColor = Colors.White | ||
| }; | ||
|
|
||
| AbsoluteLayout abs = new AbsoluteLayout(); | ||
| rootAbs.Add(abs); | ||
| rootAbs.Add(fpsLabel); | ||
|
|
||
| VerticalStackLayout vert = new VerticalStackLayout(); | ||
| vert.BackgroundColor = Colors.LightGray; | ||
| abs.Add(vert); | ||
|
|
||
| AbsoluteLayout abs2 = new AbsoluteLayout(); | ||
| vert.Add(abs2); | ||
|
|
||
| int numBorders = 3; | ||
| List<Border> borders = new List<Border>(); | ||
|
|
||
| for (int i = 0; i < numBorders; i++) | ||
| { | ||
| Border border = new Border | ||
| { | ||
| HeightRequest = 200, | ||
| WidthRequest = 500, | ||
| BackgroundColor = Colors.DimGray | ||
| }; | ||
| abs2.Add(border); | ||
| borders.Add(border); | ||
| border.Shadow = new Shadow() { Brush = new SolidColorBrush(Colors.Black), Offset = new Point(5, 5), Radius = 5 }; | ||
| } | ||
|
|
||
| Border borderBot = new Border | ||
| { | ||
| HeightRequest = 200, | ||
| WidthRequest = 50, | ||
| BackgroundColor = Colors.DarkGray | ||
| }; | ||
| vert.Add(borderBot); | ||
|
|
||
| timerUpdateEvent += delegate | ||
| { | ||
| double sinVal = (Math.Sin(time) + 1) * 0.5; | ||
| double height = 20 + sinVal * 800; | ||
| for (int i = 0; i < borders.Count; i++) | ||
| { | ||
| borders[i].HeightRequest = height; | ||
| } | ||
| }; | ||
|
|
||
| SizeChanged += delegate | ||
| { | ||
| if (Width > 0) | ||
| { | ||
| abs.WidthRequest = Width; | ||
| abs.HeightRequest = Height; | ||
| vert.WidthRequest = Width; | ||
|
|
||
| for (int i = 0; i < borders.Count; i++) | ||
| { | ||
| borders[i].WidthRequest = Width; | ||
| borders[i].TranslationX = Width * i; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| DateTime lastUpdateDateTime = DateTime.Now; | ||
| abs2.SizeChanged += delegate | ||
| { | ||
| if (lastUpdateDateTime != DateTime.Now) | ||
| { | ||
| string fps = "FPS " + 1 / (DateTime.Now - lastUpdateDateTime).TotalSeconds; | ||
| fpsLabel.Text = fps; | ||
|
|
||
| lastUpdateDateTime = DateTime.Now; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
src/Controls/samples/Controls.Sample/Pages/Core/ShadowGalleries/ShadowMaskPage.xaml
This file contains hidden or 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,25 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <views:BasePage | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Pages.ShadowMaskPage" | ||
| xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base" | ||
| Title="Shadow Mask - Shadows respect control shape"> | ||
| <VerticalStackLayout | ||
| Padding="12"> | ||
| <Button | ||
| HorizontalOptions="Center" | ||
| Text="Shadow" | ||
| CornerRadius="60" | ||
| HeightRequest="120" | ||
| WidthRequest="120"> | ||
| <Button.Shadow> | ||
| <Shadow | ||
| Brush="Black" | ||
| Opacity="1" | ||
| Radius="10" | ||
| Offset="0, 0" /> | ||
| </Button.Shadow> | ||
| </Button> | ||
| </VerticalStackLayout> | ||
| </views:BasePage> |
10 changes: 10 additions & 0 deletions
10
src/Controls/samples/Controls.Sample/Pages/Core/ShadowGalleries/ShadowMaskPage.xaml.cs
This file contains hidden or 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,10 @@ | ||
| namespace Maui.Controls.Sample.Pages | ||
mattleibow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| public partial class ShadowMaskPage | ||
| { | ||
| public ShadowMaskPage() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
126 changes: 126 additions & 0 deletions
126
src/Controls/tests/TestCases.HostApp/Issues/Issue18172.cs
This file contains hidden or 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,126 @@ | ||
| using Microsoft.Maui.Controls.Shapes; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [Issue(IssueTracker.Github, 18172, "Shadows not drawing/updating correctly in Windows & cover entire screen", PlatformAffected.UWP)] | ||
| public class Issue18172 : TestContentPage | ||
| { | ||
| protected override void Init() | ||
| { | ||
| Title = "Issue 18172"; | ||
|
|
||
| BackgroundColor = Colors.LightPink; | ||
|
|
||
| ScreenSizeMonitor.Instance.setContentPage(this); | ||
|
|
||
| VerticalStackLayout verticalStackLayout = new VerticalStackLayout(); | ||
| Content = verticalStackLayout; | ||
|
|
||
| AbsoluteLayout absoluteLayout = new AbsoluteLayout(); | ||
| verticalStackLayout.Add(absoluteLayout); | ||
| absoluteLayout.Add(TopObjectWithShadow.Instance); | ||
| } | ||
| } | ||
|
|
||
| public class TopObjectWithShadow : AbsoluteLayout | ||
| { | ||
| public static TopObjectWithShadow Instance { get { return lazy.Value; } } | ||
| static readonly Lazy<TopObjectWithShadow> lazy = new Lazy<TopObjectWithShadow>(() => new TopObjectWithShadow()); | ||
|
|
||
| public TopSubComponent topMenuFrameComponent; | ||
|
|
||
| private TopObjectWithShadow() | ||
| { | ||
| IgnoreSafeArea = true; | ||
| topMenuFrameComponent = new TopSubComponent(); | ||
| Add(topMenuFrameComponent); | ||
| topMenuFrameComponent.Shadow = new Shadow() { Offset = new Point(0, 5), Radius = 5 }; | ||
| ScreenSizeMonitor.Instance.ScreenSizeChanged += OnScreenSizeChanged; | ||
| } | ||
|
|
||
| void OnScreenSizeChanged() | ||
| { | ||
| if (topMenuFrameComponent != null) | ||
| { | ||
| WidthRequest = ScreenSizeMonitor.Instance.screenWidth; | ||
| HeightRequest = ScreenSizeMonitor.Instance.screenHeight; | ||
|
|
||
| topMenuFrameComponent.resizeFunction(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class TopSubComponent : AbsoluteLayout | ||
| { | ||
| readonly Border _frameBorder; | ||
| readonly double _frameBaseHeight = 68; | ||
|
|
||
| public TopSubComponent() | ||
| { | ||
| _frameBorder = new Border | ||
| { | ||
| AutomationId = "BorderControl" | ||
| }; | ||
|
|
||
| Add(_frameBorder); | ||
| IgnoreSafeArea = true; | ||
| _frameBorder.HeightRequest = _frameBaseHeight; | ||
| _frameBorder.BackgroundColor = Colors.White; | ||
| _frameBorder.Margin = new Thickness(0, 20, 0, 0); | ||
| _frameBorder.StrokeShape = new RoundRectangle() { CornerRadius = new CornerRadius(30, 30, 30, 30) }; | ||
| _frameBorder.StrokeThickness = 0; | ||
| } | ||
| public void resizeFunction() | ||
| { | ||
| WidthRequest = ScreenSizeMonitor.Instance.screenWidth; | ||
| HeightRequest = ScreenSizeMonitor.Instance.screenHeight; | ||
| _frameBorder.WidthRequest = ScreenSizeMonitor.Instance.screenWidth; | ||
| _frameBorder.HeightRequest = _frameBaseHeight; | ||
| } | ||
| } | ||
| public class ScreenSizeMonitor | ||
| { | ||
| public ContentPage pageToMonitor; | ||
|
|
||
| private static readonly Lazy<ScreenSizeMonitor> lazy = new Lazy<ScreenSizeMonitor>(() => new ScreenSizeMonitor()); | ||
| public static ScreenSizeMonitor Instance { get { return lazy.Value; } } | ||
|
|
||
| public double screenWidth = 0; | ||
| public double screenHeight = 0; | ||
| public event Action ScreenSizeChanged = null; | ||
|
|
||
| public void setContentPage(ContentPage contentPageToMonitor) | ||
| { | ||
| pageToMonitor = contentPageToMonitor; | ||
| StartScreenMonitor(); | ||
| } | ||
|
|
||
| void StartScreenMonitor() | ||
| { | ||
| UpdateFunction(); | ||
|
|
||
| pageToMonitor.SizeChanged += delegate | ||
| { | ||
| UpdateFunction(); | ||
| }; | ||
| } | ||
|
|
||
| void UpdateFunction() | ||
| { | ||
| if (pageToMonitor.Width > 0 && pageToMonitor.Height > 0) | ||
| { | ||
| screenWidth = pageToMonitor.Width; | ||
| screenHeight = pageToMonitor.Height; | ||
|
|
||
| invokeScreenSizeChanged(); | ||
| } | ||
| } | ||
| public void invokeScreenSizeChanged() | ||
| { | ||
| MainThread.BeginInvokeOnMainThread(() => | ||
| { | ||
| ScreenSizeChanged?.Invoke(); | ||
| }); | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18172.cs
This file contains hidden or 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,26 @@ | ||
| #if WINDOWS // Issue only happens on Windows | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| class Issue18172 : _IssuesUITest | ||
| { | ||
| public Issue18172(TestDevice device) | ||
| : base(device) | ||
| { } | ||
|
|
||
| public override string Issue => "Shadows not drawing/updating correctly in Windows & cover entire screen"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.GraphicsView)] | ||
| public async Task Issue18172Test() | ||
| { | ||
| await Task.Delay(500); | ||
|
|
||
| VerifyScreenshot(); | ||
| } | ||
| } | ||
| } | ||
| #endif |
Binary file modified
BIN
+17 Bytes
(100%)
...ests/TestCases.WinUI.Tests/snapshots/windows/HeaderAndFooterShouldBeVisible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.54 KB
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue18172Test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-911 Bytes
(98%)
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue24414Test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-788 Bytes
(99%)
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue24414Test_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.27 KB
(97%)
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue24414Test_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.48 KB
(97%)
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue24414Test_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.48 KB
(97%)
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue24414Test_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-750 Bytes
(97%)
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Issue24414Test_5.png
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsuarezruiz I know this was wrong even before, but there should be no shadows here given that the code does |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.