1- using System ;
2- using System . Collections . Generic ;
1+ #if __SKIA__
32using System . Linq ;
43using System . Numerics ;
5- using System . Text ;
64using System . Threading . Tasks ;
5+ using Windows . Foundation ;
76using Windows . UI ;
8- using Private . Infrastructure ;
9- using Microsoft . UI . Composition ;
7+ using Microsoft . UI . Xaml ;
108using Microsoft . UI . Xaml . Controls ;
9+ using Private . Infrastructure ;
10+ using Microsoft . UI . Xaml . Controls . Primitives ;
1111using Microsoft . UI . Xaml . Media ;
1212using Microsoft . UI . Xaml . Shapes ;
13+ using SamplesApp . UITests ;
14+ using SkiaSharp ;
15+ using Uno . Disposables ;
16+ using Uno . Extensions . Specialized ;
1317using Uno . UI . RuntimeTests . Helpers ;
18+ using Uno . WinUI . Graphics2DSK ;
19+ using CollectionExtensions = Uno . Extensions . CollectionExtensions ;
20+ using RectExtensions = Uno . Extensions . RectExtensions ;
1421
1522namespace Uno . UI . RuntimeTests . Tests . Windows_UI_Composition ;
1623
17- #if __SKIA__
1824[ TestClass ]
25+ [ RunsOnUIThread ]
1926public class Given_ContainerVisual
2027{
2128 [ TestMethod ]
@@ -47,7 +54,6 @@ public void When_Children_Change()
4754 }
4855
4956 [ TestMethod ]
50- [ RunsOnUIThread ]
5157 public async Task When_Child_Removed_TotalMatrix_Updated ( )
5258 {
5359 var compositor = TestServices . WindowHelper . XamlRoot . Compositor ;
@@ -63,5 +69,69 @@ public async Task When_Child_Removed_TotalMatrix_Updated()
6369 parent2 . Children . InsertAtTop ( child ) ;
6470 Assert . IsFalse ( child . TotalMatrix . IsIdentity ) ;
6571 }
72+
73+ [ TestMethod ]
74+ public async Task When_SKPicture_Collapsing_Optimization ( )
75+ {
76+ var oldValues =
77+ ( FeatureConfiguration . Rendering . EnableVisualSubtreeSkippingOptimization ,
78+ FeatureConfiguration . Rendering . VisualSubtreeSkippingOptimizationCleanFramesThreshold ,
79+ FeatureConfiguration . Rendering . VisualSubtreeSkippingOptimizationVisualCountThreshold ) ;
80+ using var _ = Disposable . Create ( ( ) =>
81+ {
82+ ( FeatureConfiguration . Rendering . EnableVisualSubtreeSkippingOptimization ,
83+ FeatureConfiguration . Rendering . VisualSubtreeSkippingOptimizationCleanFramesThreshold ,
84+ FeatureConfiguration . Rendering . VisualSubtreeSkippingOptimizationVisualCountThreshold ) = oldValues ;
85+ } ) ;
86+ ( FeatureConfiguration . Rendering . EnableVisualSubtreeSkippingOptimization ,
87+ FeatureConfiguration . Rendering . VisualSubtreeSkippingOptimizationCleanFramesThreshold ,
88+ FeatureConfiguration . Rendering . VisualSubtreeSkippingOptimizationVisualCountThreshold ) = ( true , 50 , 100 ) ;
89+ var popup = new Popup ( )
90+ {
91+ Child = new StackPanel ( ) . Apply ( sp => Enumerable . Range ( 0 , 100 ) . ForEach ( i =>
92+ sp . Children . Add ( new Rectangle
93+ {
94+ Fill = new SolidColorBrush ( Colors . Red ) ,
95+ Width = 100 ,
96+ Height = 100
97+ } ) ) )
98+ } ;
99+
100+ var skce = new FrameCounterSKCanvasElement ( ) { Width = 100 , Height = 100 } ;
101+ popup . PlacementTarget = skce ;
102+ popup . DesiredPlacement = PopupPlacementMode . Bottom ;
103+ await UITestHelper . Load ( new StackPanel { Children = { skce , popup } } ) ;
104+
105+ for ( int i = 0 ; i < 200 ; i ++ )
106+ {
107+ popup . IsOpen = ! popup . IsOpen ;
108+ await UITestHelper . WaitForIdle ( ) ;
109+ var count = skce . FrameCounter ;
110+ await UITestHelper . WaitFor ( ( ) => skce . FrameCounter > count ) ;
111+ }
112+
113+ popup . IsOpen = true ;
114+ await UITestHelper . WaitForIdle ( ) ;
115+ var p = ( popup . Child as FrameworkElement ) . GetAbsoluteBoundsRect ( ) . GetLocation ( ) . Offset ( 50 , 50 ) ;
116+
117+ var screenShot1 = await UITestHelper . ScreenShot ( ( ( FrameworkElement ) TestServices . WindowHelper . XamlRoot . VisualTree . RootElement ) ! ) ;
118+ ImageAssert . HasColorAt ( screenShot1 , p , Colors . Red ) ;
119+
120+ popup . IsOpen = false ;
121+ await UITestHelper . WaitForIdle ( ) ;
122+
123+ var screenShot2 = await UITestHelper . ScreenShot ( ( ( FrameworkElement ) TestServices . WindowHelper . XamlRoot . VisualTree . RootElement ) ! ) ;
124+ ImageAssert . DoesNotHaveColorAt ( screenShot2 , p , Colors . Red ) ;
125+ }
126+
127+ private class FrameCounterSKCanvasElement : SKCanvasElement
128+ {
129+ public int FrameCounter { get ; private set ; }
130+ protected override void RenderOverride ( SKCanvas canvas , Size area )
131+ {
132+ FrameCounter ++ ;
133+ Invalidate ( ) ;
134+ }
135+ }
66136}
67137#endif
0 commit comments