diff --git a/src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.Tizen.cs b/src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.Tizen.cs index 361bb245017e..a69a4eae0373 100644 --- a/src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.Tizen.cs +++ b/src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.Tizen.cs @@ -1,4 +1,5 @@ using Microsoft.Maui.Graphics.Skia.Views; +using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView; namespace Microsoft.Maui.Handlers { diff --git a/src/Core/src/Platform/Tizen/GraphicsViewExtensions.cs b/src/Core/src/Platform/Tizen/GraphicsViewExtensions.cs index 978262a5c46a..3c05a1324153 100644 --- a/src/Core/src/Platform/Tizen/GraphicsViewExtensions.cs +++ b/src/Core/src/Platform/Tizen/GraphicsViewExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.Maui.Graphics.Skia.Views; +using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView; namespace Microsoft.Maui { diff --git a/src/Core/src/Platform/Tizen/MauiShapeView.cs b/src/Core/src/Platform/Tizen/MauiShapeView.cs index 856540085da7..30afef24efa8 100644 --- a/src/Core/src/Platform/Tizen/MauiShapeView.cs +++ b/src/Core/src/Platform/Tizen/MauiShapeView.cs @@ -1,5 +1,6 @@ using ElmSharp; using Microsoft.Maui.Graphics.Skia.Views; +using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView; namespace Microsoft.Maui { diff --git a/src/Core/src/Platform/Tizen/SkiaGraphicsView.Tizen.cs b/src/Core/src/Platform/Tizen/SkiaGraphicsView.Tizen.cs new file mode 100644 index 000000000000..84cdea6fd9a7 --- /dev/null +++ b/src/Core/src/Platform/Tizen/SkiaGraphicsView.Tizen.cs @@ -0,0 +1,62 @@ +#nullable disable +using ElmSharp; +using SkiaSharp.Views.Tizen; +using Microsoft.Maui.Graphics; +using Microsoft.Maui.Graphics.Skia; + +namespace Microsoft.Maui.Platform.Tizen +{ + // TODO. Remove it + // This class a temporary used, until Microsoft.Maui.Graphics.Skia.Views.SkiaGraphicsView is updated on upstream. + public class SkiaGraphicsView : SKCanvasView + { + private IDrawable _drawable; + private SkiaCanvas _canvas; + private ScalingCanvas _scalingCanvas; + + public SkiaGraphicsView(EvasObject parent, IDrawable drawable = null) : base(parent) + { + _canvas = new SkiaCanvas(); + _scalingCanvas = new ScalingCanvas(_canvas); + Drawable = drawable; + PaintSurface += OnPaintSurface; + } + + public float DeviceScalingFactor { get; set; } + + public IDrawable Drawable + { + get => _drawable; + set + { + _drawable = value; + Invalidate(); + } + } + + protected virtual void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e) + { + if (_drawable == null) return; + + var skiaCanvas = e.Surface.Canvas; + skiaCanvas.Clear(); + + _canvas.Canvas = skiaCanvas; + _scalingCanvas.ResetState(); + + float width = e.Info.Width; + float height = e.Info.Height; + if (DeviceScalingFactor > 0) + { + width = width / DeviceScalingFactor; + height = height / DeviceScalingFactor; + } + + _scalingCanvas.SaveState(); + if (DeviceScalingFactor > 0) + _scalingCanvas.Scale(DeviceScalingFactor, DeviceScalingFactor); + _drawable.Draw(_scalingCanvas, new RectangleF(0, 0, width, height)); + _scalingCanvas.RestoreState(); + } + } +} diff --git a/src/Core/src/Platform/Tizen/WrapperView.cs b/src/Core/src/Platform/Tizen/WrapperView.cs index 65d2faf02527..3aeef68a8d80 100644 --- a/src/Core/src/Platform/Tizen/WrapperView.cs +++ b/src/Core/src/Platform/Tizen/WrapperView.cs @@ -7,6 +7,7 @@ using SkiaSharp.Views.Tizen; using Tizen.UIExtensions.Common; using Tizen.UIExtensions.ElmSharp; +using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView; namespace Microsoft.Maui {