Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/SkiaSharp.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<PropertyGroup>
<BasicTargetFrameworks>netstandard1.3;netstandard2.0;net462</BasicTargetFrameworks>
<Net6PlatformTargetFrameworks>net6.0-ios;net6.0-maccatalyst;net6.0-tvos;net6.0-macos;net6.0-android</Net6PlatformTargetFrameworks>
<Net6PlatformTargetFrameworks Condition="$(IsNet6TizenSupported)">$(Net6PlatformTargetFrameworks);net6.0-tizen6.5</Net6PlatformTargetFrameworks>
<Net6PlatformTargetFrameworks Condition="$(IsNet6TizenSupported)">$(Net6PlatformTargetFrameworks);net6.0-tizen</Net6PlatformTargetFrameworks>
<Net6TargetFrameworks>net6.0;$(Net6PlatformTargetFrameworks)</Net6TargetFrameworks>
</PropertyGroup>

Expand All @@ -62,7 +62,7 @@
<!-- .NET MAUI -->
<PropertyGroup>
<MauiTargetFrameworks>net6.0;net6.0-ios;net6.0-maccatalyst;net6.0-android</MauiTargetFrameworks>
<MauiTargetFrameworks Condition="$(IsNet6TizenSupported)">$(MauiTargetFrameworks);net6.0-tizen6.5</MauiTargetFrameworks>
<MauiTargetFrameworks Condition="$(IsNet6TizenSupported)">$(MauiTargetFrameworks);net6.0-tizen</MauiTargetFrameworks>
<MauiTargetFrameworks Condition="$(IsWindows)">$(MauiTargetFrameworks);net6.0-windows10.0.19041.0</MauiTargetFrameworks>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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<ISKCanvasView, SKCanvasView>
{
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 == false && PlatformView != null)
{
var scale = PlatformView.ContentScaleFactor;

x *= scale;
y *= scale;
}

return new SKPoint((float)x, (float)y);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Maui;
using Microsoft.Extensions.Logging;
using SkiaSharp.Views.Tizen;
using Tizen.UIExtensions.ElmSharp;

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 async Task<IImageSourceServiceResult<Image>?> 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();
}
}
}