From e8c3bf593fd6f297fcb06c820dd5d8dce3f2d1f0 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Thu, 13 Jun 2024 19:42:57 +0000 Subject: [PATCH] Fix tile mode used in SkShader for a TileBrush with None TileMode (#16021) * add cross test for tile brush with None tile mode * use Decal skshader tile mode for tile brush tilemode None --- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 8 ++--- .../CrossTests/Brushes/CrossTileBrushTests.cs | 32 ++++++++++++++++++ ...ender_TileBrush_With_TileMode_None.wpf.png | Bin 0 -> 398 bytes 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_TileBrush_With_TileMode_None.wpf.png diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index c54643a8daa..0a6a2187a35 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -1072,14 +1072,14 @@ private void ConfigureTileBrush(ref PaintWrapper paintWrapper, Rect targetBox, I SKShaderTileMode tileX = tileBrush.TileMode == TileMode.None - ? SKShaderTileMode.Clamp + ? SKShaderTileMode.Decal : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY ? SKShaderTileMode.Mirror : SKShaderTileMode.Repeat; SKShaderTileMode tileY = tileBrush.TileMode == TileMode.None - ? SKShaderTileMode.Clamp + ? SKShaderTileMode.Decal : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY ? SKShaderTileMode.Mirror : SKShaderTileMode.Repeat; @@ -1225,14 +1225,14 @@ private void ConfigureSceneBrushContentWithPicture(ref PaintWrapper paintWrapper SKShaderTileMode tileX = tileBrush.TileMode == TileMode.None - ? SKShaderTileMode.Clamp + ? SKShaderTileMode.Decal : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY ? SKShaderTileMode.Mirror : SKShaderTileMode.Repeat; SKShaderTileMode tileY = tileBrush.TileMode == TileMode.None - ? SKShaderTileMode.Clamp + ? SKShaderTileMode.Decal : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY ? SKShaderTileMode.Mirror : SKShaderTileMode.Repeat; diff --git a/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs b/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs index 13d4930bc97..db5a75e02b8 100644 --- a/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs +++ b/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs @@ -108,6 +108,38 @@ public void Should_Render_Aligned_TileBrush() } + [CrossFact] + public void Should_Render_TileBrush_With_TileMode_None() + { + var brush = new CrossDrawingBrush + { + TileMode = TileMode.None, + Stretch = Stretch.Fill, + Viewbox = new Rect(0, 0, 50, 50), + ViewboxUnits = BrushMappingMode.Absolute, + Viewport = new Rect(0, 0, 50, 50), + ViewportUnits = BrushMappingMode.Absolute, + Drawing = new CrossDrawingGroup() + { + Children = new List() + { + new CrossGeometryDrawing(new CrossRectangleGeometry(new(0, 0, 50, 50))) + { + Brush = new CrossSolidColorBrush(Colors.Crimson) + }, + } + } + }; + + RenderAndCompare(new CrossControl() + { + Width = 200, + Height = 200, + Background = brush + }); + + } + [CrossFact] public void Should_Render_With_Transform() { diff --git a/tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_TileBrush_With_TileMode_None.wpf.png b/tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_TileBrush_With_TileMode_None.wpf.png new file mode 100644 index 0000000000000000000000000000000000000000..7c4a13b7bd41f4930a375708129c2f541760178e GIT binary patch literal 398 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZkrl}2EbxddW??`q<)A;WS3ujRsS8y$?AMCt&*Ppyb3SVv2TPNK0{sb~7w8Te;w2xm9p_?6sg|Df PA7s0ytDnm{r-UW|qI^jn literal 0 HcmV?d00001