Skip to content

Commit

Permalink
[Tizen] Change tizen graphics backend engine (#2225)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot authored Aug 29, 2022
1 parent 8ab4146 commit 88c0960
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 47 deletions.
3 changes: 3 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<configuration>
<packageSources>
<clear />
<add key="darc-pub-dotnet-runtime-531f715" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-531f715f/nuget/v3/index.json" />
<add key="darc-pub-dotnet-emsdk-3f6c45a" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-3f6c45a2/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion scripts/azure-pipelines-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ variables:
XCODE_VERSION: 13.2.1
VISUAL_STUDIO_VERSION: '17/pre'
DOTNET_VERSION_PREVIEW: '6.0.400'
DOTNET_WORKLOAD_SOURCE: 'https://aka.ms/dotnet/maui/6.0.486.json'
DOTNET_WORKLOAD_SOURCE: 'https://maui.blob.core.windows.net/metadata/rollbacks/6.0.513.json'
CONFIGURATION: 'Release'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
THROW_ON_TEST_FAILURE: true
Expand Down
4 changes: 2 additions & 2 deletions scripts/install-dotnet-workloads.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ $previewRuntime = 'https://api.nuget.org/v3/index.json'
$previewEmscripten = 'https://api.nuget.org/v3/index.json'
if ($IsPreview) {
$previewFeed = 'https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json'
$previewRuntime = 'https://api.nuget.org/v3/index.json'
$previewEmscripten = 'https://api.nuget.org/v3/index.json'
$previewRuntime = 'https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-531f715f/nuget/v3/index.json'
$previewEmscripten = 'https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-3f6c45a2/nuget/v3/index.json'
}

Write-Host "Installing .NET workloads..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@ public static MauiAppBuilder UseSkiaSharp(this MauiAppBuilder builder, bool regi
#if !NETSTANDARD
if (registerRenderers)
{
#if __TIZEN__
#pragma warning disable CS0612 // Type or member is obsolete
if (replaceHandlers)
handlers.AddCompatibilityRenderer<SKCanvasView, SKCanvasViewRenderer>();
else
handlers.TryAddCompatibilityRenderer(typeof(SKCanvasView), typeof(SKCanvasViewRenderer));
if (replaceHandlers)
handlers.AddCompatibilityRenderer<SKGLView, SKGLViewRenderer>();
else
handlers.TryAddCompatibilityRenderer(typeof(SKGLView), typeof(SKGLViewRenderer));
#pragma warning restore CS0612 // Type or member is obsolete
#else
#if !__TIZEN__
if (replaceHandlers)
handlers.AddHandler<SKCanvasView, SKCanvasViewRenderer>();
else
Expand All @@ -54,10 +42,12 @@ public static MauiAppBuilder UseSkiaSharp(this MauiAppBuilder builder, bool regi
#endif
}
#if !__TIZEN__
CompatRegistrar.Registered.Register(typeof(SKImageImageSource), typeof(SKImageSourceHandler));
CompatRegistrar.Registered.Register(typeof(SKBitmapImageSource), typeof(SKImageSourceHandler));
CompatRegistrar.Registered.Register(typeof(SKPixmapImageSource), typeof(SKImageSourceHandler));
CompatRegistrar.Registered.Register(typeof(SKPictureImageSource), typeof(SKImageSourceHandler));
#endif
#endif
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<None Include="**\*.Tizen.cs" />
</ItemGroup>
<!-- forms files -->
<ItemGroup>
<ItemGroup Condition="!$(TargetFramework.Contains('-tizen'))">
<Compile Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SKCanvasViewRendererBase.cs" Link="SKCanvasViewRendererBase.cs" />
<Compile Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SKGLViewRendererBase.cs" Link="SKGLViewRendererBase.cs" />
</ItemGroup>
Expand Down Expand Up @@ -74,14 +74,4 @@
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.UWP\SKGLViewRenderer.cs" Link="Windows\SKGLViewRenderer.cs" />
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.UWP\SKImageSourceHandler.cs" Link="Windows\SKImageSourceHandler.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-tizen'))">
<Compile Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKCanvasViewRenderer.cs" Link="Tizen\SKCanvasViewRenderer.cs" />
<Compile Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKGLViewRenderer.cs" Link="Tizen\SKGLViewRenderer.cs" />
<Compile Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKImageSourceHandler.cs" Link="Tizen\SKImageSourceHandler.cs" />
</ItemGroup>
<ItemGroup Condition="!$(TargetFramework.Contains('-tizen'))">
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKCanvasViewRenderer.cs" Link="Tizen\SKCanvasViewRenderer.cs" />
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKGLViewRenderer.cs" Link="Tizen\SKGLViewRenderer.cs" />
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKImageSourceHandler.cs" Link="Tizen\SKImageSourceHandler.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Microsoft.Maui;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using SkiaSharp.Views.Tizen;
using Microsoft.Maui.Handlers;
using SkiaSharp.Views.Maui.Platform;
using SkiaSharp.Views.Tizen.NUI;
using ScalingInfo = SkiaSharp.Views.Tizen.ScalingInfo;

namespace SkiaSharp.Views.Maui.Handlers
{
Expand All @@ -11,7 +10,7 @@ public partial class SKCanvasViewHandler : ViewHandler<ISKCanvasView, SKCanvasVi
private SKSizeI lastCanvasSize;
private SKTouchHandler? touchHandler;

protected override SKCanvasView CreatePlatformView() => new SKCanvasView(PlatformParent);
protected override SKCanvasView CreatePlatformView() => new SKCanvasView();

protected override void ConnectHandler(SKCanvasView platformView)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Maui;
using Tizen.UIExtensions.ElmSharp;
using Microsoft.Maui.Platform;

namespace SkiaSharp.Views.Maui.Handlers
{
public partial class SKImageSourceService
{
public override Task<IImageSourceServiceResult<Image>?> GetImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) =>
GetImageAsync((IStreamImageSource)imageSource, image, cancellationToken);
public override Task<IImageSourceServiceResult<MauiImageSource>?> GetImageAsync(
IImageSource imageSource,
CancellationToken cancellationToken = default) =>
GetImageAsync((IStreamImageSource)imageSource, cancellationToken);

public async Task<IImageSourceServiceResult<Image>?> GetImageAsync(IStreamImageSource imageSource, Image image, CancellationToken cancellationToken = default)
public async Task<IImageSourceServiceResult<MauiImageSource>?> GetImageAsync(IStreamImageSource imageSource, CancellationToken cancellationToken = default)
{
if (imageSource.IsEmpty)
return null;
Expand All @@ -32,12 +34,11 @@ public partial class SKImageSourceService
if (stream == null)
throw new InvalidOperationException("Unable to load image stream.");

var isLoadComplated = await image.LoadAsync(stream, cancellationToken);
var image = new MauiImageSource();
await image.LoadSource(stream);

if (!isLoadComplated)
throw new InvalidOperationException("Unable to decode image from stream.");
return new ImageSourceServiceResult(image, image.Dispose);

return new ImageSourceServiceResult(image);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SkiaSharp.Views.Tizen;
using SkiaSharp.Views.Tizen.NUI;

namespace SkiaSharp.Views.Maui.Platform
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#nullable enable
using System;
using Tizen.NUI;
using NView = Tizen.NUI.BaseComponents.View;

#if __MAUI__
namespace SkiaSharp.Views.Maui.Platform
#else
namespace SkiaSharp.Views.Forms
#endif
{
internal class SKTouchHandler
{
private Action<SKTouchEventArgs>? onTouchAction;
private Func<double, double, SKPoint>? scalePixels;
private bool touchEnabled;
private int currentId = 0;

public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<double, double, SKPoint> scalePixels)
{
this.onTouchAction = onTouchAction;
this.scalePixels = scalePixels;
}

public void SetEnabled(NView view, bool enableTouchEvents)
{
if (view != null)
{
if (touchEnabled != enableTouchEvents)
{
if (enableTouchEvents)
{
view.TouchEvent += OnTouchEvent;
}
else
{
view.TouchEvent -= OnTouchEvent;
}
touchEnabled = enableTouchEvents;
}
}
}

bool OnTouchEvent(object source, NView.TouchEventArgs e)
{
var pos = e.Touch.GetLocalPosition(0);
var action = ToTouchAction(e.Touch.GetState(0));
if (action == SKTouchAction.Pressed)
{
currentId++;
}

var coords = scalePixels?.Invoke(pos.X, pos.Y) ?? new SKPoint(pos.X, pos.Y);
var inContact = (action == SKTouchAction.Pressed || action == SKTouchAction.Moved) ? true : false;
onTouchAction?.Invoke(new SKTouchEventArgs(currentId, action, coords, inContact));
return true;
}

public void Detach(NView view)
{
// clean the view
SetEnabled(view, false);

// remove references
onTouchAction = null;
scalePixels = null;
}

private static SKTouchAction ToTouchAction(PointStateType state) => state switch
{
PointStateType.Down => SKTouchAction.Pressed,
PointStateType.Up => SKTouchAction.Released,
PointStateType.Motion => SKTouchAction.Moved,
PointStateType.Leave => SKTouchAction.Exited,
PointStateType.Interrupted => SKTouchAction.Cancelled,
_ => SKTouchAction.Cancelled,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,4 @@
<ItemGroup Condition="!$(TargetFramework.Contains('-windows'))">
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.UWP\SKTouchHandler.cs" Link="Platform\Windows\SKTouchHandler.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-tizen'))">
<Compile Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKTouchHandler.cs" Link="Platform\Tizen\SKTouchHandler.cs" />
</ItemGroup>
<ItemGroup Condition="!$(TargetFramework.Contains('-tizen'))">
<None Include="..\..\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Tizen\SKTouchHandler.cs" Link="Platform\Tizen\SKTouchHandler.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Threading;
using Tizen.NUI;
using NImageView = Tizen.NUI.BaseComponents.ImageView;

namespace SkiaSharp.Views.Tizen.NUI
{
public abstract class CustomRenderingView : NImageView
{
bool _redrawRequest;

protected SynchronizationContext MainloopContext { get; }

protected CustomRenderingView()
{
Layout = new CustomLayout
{
SizeUpdated = OnResized
};
MainloopContext = SynchronizationContext.Current ?? throw new InvalidOperationException("Must create on main thread");
}

public event EventHandler<SKPaintSurfaceEventArgs>? PaintSurface;

public void Invalidate()
{
if (!_redrawRequest)
{
_redrawRequest = true;
MainloopContext.Post((s) =>
{
_redrawRequest = false;
if (!Disposed)
{
OnDrawFrame();
}
}, null);
}
}

protected abstract void OnResized();

protected abstract void OnDrawFrame();

protected void SendPaintSurface(SKPaintSurfaceEventArgs e)
{
PaintSurface?.Invoke(this, e);
}

class CustomLayout : AbsoluteLayout
{
float _width;
float _height;

public Action? SizeUpdated { get; set; }

protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
{
var sizeChanged = _width != Owner.SizeWidth || _height != Owner.SizeHeight;
_width = Owner.SizeWidth;
_height = Owner.SizeHeight;
if (sizeChanged)
{
SizeUpdated?.Invoke();
}
base.OnLayout(changed, left, top, right, bottom);
}
}
}
}
Loading

0 comments on commit 88c0960

Please sign in to comment.