Skip to content

Commit 9e73473

Browse files
committed
chore: Address comments
1 parent 4c71ba3 commit 9e73473

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/Uno.UI.Composition/Composition/AnimatedImageFrameProvider.skia.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal sealed class AnimatedImageFrameProvider : IFrameProvider
1919
private readonly WeakReference<Action> _onFrameChanged;
2020

2121
private int _currentFrame;
22-
private bool _disposed;
22+
private int _disposed;
2323

2424
// Note: The Timer will keep holding onto the AnimatedImageFrameProvider until stopped (it's a static root).
2525
// But we only stop the timer when we dispose AnimatedImageFrameProvider from SkiaCompositionSurface finalizer.
@@ -118,9 +118,8 @@ private void OnTimerCallback(object? state)
118118

119119
public void Dispose()
120120
{
121-
if (!_disposed)
121+
if (Interlocked.Exchange(ref _disposed, 1) == 0)
122122
{
123-
_disposed = true;
124123
_timer?.Dispose();
125124

126125
for (int i = 0; i < _images.Length; i++)

src/Uno.UI.Composition/Composition/FrameProviderFactory.skia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static bool TryCreate(SKManagedStream stream, Action onFrameChanged, [Not
3737

3838
var images = GC.AllocateUninitializedArray<SKImage>(frameInfos.Length);
3939
var durations = new int[frameInfos.Length];
40-
var totalDuration = 0;
40+
long totalDuration = 0;
4141

4242
for (int i = 0; i < frameInfos.Length; i++)
4343
{

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Image.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -862,16 +862,23 @@ public async Task When_AnimatedWebP_Changes_Frames()
862862
var screenshot1 = await UITestHelper.ScreenShot(image);
863863
var pixel1 = screenshot1.GetPixel(screenshot1.Width / 2, screenshot1.Height / 2);
864864

865-
// Wait long enough for animation to advance (frames are 200ms each).
866-
await Task.Delay(400);
867-
868-
// Take second screenshot - at least one should differ because the animation cycles.
869-
var screenshot2 = await UITestHelper.ScreenShot(image);
870-
var pixel2 = screenshot2.GetPixel(screenshot2.Width / 2, screenshot2.Height / 2);
865+
// Poll until the center pixel changes (animation has frames every 200ms).
866+
// Use a polling loop instead of a fixed delay to avoid flakiness on slow CI.
867+
var changed = false;
868+
var sw = Stopwatch.StartNew();
869+
while (sw.Elapsed < TimeSpan.FromSeconds(5))
870+
{
871+
await Task.Delay(100);
872+
var screenshot2 = await UITestHelper.ScreenShot(image);
873+
var pixel2 = screenshot2.GetPixel(screenshot2.Width / 2, screenshot2.Height / 2);
874+
if (pixel2 != pixel1)
875+
{
876+
changed = true;
877+
break;
878+
}
879+
}
871880

872-
// The animated WebP has red, green, blue, yellow, cyan, magenta frames.
873-
// After enough delay, the center pixel should have changed color at least once.
874-
Assert.AreNotEqual(pixel1, pixel2, "Animated WebP should show different frames over time");
881+
Assert.IsTrue(changed, "Animated WebP should show different frames over time");
875882
}
876883
#endif
877884
}

0 commit comments

Comments
 (0)