From 7e1efb33e2d8a7b87223450948cfc718e2f979de Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 27 May 2017 11:45:31 +0200 Subject: [PATCH] Added failing render test. Deferred rendering does not yet support clipping in `Visual.Render`. --- .../Controls/CustomRenderTests.cs | 60 ++++++++++++++---- .../Controls/CustomRender/Clip.expected.png | Bin 0 -> 766 bytes .../Controls/CustomRender/Clip.expected.png | Bin 0 -> 766 bytes .../Controls/CustomRender/Clip.expected.png | Bin 0 -> 766 bytes 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png create mode 100644 tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png create mode 100644 tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png diff --git a/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs b/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs index f87b1b5a15..995b285df1 100644 --- a/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs +++ b/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs @@ -1,6 +1,7 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using System; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Layout; @@ -23,37 +24,68 @@ namespace Avalonia.Direct2D1.RenderTests.Controls } [Fact] - public async Task Opacity() + public async Task Clip() { Decorator target = new Decorator { Padding = new Thickness(8), Width = 200, Height = 200, - Child = new OpacityRenderer(), + Child = new CustomRenderer((control, context) => + { + context.FillRectangle( + Brushes.Red, + control.Bounds, + 4); + + using (context.PushClip(control.Bounds.Deflate(20))) + { + context.FillRectangle( + Brushes.Blue, + control.Bounds, + 4); + } + }), }; await RenderToFile(target); CompareImages(); } - class OpacityRenderer : Control + [Fact] + public async Task Opacity() { - public override void Render(DrawingContext context) + Decorator target = new Decorator { - context.FillRectangle( - Brushes.Red, - Bounds, - 4); - - using (context.PushOpacity(0.5)) + Padding = new Thickness(8), + Width = 200, + Height = 200, + Child = new CustomRenderer((control, context) => { context.FillRectangle( - Brushes.Blue, - Bounds.Deflate(20), + Brushes.Red, + control.Bounds, 4); - } - } + + using (context.PushOpacity(0.5)) + { + context.FillRectangle( + Brushes.Blue, + control.Bounds.Deflate(20), + 4); + } + }), + }; + + await RenderToFile(target); + CompareImages(); + } + + class CustomRenderer : Control + { + private Action _render; + public CustomRenderer(Action render) => _render = render; + public override void Render(DrawingContext context) => _render(this, context); } } } diff --git a/tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png b/tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..3347370368a9ecbd9713c1f9e105fe73610d8cfb GIT binary patch literal 766 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZk(GggX@#eYV@O5Z+nb6-B90Ob7b8uKgbuPQ6|wV8TwTD%=fu+9(b0cEN#M1E z!UdiBpyZ!jr*Z<{T&XsVwcWiawEpVm&D=m!;XwT9hI6z3L`^d{uAT8QPi#-sKOwyf znUQ_Qch6V+&w6LhzUkOU4W4f)PCpH+e?60FteNAQcfEguwD8HhmP|jNeM#t_C%4^< z-KhHv>u;0&&JFg094w6v0wCf?dj3YfxU!G(mVcjKD{q1bf@MYtXb=s2Kv=B#+&y=m z{tb0?c)SU4w4806Gwtc`D(>Az)xRtHgrC&SP0W`&_tE~uZOQrR3$MQpFZh_||9{TQ zw9lMIi8XTzZMo}aJuK|*Hmm+&@i;F}z3=Jid`=&|U1tQIx`2|Jr>mdKI;Vst05mk$ A9RL6T literal 0 HcmV?d00001 diff --git a/tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png b/tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..3347370368a9ecbd9713c1f9e105fe73610d8cfb GIT binary patch literal 766 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZk(GggX@#eYV@O5Z+nb6-B90Ob7b8uKgbuPQ6|wV8TwTD%=fu+9(b0cEN#M1E z!UdiBpyZ!jr*Z<{T&XsVwcWiawEpVm&D=m!;XwT9hI6z3L`^d{uAT8QPi#-sKOwyf znUQ_Qch6V+&w6LhzUkOU4W4f)PCpH+e?60FteNAQcfEguwD8HhmP|jNeM#t_C%4^< z-KhHv>u;0&&JFg094w6v0wCf?dj3YfxU!G(mVcjKD{q1bf@MYtXb=s2Kv=B#+&y=m z{tb0?c)SU4w4806Gwtc`D(>Az)xRtHgrC&SP0W`&_tE~uZOQrR3$MQpFZh_||9{TQ zw9lMIi8XTzZMo}aJuK|*Hmm+&@i;F}z3=Jid`=&|U1tQIx`2|Jr>mdKI;Vst05mk$ A9RL6T literal 0 HcmV?d00001 diff --git a/tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png b/tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..3347370368a9ecbd9713c1f9e105fe73610d8cfb GIT binary patch literal 766 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZk(GggX@#eYV@O5Z+nb6-B90Ob7b8uKgbuPQ6|wV8TwTD%=fu+9(b0cEN#M1E z!UdiBpyZ!jr*Z<{T&XsVwcWiawEpVm&D=m!;XwT9hI6z3L`^d{uAT8QPi#-sKOwyf znUQ_Qch6V+&w6LhzUkOU4W4f)PCpH+e?60FteNAQcfEguwD8HhmP|jNeM#t_C%4^< z-KhHv>u;0&&JFg094w6v0wCf?dj3YfxU!G(mVcjKD{q1bf@MYtXb=s2Kv=B#+&y=m z{tb0?c)SU4w4806Gwtc`D(>Az)xRtHgrC&SP0W`&_tE~uZOQrR3$MQpFZh_||9{TQ zw9lMIi8XTzZMo}aJuK|*Hmm+&@i;F}z3=Jid`=&|U1tQIx`2|Jr>mdKI;Vst05mk$ A9RL6T literal 0 HcmV?d00001