diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml
index 06e919762b3e..82e1e8774c45 100644
--- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml
+++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml
@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:skia="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
x:Name="_basicShapesTestRoot">
@@ -38,6 +39,10 @@
Content="Generate screenshots"
Click="GenerateScreenshots"
Margin="5,0,0,0" />
+
diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml.cs
index 5624bca6d9fc..b273cfb67830 100644
--- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml.cs
+++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Basic_Shapes.xaml.cs
@@ -259,7 +259,22 @@ private void Update()
private async void GenerateScreenshots(object sender, RoutedEventArgs e)
{
-#if WINDOWS_UWP
+#if __SKIA__
+ // Workaround to avoid issue #7829
+ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, GenerateScreenshots);
+#else
+ await GenerateScreenshots();
+#endif
+ }
+ private async
+#if __SKIA__
+ void
+#else
+ Task
+#endif
+ GenerateScreenshots()
+ {
+#if WINDOWS_UWP || __SKIA__
_root.Visibility = Visibility.Collapsed;
var folder = await new FolderPicker { FileTypeFilter = { "*" } }.PickSingleFolderAsync();
@@ -271,81 +286,38 @@ private async void GenerateScreenshots(object sender, RoutedEventArgs e)
var alteratorsMap = _stretches.SelectMany(stretch => _sizes.Select(size => new[] { stretch, size })).ToArray();
foreach (var shape in _shapes)
- foreach (var alterators in alteratorsMap)
- {
- var fileName = shape.Name + "_" + string.Join("_", alterators.Select(a => a.Id)) + ".png";
- var grid = BuildHoriVertTestGridForScreenshot(shape, alterators);
- _testZone.Child = grid;
- await Task.Yield();
+ foreach (var alterators in alteratorsMap)
+ {
+ var fileName = shape.Name + "_" + string.Join("_", alterators.Select(a => a.Id)) + ".png";
+ var grid = BuildHoriVertTestGridForScreenshot(shape, alterators);
+ _testZone.Child = grid;
+ await Task.Yield();
- var renderer = new RenderTargetBitmap();
- await renderer.RenderAsync(grid);
+ var renderer = new RenderTargetBitmap();
+ await renderer.RenderAsync(grid);
- var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
- using (var output = await file.OpenAsync(FileAccessMode.ReadWrite))
- {
- var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, output);
- encoder.SetSoftwareBitmap(SoftwareBitmap.CreateCopyFromBuffer(await renderer.GetPixelsAsync(), BitmapPixelFormat.Bgra8, renderer.PixelWidth, renderer.PixelHeight));
- await encoder.FlushAsync();
- await output.FlushAsync();
+ var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
+ using (var output = await file.OpenAsync(FileAccessMode.ReadWrite))
+ {
+ var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, output);
+ encoder.SetSoftwareBitmap(SoftwareBitmap.CreateCopyFromBuffer(await renderer.GetPixelsAsync(), BitmapPixelFormat.Bgra8, renderer.PixelWidth, renderer.PixelHeight));
+ await encoder.FlushAsync();
+ await output.FlushAsync();
+ }
}
- }
_root.Visibility = Visibility.Visible;
_testZone.Child = null;
#endif
}
-
-#if __IOS__ // This is the base work for a fix in the UITests in order to highly increase Screenshot speed. It will be removed by https://github.com/unoplatform/Uno.UITest/issues/39
- private static byte[] RenderAsPng(FrameworkElement elt)
- {
- UIImage img;
- try
- {
- UIGraphics.BeginImageContextWithOptions(new Size(elt.ActualWidth, elt.ActualHeight), true, UIScreen.MainScreen.Scale);
- var ctx = UIGraphics.GetCurrentContext();
- ctx.SetFillColor(Colors.White);
- elt.Layer.RenderInContext(ctx);
- img = UIGraphics.GetImageFromCurrentImageContext();
- }
- finally
- {
- UIGraphics.EndImageContext();
- }
-
- using (img)
- {
- return img.AsPNG().ToArray();
- }
- }
-#elif __ANDROID__
- private static byte[] RenderAsPng(FrameworkElement elt)
- {
- Android.Graphics.Bitmap b = Android.Graphics.Bitmap.CreateBitmap((int)ViewHelper.LogicalToPhysicalPixels(elt.ActualWidth), (int)ViewHelper.LogicalToPhysicalPixels(elt.ActualHeight), Android.Graphics.Bitmap.Config.Argb8888);
- Android.Graphics.Canvas c = new Android.Graphics.Canvas(b);
- var view = elt as Android.Views.View;
-
- view.Layout(0, 0, (int)ViewHelper.LogicalToPhysicalPixels(elt.ActualWidth), (int)ViewHelper.LogicalToPhysicalPixels(elt.ActualHeight));
- c.DrawColor(Android.Graphics.Color.White);
- view.Draw(c);
- using var stream = new MemoryStream();
- b.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream);
-
- return stream.ToArray();
- }
-#else
- private static byte[] RenderAsPng(FrameworkElement elt)
- => throw new NotImplementedException("Not supported yet on this platform");
-#endif
-
public string RunTests(string testNames)
{
TestResult = "";
- var tests = testNames.Split(new [] {';'}, StringSplitOptions.RemoveEmptyEntries);
+ var tests = testNames.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var id = Guid.NewGuid().ToString("N");
- _ = ((DependencyObject)this).Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => _ = RunTestsCore(tests));
+ _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => _ = RunTestsCore(tests));
return id;
@@ -353,7 +325,7 @@ async Task RunTestsCore(string[] strings)
{
var result = new StringBuilder();
result.AppendLine(id);
-
+ var renderer = new RenderTargetBitmap();
foreach (var test in strings)
{
result.Append(test);
@@ -361,10 +333,11 @@ async Task RunTestsCore(string[] strings)
try
{
var elt = await RenderById(test);
- var testResult = RenderAsPng(elt);
+ await renderer.RenderAsync(elt); ;
+ var testResult = await renderer.GetPixelsAsync();
result.Append("SUCCESS;");
- result.Append(Convert.ToBase64String(testResult));
+ result.Append(Convert.ToBase64String(testResult.ToArray()));
}
catch (Exception e)
{