Browse Source

Fixed incorrect opacity stack handling (#20730)

pull/20731/head
Nikita Tsukanov 7 months ago
committed by GitHub
parent
commit
f9c1570ac6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual/ServerCompositionVisual.Render.cs
  2. 55
      tests/Avalonia.RenderTests/BugRepros.cs
  3. BIN
      tests/TestFiles/Skia/BugRepros/Sibling_Visuals_With_Opacity_Should_Not_Affect_Each_Other.expected.png

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

@ -94,7 +94,8 @@ partial class ServerCompositionVisual
if (visual.Opacity != 1)
{
_opacityStack.Push(effectiveOpacity);
_opacityStack.Push(_opacity);
_opacity = effectiveOpacity;
_canvas.PushOpacity(visual.Opacity, visual._transformedSubTreeBounds.Value.ToRect());
}

55
tests/Avalonia.RenderTests/BugRepros.cs

@ -0,0 +1,55 @@
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Layout;
using Avalonia.Media;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
namespace Avalonia.Skia.RenderTests;
public class BugRepros() : TestBase(nameof(BugRepros))
{
[Fact]
public async Task Sibling_Visuals_With_Opacity_Should_Not_Affect_Each_Other()
{
var brushes = new IBrush[]
{
Brushes.Red,
Brushes.Green,
Brushes.Blue,
Brushes.Yellow,
Brushes.Magenta,
Brushes.Cyan,
Brushes.Orange,
Brushes.Purple,
Brushes.Pink,
Brushes.Brown
};
var stackPanel = new StackPanel
{
Orientation = Orientation.Vertical,
Width = 300,
Height = 500,
Background = Brushes.White,
};
for (int i = 0; i < brushes.Length; i++)
{
var border = new Border
{
Width = 280,
Height = 40,
BorderThickness = new Thickness(2),
Margin = new Thickness(5),
Background = brushes[i],
Opacity = 0.3
};
stackPanel.Children.Add(border);
}
await RenderToFile(stackPanel);
CompareImages();
}
}

BIN
tests/TestFiles/Skia/BugRepros/Sibling_Visuals_With_Opacity_Should_Not_Affect_Each_Other.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Loading…
Cancel
Save