From 95c0ea56861e6aa70c60739a18e0f26167fe9400 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Wed, 8 Jun 2022 00:30:56 +0200 Subject: [PATCH] Add the net6.0-tizen TFM (#2099) * Add the net6.0-tizen TFM * [Tizen] Add SKCanvasViewHander and SKImageSourceService (#2101) Co-authored-by: Kangho Hur --- binding/SkiaSharp/SkiaSharp.csproj | 7 ++ ...p.Views.Maui.Controls.Compatibility.nuspec | 5 ++ nuget/SkiaSharp.Views.Maui.Controls.nuspec | 5 ++ nuget/SkiaSharp.Views.Maui.Core.nuspec | 6 ++ nuget/SkiaSharp.Views.nuspec | 6 ++ nuget/SkiaSharp.nuspec | 6 ++ .../SkiaSharpSample/Platforms/Tizen/Main.cs | 17 ++++ .../Platforms/Tizen/tizen-manifest.xml | 15 ++++ .../SkiaSharpSample/SkiaSharpSample.csproj | 8 +- source/SkiaSharp.Build.props | 8 ++ source/SkiaSharp.Build.targets | 8 -- .../SKCanvasViewRendererBase.cs | 8 ++ .../SKGLViewRendererBase.cs | 8 ++ .../SKCanvasViewRenderer.cs | 16 +++- .../SKGLViewRenderer.cs | 15 ++++ .../SKImageSourceHandler.cs | 14 +++- .../SKTouchHandler.cs | 28 +++---- .../AppHostBuilderExtensions.cs | 31 +++++-- ...p.Views.Maui.Controls.Compatibility.csproj | 14 ++++ .../SkiaSharp.Views.Maui.Controls.csproj | 4 + .../SKCanvasView/SKCanvasViewHandler.Tizen.cs | 82 +++++++++++++++++++ .../SKImageSourceService.Tizen.cs | 54 ++++++++++++ .../Platform/Tizen/SKCanvasViewExtensions.cs | 10 +++ .../SkiaSharp.Views.Maui.Core.csproj | 14 +++- .../SkiaSharp.Views/SkiaSharp.Views.csproj | 11 +++ 25 files changed, 366 insertions(+), 34 deletions(-) create mode 100644 samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/Main.cs create mode 100644 samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/tizen-manifest.xml create mode 100644 source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKCanvasView/SKCanvasViewHandler.Tizen.cs create mode 100644 source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKImageSourceService/SKImageSourceService.Tizen.cs create mode 100644 source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Platform/Tizen/SKCanvasViewExtensions.cs diff --git a/binding/SkiaSharp/SkiaSharp.csproj b/binding/SkiaSharp/SkiaSharp.csproj index 27814eeca5..1cef7122e1 100644 --- a/binding/SkiaSharp/SkiaSharp.csproj +++ b/binding/SkiaSharp/SkiaSharp.csproj @@ -84,6 +84,13 @@ + + + + + + + diff --git a/nuget/SkiaSharp.Views.Maui.Controls.Compatibility.nuspec b/nuget/SkiaSharp.Views.Maui.Controls.Compatibility.nuspec index 329cc3106f..98ccd6ee73 100644 --- a/nuget/SkiaSharp.Views.Maui.Controls.Compatibility.nuspec +++ b/nuget/SkiaSharp.Views.Maui.Controls.Compatibility.nuspec @@ -42,6 +42,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + @@ -58,6 +61,8 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + diff --git a/nuget/SkiaSharp.Views.Maui.Controls.nuspec b/nuget/SkiaSharp.Views.Maui.Controls.nuspec index c34e99d276..29a333d7fb 100644 --- a/nuget/SkiaSharp.Views.Maui.Controls.nuspec +++ b/nuget/SkiaSharp.Views.Maui.Controls.nuspec @@ -42,6 +42,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + @@ -58,6 +61,8 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + diff --git a/nuget/SkiaSharp.Views.Maui.Core.nuspec b/nuget/SkiaSharp.Views.Maui.Core.nuspec index 7fcbf135b2..7b0637465b 100644 --- a/nuget/SkiaSharp.Views.Maui.Core.nuspec +++ b/nuget/SkiaSharp.Views.Maui.Core.nuspec @@ -46,6 +46,10 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + + @@ -62,6 +66,8 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + diff --git a/nuget/SkiaSharp.Views.nuspec b/nuget/SkiaSharp.Views.nuspec index dbe44ed74e..5dedb94b05 100644 --- a/nuget/SkiaSharp.Views.nuspec +++ b/nuget/SkiaSharp.Views.nuspec @@ -70,6 +70,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + @@ -115,6 +118,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + diff --git a/nuget/SkiaSharp.nuspec b/nuget/SkiaSharp.nuspec index 60e08dd5c0..cafb007218 100644 --- a/nuget/SkiaSharp.nuspec +++ b/nuget/SkiaSharp.nuspec @@ -86,6 +86,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + @@ -140,6 +143,9 @@ Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release + + + diff --git a/samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/Main.cs b/samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/Main.cs new file mode 100644 index 0000000000..16d024f090 --- /dev/null +++ b/samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/Main.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Maui; +using Microsoft.Maui.Hosting; + +namespace SkiaSharpSample +{ + class Program : MauiApplication + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } + } +} diff --git a/samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/tizen-manifest.xml b/samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/tizen-manifest.xml new file mode 100644 index 0000000000..e77ca8e6cb --- /dev/null +++ b/samples/Basic/Maui/SkiaSharpSample/Platforms/Tizen/tizen-manifest.xml @@ -0,0 +1,15 @@ + + + + + + appicon.xhigh.png + + + + + http://tizen.org/privilege/internet + + + + \ No newline at end of file diff --git a/samples/Basic/Maui/SkiaSharpSample/SkiaSharpSample.csproj b/samples/Basic/Maui/SkiaSharpSample/SkiaSharpSample.csproj index 3ad92c5079..b68a523c98 100644 --- a/samples/Basic/Maui/SkiaSharpSample/SkiaSharpSample.csproj +++ b/samples/Basic/Maui/SkiaSharpSample/SkiaSharpSample.csproj @@ -2,6 +2,7 @@ net6.0-ios;net6.0-maccatalyst;net6.0-android + $(TargetFrameworks);net6.0-tizen $(TargetFrameworks);net6.0-windows10.0.19041.0 Exe true @@ -15,10 +16,11 @@ 1.0 10.0 True - 14.2 - 14.0 - 21.0 + 14.2 + 14.0 + 21.0 10.0.17763.0 + 6.5 diff --git a/source/SkiaSharp.Build.props b/source/SkiaSharp.Build.props index 58a591bcd6..4ae04ce620 100644 --- a/source/SkiaSharp.Build.props +++ b/source/SkiaSharp.Build.props @@ -14,6 +14,8 @@ $([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux))) true false + true + false @@ -47,6 +49,7 @@ netstandard1.3;netstandard2.0;net462 net6.0-ios;net6.0-maccatalyst;net6.0-tvos;net6.0-macos;net6.0-android + $(Net6PlatformTargetFrameworks);net6.0-tizen net6.0;$(Net6PlatformTargetFrameworks) @@ -59,6 +62,7 @@ net6.0;net6.0-ios;net6.0-maccatalyst;net6.0-android + $(MauiTargetFrameworks);net6.0-tizen $(MauiTargetFrameworks);net6.0-windows10.0.19041.0 @@ -120,6 +124,10 @@ 10.0.17763.0 10.0.17763.0 + + 6.5 + 6.5 + diff --git a/source/SkiaSharp.Build.targets b/source/SkiaSharp.Build.targets index 313f328b06..ee8ca7c1c4 100644 --- a/source/SkiaSharp.Build.targets +++ b/source/SkiaSharp.Build.targets @@ -17,14 +17,6 @@ $(GIT_SHA) $(GIT_COMMIT) - - 10.0 - 10.0 - 10.14 - 13.1 - 21.0 - 10.0.17763.0 - @@ -70,4 +74,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/SkiaSharp.Views.Maui.Controls.csproj b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/SkiaSharp.Views.Maui.Controls.csproj index 26ac71720a..1e3b459416 100644 --- a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/SkiaSharp.Views.Maui.Controls.csproj +++ b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/SkiaSharp.Views.Maui.Controls.csproj @@ -38,6 +38,10 @@ + + + + diff --git a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKCanvasView/SKCanvasViewHandler.Tizen.cs b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKCanvasView/SKCanvasViewHandler.Tizen.cs new file mode 100644 index 0000000000..a116b2901e --- /dev/null +++ b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKCanvasView/SKCanvasViewHandler.Tizen.cs @@ -0,0 +1,82 @@ +using Microsoft.Maui; +using Microsoft.Maui.Handlers; +using Microsoft.Maui.Platform; +using SkiaSharp.Views.Tizen; +using SkiaSharp.Views.Maui.Platform; + +namespace SkiaSharp.Views.Maui.Handlers +{ + public partial class SKCanvasViewHandler : ViewHandler + { + private SKSizeI lastCanvasSize; + private SKTouchHandler? touchHandler; + + protected override SKCanvasView CreatePlatformView() => new SKCanvasView(PlatformParent); + + protected override void ConnectHandler(SKCanvasView platformView) + { + platformView.PaintSurface += OnPaintSurface; + + base.ConnectHandler(platformView); + } + + protected override void DisconnectHandler(SKCanvasView platformView) + { + touchHandler?.Detach(platformView); + touchHandler = null; + + platformView.PaintSurface -= OnPaintSurface; + + base.DisconnectHandler(platformView); + } + + // Mapper actions / properties + + public static void OnInvalidateSurface(SKCanvasViewHandler handler, ISKCanvasView canvasView, object? args) + { + handler.PlatformView?.Invalidate(); + } + + public static void MapIgnorePixelScaling(SKCanvasViewHandler handler, ISKCanvasView canvasView) + { + handler.PlatformView?.UpdateIgnorePixelScaling(canvasView); + } + + public static void MapEnableTouchEvents(SKCanvasViewHandler handler, ISKCanvasView canvasView) + { + if (handler.PlatformView == null) + return; + + handler.touchHandler ??= new SKTouchHandler( + args => canvasView.OnTouch(args), + (x, y) => handler.OnGetScaledCoord(x, y)); + + handler.touchHandler?.SetEnabled(handler.PlatformView, canvasView.EnableTouchEvents); + } + + // helper methods + + private void OnPaintSurface(object? sender, Tizen.SKPaintSurfaceEventArgs e) + { + var newCanvasSize = e.Info.Size; + if (lastCanvasSize != newCanvasSize) + { + lastCanvasSize = newCanvasSize; + VirtualView?.OnCanvasSizeChanged(newCanvasSize); + } + + VirtualView?.OnPaintSurface(new SKPaintSurfaceEventArgs(e.Surface, e.Info, e.RawInfo)); + } + + private SKPoint OnGetScaledCoord(double x, double y) + { + if (VirtualView?.IgnorePixelScaling == true && PlatformView != null) + { + x = ScalingInfo.FromPixel(x); + y = ScalingInfo.FromPixel(y); + } + + return new SKPoint((float)x, (float)y); + } + } +} diff --git a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKImageSourceService/SKImageSourceService.Tizen.cs b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKImageSourceService/SKImageSourceService.Tizen.cs new file mode 100644 index 0000000000..ffcc6a6f4d --- /dev/null +++ b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Handlers/SKImageSourceService/SKImageSourceService.Tizen.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Maui; +using Tizen.UIExtensions.ElmSharp; + +namespace SkiaSharp.Views.Maui.Handlers +{ + public partial class SKImageSourceService + { + public override Task?> GetImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => + GetImageAsync((IStreamImageSource)imageSource, image, cancellationToken); + + public async Task?> GetImageAsync(IStreamImageSource imageSource, Image image, CancellationToken cancellationToken = default) + { + if (imageSource.IsEmpty) + return null; + + try + { + var stream = imageSource switch + { + ISKImageImageSource img => ToStream(img.Image), + ISKBitmapImageSource bmp => ToStream(SKImage.FromBitmap(bmp.Bitmap)), + ISKPixmapImageSource pix => ToStream(SKImage.FromPixels(pix.Pixmap)), + ISKPictureImageSource pic => ToStream(SKImage.FromPicture(pic.Picture, pic.Dimensions)), + _ => null, + }; + + if (stream == null) + throw new InvalidOperationException("Unable to load image stream."); + + var isLoadComplated = await image.LoadAsync(stream, cancellationToken); + + if (!isLoadComplated) + throw new InvalidOperationException("Unable to decode image from stream."); + + return new ImageSourceServiceResult(image); + } + catch (Exception ex) + { + Logger?.LogWarning(ex, "Unable to load image stream."); + throw; + } + } + + private static Stream ToStream(SKImage skiaImage) + { + return skiaImage.Encode().AsStream(); + } + } +} diff --git a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Platform/Tizen/SKCanvasViewExtensions.cs b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Platform/Tizen/SKCanvasViewExtensions.cs new file mode 100644 index 0000000000..2161026152 --- /dev/null +++ b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Platform/Tizen/SKCanvasViewExtensions.cs @@ -0,0 +1,10 @@ +using SkiaSharp.Views.Tizen; + +namespace SkiaSharp.Views.Maui.Platform +{ + public static class SKCanvasViewExtensions + { + public static void UpdateIgnorePixelScaling(this SKCanvasView nativeView, ISKCanvasView canvasView) => + nativeView.IgnorePixelScaling = canvasView?.IgnorePixelScaling ?? false; + } +} diff --git a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/SkiaSharp.Views.Maui.Core.csproj b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/SkiaSharp.Views.Maui.Core.csproj index 5190d174af..86a9bd3cd3 100644 --- a/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/SkiaSharp.Views.Maui.Core.csproj +++ b/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/SkiaSharp.Views.Maui.Core.csproj @@ -18,7 +18,7 @@ - + @@ -49,6 +49,12 @@ + + + + + + @@ -73,4 +79,10 @@ + + + + + + \ No newline at end of file diff --git a/source/SkiaSharp.Views/SkiaSharp.Views/SkiaSharp.Views.csproj b/source/SkiaSharp.Views/SkiaSharp.Views/SkiaSharp.Views.csproj index 535c3c7019..cf04adf732 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views/SkiaSharp.Views.csproj +++ b/source/SkiaSharp.Views/SkiaSharp.Views/SkiaSharp.Views.csproj @@ -21,6 +21,10 @@ SkiaSharp.Views.Android SkiaSharp.Views.Android + + SkiaSharp.Views.Tizen + SkiaSharp.Views.Tizen + @@ -42,6 +46,8 @@ + + @@ -72,6 +78,11 @@ + + + + +