Browse Source

Fixed a bug with stale _usedCache value that wasn't reset properly (#21823)

pull/21827/head
Nikita Tsukanov 2 months ago
committed by GitHub
parent
commit
b3810fc08c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual/ServerCompositionVisual.Render.cs
  2. 52
      tests/Avalonia.RenderTests/Media/EffectTests.cs
  3. BIN
      tests/TestFiles/Skia/Media/Effects/CachedSiblingFollowedByEffect.expected.png

7
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual/ServerCompositionVisual.Render.cs

@ -192,7 +192,12 @@ partial class ServerCompositionVisual
if (visual.RenderOptions != default)
_canvas.PopRenderOptions();
}
// A cached visual is always a leaf in the walk (children are skipped), so its
// PreSubgraph/PostSubgraph are adjacent. Reset here so the flag never leaks into a
// later sibling and causes its effect/mask/options pushes to be left unpopped.
_usedCache = false;
// If we are rendering to bitmap cache, PreSubgraph skipped those for the root visual
if (!bitmapCacheRoot)
{

52
tests/Avalonia.RenderTests/Media/EffectTests.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Layout;
using Avalonia.Media;
using Xunit;
#pragma warning disable CS0649
@ -76,6 +77,55 @@ public class EffectTests : TestBase
await RenderToFile(target);
CompareImages(skipImmediate: true);
}
[Fact]
public async Task CachedSiblingFollowedByEffect()
{
var target = new Border
{
Background = Brushes.White,
Width = 200,
Height = 200,
Child = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 10,
Margin = new Thickness(15),
Children =
{
new Rectangle
{
Width = 50,
Height = 50,
Fill = Brushes.Yellow,
CacheMode = new BitmapCache()
},
new Rectangle
{
Width = 50,
Height = 50,
Fill = Brushes.Blue,
Effect = new DropShadowEffect
{
Opacity = 1,
OffsetX = 0,
OffsetY = 0,
Color = Colors.Black,
BlurRadius = 20
}
},
new Rectangle
{
Width = 50,
Height = 50,
Fill = Brushes.Green
}
}
}
};
await RenderToFile(target);
CompareImages(skipImmediate: true);
}
}
#endif

BIN
tests/TestFiles/Skia/Media/Effects/CachedSiblingFollowedByEffect.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Loading…
Cancel
Save