Browse Source

Fixed Skia's RenderTargetBitmap and made Skia tests to run for .NET Core

pull/1077/head
Nikita Tsukanov 9 years ago
parent
commit
1d6beab970
  1. 14
      build.cake
  2. 2
      build/Magick.NET-Q16-AnyCPU.props
  3. 29
      src/Skia/Avalonia.Skia/BitmapImpl.cs
  4. 126
      tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj
  5. 5
      tests/Avalonia.RenderTests/TestBase.cs
  6. BIN
      tests/TestFiles/Skia/OpacityMask/Opacity_Mask_Masks_Element.expected.png

14
build.cake

@ -157,10 +157,13 @@ Task("Build")
}
});
void RunCoreTest(string dir, Parameters parameters, bool net461Only)
void RunCoreTest(string project, Parameters parameters, bool net461Only)
{
Information("Running tests from " + dir);
DotNetCoreRestore(dir);
if(!project.EndsWith(".csproj"))
project = System.IO.Path.Combine(project, System.IO.Path.GetFileName(project)+".csproj");
Information("Running tests from " + project);
DotNetCoreRestore(project);
var frameworks = new List<string>(){"netcoreapp1.1"};
if(parameters.IsRunningOnWindows)
frameworks.Add("net461");
@ -169,7 +172,8 @@ void RunCoreTest(string dir, Parameters parameters, bool net461Only)
if(fw != "net461" && net461Only)
continue;
Information("Running for " + fw);
DotNetCoreTest(System.IO.Path.Combine(dir, System.IO.Path.GetFileName(dir)+".csproj"),
DotNetCoreTest(project,
new DotNetCoreTestSettings {
Configuration = parameters.Configuration,
Framework = fw
@ -189,6 +193,8 @@ Task("Run-Net-Core-Unit-Tests")
RunCoreTest("./tests/Avalonia.Markup.Xaml.UnitTests", parameters, false);
RunCoreTest("./tests/Avalonia.Styling.UnitTests", parameters, false);
RunCoreTest("./tests/Avalonia.Visuals.UnitTests", parameters, false);
if(parameters.IsRunningOnWindows)
RunCoreTest("./tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj", parameters, false);
});
Task("Run-Unit-Tests")

2
build/Magick.NET-Q16-AnyCPU.props

@ -1,5 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.0.0.0101" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.0.6.102" />
</ItemGroup>
</Project>

29
src/Skia/Avalonia.Skia/BitmapImpl.cs

@ -38,29 +38,6 @@ namespace Avalonia.Skia
Bitmap.Dispose();
}
public void Save(string fileName)
{
#if DESKTOP
if(Bitmap.ColorType != SKColorType.Bgra8888)
{
using (var tmp = new BitmapImpl(Bitmap.Copy(SKColorType.Bgra8888)))
tmp.Save(fileName);
return;
}
IntPtr length;
using (var sdb = new System.Drawing.Bitmap(PixelWidth, PixelHeight, Bitmap.RowBytes,
System.Drawing.Imaging.PixelFormat.Format32bppArgb,
Bitmap.GetPixels(out length)))
sdb.Save(fileName);
#else
//SkiaSharp doesn't expose image encoders yet
#endif
}
public int PixelWidth { get; private set; }
public int PixelHeight { get; private set; }
@ -111,6 +88,12 @@ namespace Avalonia.Skia
}
}
public void Save(string fileName)
{
using (var stream = File.Create(fileName))
Save(stream);
}
class BitmapFramebuffer : ILockedFramebuffer
{
private SKBitmap _bmp;

126
tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj

@ -1,107 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D35A9F3D-8BB0-496E-BF72-444038A7DEBB}</ProjectGuid>
<TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks>
<Platform Condition="'$(TargetFramework)' == 'net461'">x86</Platform>
<OutputPath Condition="'$(TargetFramework)' == 'net461'">bin\$(Configuration)</OutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
<DefineConstants>$(DefineConstants);AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL</DefineConstants>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Avalonia.Skia.RenderTests</RootNamespace>
<AssemblyName>Avalonia.Skia.RenderTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;DEBUG;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;DEBUG;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL;</DefineConstants>
<Optimize>true</Optimize>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj">
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project>
<Name>Avalonia.Animation</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj">
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project>
<Name>Avalonia.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj">
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project>
<Name>Avalonia.Controls</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj">
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project>
<Name>Avalonia.Input</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj">
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project>
<Name>Avalonia.Interactivity</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj">
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project>
<Name>Avalonia.Layout</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj">
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project>
<Name>Avalonia.Visuals</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj">
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project>
<Name>Avalonia.Styling</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Skia\Avalonia.Skia\Avalonia.Skia.csproj">
<Project>{7d2d3083-71dd-4cc9-8907-39a0d86fb322}</Project>
<Name>Avalonia.Skia</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
<ProjectReference Condition="'$(TargetFramework)' == 'net461'" Include="..\..\src\Avalonia.DotNetFrameworkRuntime\Avalonia.DotNetFrameworkRuntime.csproj" />
<ProjectReference Condition="'$(TargetFramework)' == 'netcoreapp1.1'" Include="..\..\src\Avalonia.DotNetCoreRuntime\Avalonia.DotNetCoreRuntime.csproj" />
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" />
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup\Avalonia.Markup.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
<ProjectReference Include="..\..\src\Skia\Avalonia.Skia\Avalonia.Skia.csproj"/>
</ItemGroup>
<Import Project="..\..\build\Moq.props" />
<Import Project="..\..\build\Rx.props" />
<Import Project="..\..\build\XUnit.props" />
<Import Condition="'$(TargetFramework)' == 'net461'" Project="$(MSBuildThisFileDirectory)..\..\src\Shared\nuget.workaround.targets" />
<Import Project="Avalonia.RenderTests.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\build\Magick.NET-Q16-AnyCPU.props" />
<Import Project="..\..\build\XUnit.props" />
<Import Project="..\..\build\SkiaSharp.props" />
<Import Project="$(MSBuildThisFileDirectory)..\..\src\Shared\nuget.workaround.targets" />
<Target Name="FixSkiaSharp" AfterTargets="Build">
<Copy SourceFiles="$(OutputPath)\x86\libSkiaSharp.dll" DestinationFolder="$(OutputPath)" Condition="'$(TargetFramework)' == 'net461'"/>
</Target>
</Project>

5
tests/Avalonia.RenderTests/TestBase.cs

@ -44,7 +44,7 @@ namespace Avalonia.Direct2D1.RenderTests
#if AVALONIA_CAIRO
string testFiles = Path.GetFullPath(@"..\..\tests\TestFiles\Cairo");
#elif AVALONIA_SKIA
string testFiles = Path.GetFullPath(@"..\..\tests\TestFiles\Skia");
string testFiles = Path.GetFullPath(@"..\..\..\..\TestFiles\Skia");
#else
string testFiles = Path.GetFullPath(@"..\..\tests\TestFiles\Direct2D1");
#endif
@ -63,7 +63,8 @@ namespace Avalonia.Direct2D1.RenderTests
Directory.CreateDirectory(OutputPath);
}
string path = Path.Combine(OutputPath, testName + ".out.png");
string path = Path.GetFullPath(Path.Combine(OutputPath, testName + ".out.png"));
System.Console.WriteLine("Rendering to "+path);
using (RenderTargetBitmap bitmap = new RenderTargetBitmap(
(int)target.Width,

BIN
tests/TestFiles/Skia/OpacityMask/Opacity_Mask_Masks_Element.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 799 B

Loading…
Cancel
Save