Merge remote-tracking branch 'origin/main' into develop

This commit is contained in:
Matthew Leibowitz 2021-05-30 11:18:12 +02:00
Родитель fb6741acd1 11591db5b9
Коммит 3342c4d7d7
13 изменённых файлов: 193 добавлений и 124 удалений

Просмотреть файл

@ -139,6 +139,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release
<!-- watchos -->
<file platform="macos" src="build/xamarinwatchos1.0/libSkiaSharp.framework/**/*" target="build/xamarinwatchos1.0/libSkiaSharp.framework" />
<!-- .NET interactive -->
<file src="interactive-extensions/dotnet/SkiaSharp.DotNet.Interactive.dll" />
<!-- legal -->
<file src="LICENSE.txt" />
<file src="THIRD-PARTY-NOTICES.txt" />

Просмотреть файл

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Html;
using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags;
namespace SkiaSharp.DotNet.Interactive
{
public static class ColorRenderer
{
public static IHtmlContent Render(this SKColor color)
{
var colorString = color.Alpha == 255
? $"rgb({color.Red},{color.Green},{color.Blue})"
: $"rgba({color.Red},{color.Green},{color.Blue},{color.Alpha / 255.0:0.0##})";
return GetHtml(colorString);
}
public static IHtmlContent Render(this SKColorF color) =>
((SKColor)color).Render();
private static IHtmlContent GetHtml(string colorString) =>
div(
span[style:
$"width: 2em; " +
$"background: {colorString}; " +
$"display: inline-block; " +
$"border: 1px solid black; "](
new HtmlString("&nbsp;")),
span(
new HtmlString("&nbsp;"),
colorString));
}
}

Просмотреть файл

@ -2,10 +2,10 @@
using System.Reflection;
using System.Resources;
[assembly: AssemblyTitle("SkiaSharp.Workbooks")]
[assembly: AssemblyDescription("SkiaSharp.Workbooks adds functionality for SkiaSharp to Xamarin.Workbooks.")]
[assembly: AssemblyTitle("SkiaSharp.DotNet.Interactive")]
[assembly: AssemblyDescription("SkiaSharp.DotNet.Interactive adds functionality for SkiaSharp to .NET Interactive notebooks.")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("SkiaSharp.Workbooks")]
[assembly: AssemblyProduct("SkiaSharp.DotNet.Interactive")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: NeutralResourcesLanguage("en")]

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using Microsoft.AspNetCore.Html;
using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags;
namespace SkiaSharp.DotNet.Interactive
{
public static class RasterRenderer
{
public static IHtmlContent Render(this SKBitmap bitmap)
{
using var image = SKImage.FromBitmap(bitmap);
return Render(image);
}
public static IHtmlContent Render(this SKPixmap pixmap)
{
using var image = SKImage.FromPixels(pixmap);
return Render(image);
}
public static IHtmlContent Render(this SKPicture picture)
{
using var image = SKImage.FromPicture(picture, picture.CullRect.Size.ToSizeI());
return Render(image);
}
public static IHtmlContent Render(this SKSurface surface)
{
using var image = surface.Snapshot();
return Render(image);
}
public static IHtmlContent Render(this SKImage image)
{
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
return GetHtml(data);
}
private static IHtmlContent GetHtml(SKData data)
{
var base64 = Convert.ToBase64String(data.AsSpan());
return div(
img[src: "data:image/png;base64," + base64]);
}
}
}

Просмотреть файл

@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>SkiaSharp.DotNet.Interactive</RootNamespace>
<AssemblyName>SkiaSharp.DotNet.Interactive</AssemblyName>
<MDocDocumentationDirectory></MDocDocumentationDirectory>
<SignAssembly>false</SignAssembly>
<PackagingGroup>SkiaSharp</PackagingGroup>
<PackagingLocation>interactive-extensions\dotnet</PackagingLocation>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.21255.3" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\binding\SkiaSharp\SkiaSharp.csproj" />
</ItemGroup>
<!-- uncomment this block for local testing -->
<!--<PropertyGroup>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsPackable>true</IsPackable>
<PackageVersion>0.0.1-preview.$([System.DateTime]::Now.ToString('yyyy.M.d.H.m.s'))</PackageVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Update="..\..\binding\SkiaSharp\SkiaSharp.csproj" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\output\native\osx\libSkiaSharp*" Pack="true" PackagePath="runtimes\osx\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\windows\x64\libSkiaSharp*" Pack="true" PackagePath="runtimes\win-x64\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\windows\x86\libSkiaSharp*" Pack="true" PackagePath="runtimes\win-x86\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\windows\arm64\libSkiaSharp*" Pack="true" PackagePath="runtimes\win-arm64\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\linux\x64\libSkiaSharp*" Pack="true" PackagePath="runtimes\linux-x64\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\linux\x86\libSkiaSharp*" Pack="true" PackagePath="runtimes\linux-x86\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\linux\arm64\libSkiaSharp*" Pack="true" PackagePath="runtimes\linux-arm64\native\%(Filename)%(Extension)" />
<None Include="..\..\output\native\linux\arm\libSkiaSharp*" Pack="true" PackagePath="runtimes\linux-arm\native\%(Filename)%(Extension)" />
<None Include="..\..\output\SkiaSharp\nuget\lib\netstandard2.0\SkiaSharp.dll" Pack="true" PackagePath="lib\netstandard2.0\SkiaSharp.dll" />
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="$(PackagingLocation)" />
</ItemGroup>-->
</Project>

Просмотреть файл

@ -0,0 +1,27 @@
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Formatting;
namespace SkiaSharp.DotNet.Interactive
{
public class SkiaSharpKernelExtension : IKernelExtension
{
public Task OnLoadAsync(Kernel kernel)
{
// colors
Formatter.Register<SKColor>((color, writer) => writer.Write(color.Render()), "text/html");
Formatter.Register<SKColorF>((color, writer) => writer.Write(color.Render()), "text/html");
// "images"
Formatter.Register<SKBitmap>((bmp, writer) => writer.Write(bmp.Render()), "text/html");
Formatter.Register<SKPixmap>((pix, writer) => writer.Write(pix.Render()), "text/html");
Formatter.Register<SKPicture>((pic, writer) => writer.Write(pic.Render()), "text/html");
Formatter.Register<SKSurface>((surface, writer) => writer.Write(surface.Render()), "text/html");
Formatter.Register<SKImage>((img, writer) => writer.Write(img.Render()), "text/html");
// TODO: colorspaces and other things
return Task.CompletedTask;
}
}
}

Просмотреть файл

@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>SkiaSharp.Workbooks</RootNamespace>
<AssemblyName>SkiaSharp.Workbooks</AssemblyName>
<MDocDocumentationDirectory></MDocDocumentationDirectory>
<SignAssembly>false</SignAssembly>
<PackagingGroup>SkiaSharp</PackagingGroup>
<PackagingLocation>xamarin.interactive</PackagingLocation>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Workbooks.Integration" Version="1.0.0-rc5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\binding\SkiaSharp\SkiaSharp.csproj" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,92 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using Xamarin.Interactive.Logging;
using Xamarin.Interactive.Representations;
using Xamarin.Interactive.Representations.Reflection;
using Xamarin.Interactive.Serialization;
namespace SkiaSharp.Workbooks
{
sealed class SkiaSharpRepresentationProvider : RepresentationProvider
{
public override IEnumerable<object> ProvideRepresentations (object obj)
{
yield return ProvideSingleRepresentation (obj);
}
public override bool TryConvertFromRepresentation (
IRepresentedType representedType,
object [] representations,
out object represented)
{
represented = null;
Color color;
if (TryFindMatchingRepresentation<SKColor, Color> (
representedType,
representations,
out color)) {
represented = new SKColor (
(byte)(color.Red * 255),
(byte)(color.Green * 255),
(byte)(color.Blue * 255),
(byte)(color.Alpha * 255));
return true;
}
return base.TryConvertFromRepresentation (representedType, representations, out represented);
}
ISerializableObject ProvideSingleRepresentation (object obj)
{
try {
var bitmap = obj as SKBitmap;
if (bitmap != null)
return SKImageToRepresentationImage (SKImage.FromBitmap (bitmap));
var image = obj as SKImage;
if (image != null)
return SKImageToRepresentationImage (image);
var surface = obj as SKSurface;
if (surface != null)
return SKImageToRepresentationImage (surface.Snapshot ());
var pixmap = obj as SKPixmap;
if (pixmap != null)
return ImageFromSKData (
pixmap.Encode (SKEncodedImageFormat.Png, 85),
pixmap.Width,
pixmap.Height);
if (obj is SKColor) {
var color = (SKColor)obj;
return new Color (color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0);
}
return null;
} catch (Exception e) {
Log.Error (
nameof (SkiaSharpRepresentationProvider),
$"Error while trying to provide representation for {obj.GetType ()}.",
e);
return null;
}
}
ISerializableObject SKImageToRepresentationImage (SKImage image)
=> ImageFromSKData (image.Encode (), image.Width, image.Height);
ISerializableObject ImageFromSKData (SKData data, int width, int height)
{
byte [] pngData;
using (var ms = new MemoryStream ()) {
data.SaveTo (ms);
pngData = ms.ToArray ();
}
return new Image (ImageFormat.Png, pngData, width, height);
}
}
}

Просмотреть файл

@ -1,12 +0,0 @@
using Xamarin.Interactive;
[assembly: AgentIntegration (typeof (SkiaSharp.Workbooks.SkiaWorkbooksIntegration))]
namespace SkiaSharp.Workbooks
{
sealed class SkiaWorkbooksIntegration : IAgentIntegration
{
public void IntegrateWith (IAgent agent)
=> agent.RepresentationManager.AddProvider (new SkiaSharpRepresentationProvider ());
}
}

Просмотреть файл

@ -47,6 +47,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Views.Uno.Wasm",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Views.Uno.Reference", "SkiaSharp.Views.Uno\SkiaSharp.Views.Uno.Reference\SkiaSharp.Views.Uno.Reference.csproj", "{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive", "{E0EDA875-C25F-4727-BB98-6EF7BBAFEB4B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive\SkiaSharp.DotNet.Interactive.csproj", "{03A0F2E5-345D-4FA2-B1F8-45D2D7EEA3EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -113,6 +117,10 @@ Global
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}.Release|Any CPU.Build.0 = Release|Any CPU
{03A0F2E5-345D-4FA2-B1F8-45D2D7EEA3EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03A0F2E5-345D-4FA2-B1F8-45D2D7EEA3EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03A0F2E5-345D-4FA2-B1F8-45D2D7EEA3EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03A0F2E5-345D-4FA2-B1F8-45D2D7EEA3EB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -133,6 +141,7 @@ Global
{4606F63B-F0B1-418E-8B45-844361E17EB1} = {66A0800A-CA70-4AC2-88B7-8E7C4CA7C914}
{08599A28-FADE-43B5-95A0-BDCB22B97D3A} = {00C9099A-BE4F-40D0-9401-295618368370}
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB} = {00C9099A-BE4F-40D0-9401-295618368370}
{03A0F2E5-345D-4FA2-B1F8-45D2D7EEA3EB} = {E0EDA875-C25F-4727-BB98-6EF7BBAFEB4B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4229170-607D-4886-9990-8FD5D86220B9}

Просмотреть файл

@ -85,6 +85,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Views.Uno.Wasm",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Views.Uno.Reference", "SkiaSharp.Views.Uno\SkiaSharp.Views.Uno.Reference\SkiaSharp.Views.Uno.Reference.csproj", "{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive\SkiaSharp.DotNet.Interactive.csproj", "{A23C2451-BBCE-4309-B80F-CEE482A140C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive", "{A54F6AE5-2921-4C68-846A-25D38F1C2E7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -227,6 +231,10 @@ Global
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB}.Release|Any CPU.Build.0 = Release|Any CPU
{A23C2451-BBCE-4309-B80F-CEE482A140C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A23C2451-BBCE-4309-B80F-CEE482A140C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A23C2451-BBCE-4309-B80F-CEE482A140C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A23C2451-BBCE-4309-B80F-CEE482A140C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -266,6 +274,7 @@ Global
{E0FF9BFF-2253-4486-A8E2-94312D09D056} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{242213FA-1F0E-40BB-A9B2-6FEE82B5D216} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{A23C2451-BBCE-4309-B80F-CEE482A140C7} = {A54F6AE5-2921-4C68-846A-25D38F1C2E7E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4B8BED07-EA83-4BC1-B3BB-6B8EBC54C25F}

Просмотреть файл

@ -73,6 +73,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Views.WinUI", "Sk
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp.Views.WinUI", "SkiaSharp.Views.WinUI", "{32AE56A0-F3E1-4721-9BED-B1F609DEA8E8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive", "{B7F572BF-AD3F-4AC8-A654-3ED241E3ECA4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive\SkiaSharp.DotNet.Interactive.csproj", "{73185ECB-5A38-447C-95CF-D32D6784B97D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -187,6 +191,10 @@ Global
{F50AE765-D9B9-4025-88A8-E8B080D5D624}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F50AE765-D9B9-4025-88A8-E8B080D5D624}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F50AE765-D9B9-4025-88A8-E8B080D5D624}.Release|Any CPU.Build.0 = Release|Any CPU
{73185ECB-5A38-447C-95CF-D32D6784B97D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73185ECB-5A38-447C-95CF-D32D6784B97D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73185ECB-5A38-447C-95CF-D32D6784B97D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73185ECB-5A38-447C-95CF-D32D6784B97D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -219,6 +227,7 @@ Global
{F675A841-ECDB-4571-8AA3-7D4642FD57DB} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{F50AE765-D9B9-4025-88A8-E8B080D5D624} = {32AE56A0-F3E1-4721-9BED-B1F609DEA8E8}
{73185ECB-5A38-447C-95CF-D32D6784B97D} = {B7F572BF-AD3F-4AC8-A654-3ED241E3ECA4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {63A8C36E-4917-46DB-9AAD-522B8EC00C23}

Просмотреть файл

@ -109,6 +109,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp.Views.WinUI", "Sk
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Views.WinUI", "SkiaSharp.Views.WinUI\SkiaSharp.Views.WinUI\SkiaSharp.Views.WinUI.csproj", "{02CA4107-1FC6-4676-B284-9981694A450E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive", "{94767AFC-EB2B-41ED-BFEF-93EF33EEEBCF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.DotNet.Interactive", "SkiaSharp.DotNet.Interactive\SkiaSharp.DotNet.Interactive.csproj", "{D213D614-2F31-450C-B6FA-294754C4DCD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -295,6 +299,10 @@ Global
{02CA4107-1FC6-4676-B284-9981694A450E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02CA4107-1FC6-4676-B284-9981694A450E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02CA4107-1FC6-4676-B284-9981694A450E}.Release|Any CPU.Build.0 = Release|Any CPU
{D213D614-2F31-450C-B6FA-294754C4DCD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D213D614-2F31-450C-B6FA-294754C4DCD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D213D614-2F31-450C-B6FA-294754C4DCD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D213D614-2F31-450C-B6FA-294754C4DCD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -345,6 +353,7 @@ Global
{047C460D-7470-418C-AF2C-30620A1AF61C} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{D5C7D157-609E-4D64-8E42-C1DB0FAA86EB} = {E53351EA-FE40-47D2-B388-4A75DA6CCD71}
{02CA4107-1FC6-4676-B284-9981694A450E} = {6430EC5F-EDA1-4202-AB7B-22ED0496E016}
{D213D614-2F31-450C-B6FA-294754C4DCD4} = {94767AFC-EB2B-41ED-BFEF-93EF33EEEBCF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {67EACD19-0CEA-4127-9842-549AA6FB84C9}