From eecd3555f97c9a19307c2edec2994ae2483ae6d0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 24 Nov 2018 16:38:41 +0100 Subject: [PATCH] Fix DPI in ImageBrushImpl. And add expected output for tests. D2D now passes, skia still renders incorrectly. --- .../Rendering/Utilities/TileBrushCalculator.cs | 14 +++++--------- .../Avalonia.Direct2D1/Media/ImageBrushImpl.cs | 5 +++-- .../VisualBrush_Checkerboard_144_Dpi.expected.png | Bin 0 -> 752 bytes .../VisualBrush_Checkerboard_192_Dpi.expected.png | Bin 0 -> 732 bytes .../VisualBrush_Checkerboard_144_Dpi.expected.png | Bin 0 -> 752 bytes .../VisualBrush_Checkerboard_192_Dpi.expected.png | Bin 0 -> 732 bytes 6 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Checkerboard_144_Dpi.expected.png create mode 100644 tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Checkerboard_192_Dpi.expected.png create mode 100644 tests/TestFiles/Skia/Media/VisualBrush/VisualBrush_Checkerboard_144_Dpi.expected.png create mode 100644 tests/TestFiles/Skia/Media/VisualBrush/VisualBrush_Checkerboard_192_Dpi.expected.png diff --git a/src/Avalonia.Visuals/Rendering/Utilities/TileBrushCalculator.cs b/src/Avalonia.Visuals/Rendering/Utilities/TileBrushCalculator.cs index 97af33c3e2..52a8fb5ab7 100644 --- a/src/Avalonia.Visuals/Rendering/Utilities/TileBrushCalculator.cs +++ b/src/Avalonia.Visuals/Rendering/Utilities/TileBrushCalculator.cs @@ -9,7 +9,6 @@ namespace Avalonia.Rendering.Utilities { private readonly Size _imageSize; private readonly Rect _drawRect; - private readonly Vector _dpi; public bool IsValid { get; } @@ -19,7 +18,7 @@ namespace Avalonia.Rendering.Utilities /// The brush to be rendered. /// The size of the content of the tile brush. /// The size of the control to which the brush is being rendered. - public TileBrushCalculator(ITileBrush brush, Size contentSize, Size targetSize, Vector dpi) + public TileBrushCalculator(ITileBrush brush, Size contentSize, Size targetSize) : this( brush.TileMode, brush.Stretch, @@ -28,8 +27,7 @@ namespace Avalonia.Rendering.Utilities brush.SourceRect, brush.DestinationRect, contentSize, - targetSize, - dpi) + targetSize) { } @@ -52,14 +50,12 @@ namespace Avalonia.Rendering.Utilities RelativeRect sourceRect, RelativeRect destinationRect, Size contentSize, - Size targetSize, - Vector dpi) + Size targetSize) { _imageSize = contentSize; - _dpi = dpi; - SourceRect = sourceRect.ToPixels(_imageSize) * (_dpi / 96); - DestinationRect = destinationRect.ToPixels(targetSize) * (dpi / 96); + SourceRect = sourceRect.ToPixels(_imageSize); + DestinationRect = destinationRect.ToPixels(targetSize); var scale = stretch.CalculateScaling(DestinationRect.Size, SourceRect.Size); var translate = CalculateTranslate(alignmentX, alignmentY, SourceRect, DestinationRect, scale); diff --git a/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs index 6c2a88af17..2ca2a77fb8 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs @@ -20,8 +20,9 @@ namespace Avalonia.Direct2D1.Media BitmapImpl bitmap, Size targetSize) { - var calc = new TileBrushCalculator(brush, bitmap.PixelSize.ToSize(96), targetSize, new Vector(target.DotsPerInch.Width, target.DotsPerInch.Height)); - + var dpi = new Vector(target.DotsPerInch.Width, target.DotsPerInch.Height); + var calc = new TileBrushCalculator(brush, bitmap.PixelSize.ToSize(dpi), targetSize); + if (!calc.NeedsIntermediate) { _bitmap = bitmap.GetDirect2DBitmap(target); diff --git a/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Checkerboard_144_Dpi.expected.png b/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Checkerboard_144_Dpi.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..7e674b849ae4f5763b302d07b57aff122e612679 GIT binary patch literal 752 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZkrl}2EbxddW?&Fg1z|?dAe9dc3{0(_E{-7;ac}P^<}o`8xE{PY=Z^V(0q5tX zVO*Z8yKWr#^=4(K>GjIFzikTk-;1w%S@om(_u0DNum7(9uKuCXL4kv%2@7$kbbk8( zqo3~2OWXfVM%xNb!1@J z*w6hZkrl}2EbxddW?+zQ2Vutkryo-p7?=t@T^vIy;@;j>%sb*B;CisoZ=ZR2N8&fe z?M_jlDry(q{d>cT=bqnr{=nZ#ySQC#|MUOVM%xNb!1@J z*w6hZkrl}2EbxddW?&Fg1z|?dAe9dc3{0(_E{-7;ac}P^<}o`8xE{PY=Z^V(0q5tX zVO*Z8yKWr#^=4(K>GjIFzikTk-;1w%S@om(_u0DNum7(9uKuCXL4kv%2@7$kbbk8( zqo3~2OWXfVM%xNb!1@J z*w6hZkrl}2EbxddW?+zQ2Vutkryo-p7?=t@T^vIy;@;j>%sb*B;CisoZ=ZR2N8&fe z?M_jlDry(q{d>cT=bqnr{=nZ#ySQC#|MUO