-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 #12568 from JetBrains/fixes/clip-bounds-invalidate
Enhanced Clipping and Rendered Visuals Tracking in ServerCompositionVisual
- Loading branch information
Showing
5 changed files
with
105 additions
and
5 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
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
68 changes: 68 additions & 0 deletions
68
tests/Avalonia.Base.UnitTests/Rendering/CompositorInvalidationClippingTests.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,68 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Media; | ||
using Xunit; | ||
|
||
namespace Avalonia.Base.UnitTests.Rendering; | ||
/// <summary> | ||
/// Test class that verifies how clipping influences rendering in the compositor | ||
/// </summary> | ||
public class CompositorInvalidationClippingTests : CompositorTestsBase | ||
{ | ||
[Fact] | ||
// Test case: When the ClipToBounds is false, all visuals should be rendered | ||
public void Siblings_Should_Be_Rendered_On_Invalidate_Without_ClipToBounds() | ||
{ | ||
AssertRenderedVisuals(clipToBounds: false, clipGeometry: false, expectedRenderedVisualsCount: 4); | ||
} | ||
|
||
[Fact] | ||
// Test case: When the ClipToBounds is true, only visuals within the clipped boundary should be rendered | ||
public void Siblings_Should_Not_Be_Rendered_On_Invalidate_With_ClipToBounds() | ||
{ | ||
AssertRenderedVisuals(clipToBounds: true, clipGeometry: false, expectedRenderedVisualsCount: 3); | ||
} | ||
|
||
[Fact] | ||
// Test case: When the Clip is used, only visuals within the clip geometry should be rendered | ||
public void Siblings_Should_Not_Be_Rendered_On_Invalidate_With_Clip() | ||
{ | ||
AssertRenderedVisuals(clipToBounds: false, clipGeometry: true, expectedRenderedVisualsCount: 3); | ||
} | ||
|
||
private void AssertRenderedVisuals(bool clipToBounds, bool clipGeometry, int expectedRenderedVisualsCount) | ||
{ | ||
using (var s = new CompositorCanvas()) | ||
{ | ||
//#1 visual is top level | ||
//#2 visual is s.Canvas | ||
|
||
//#3 visual is border1 | ||
s.Canvas.Children.Add(new Border() | ||
{ | ||
[Canvas.LeftProperty] = 0, [Canvas.TopProperty] = 0, | ||
Width = 20, Height = 10, | ||
Background = Brushes.Red, | ||
ClipToBounds = clipToBounds, | ||
Clip = clipGeometry ? new RectangleGeometry(new Rect(new Size(20, 10))) : null | ||
}); | ||
|
||
//#4 visual is border2 | ||
s.Canvas.Children.Add(new Border() | ||
{ | ||
[Canvas.LeftProperty] = 30, [Canvas.TopProperty] = 50, | ||
Width = 20, Height = 10, | ||
Background = Brushes.Red, | ||
ClipToBounds = clipToBounds, | ||
Clip = clipGeometry ? new RectangleGeometry(new Rect(new Size(20, 10))) : null | ||
}); | ||
s.RunJobs(); | ||
s.Events.Reset(); | ||
|
||
//invalidate border1 | ||
s.Canvas.Children[0].IsVisible = false; | ||
s.RunJobs(); | ||
|
||
s.AssertRenderedVisuals(expectedRenderedVisualsCount); | ||
} | ||
} | ||
} |
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