Skip to content

Commit

Permalink
Replace SkiaGraphicsView with local patch (#135)
Browse files Browse the repository at this point in the history
This commit will be revert when upstream code is updated
  • Loading branch information
myroot authored and rookiejava committed Apr 8, 2022
1 parent 2cb94ad commit dddfb51
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Maui.Graphics.Skia.Views;
using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView;

namespace Microsoft.Maui.Handlers
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/Platform/Tizen/GraphicsViewExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Maui.Graphics.Skia.Views;
using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView;

namespace Microsoft.Maui
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/Platform/Tizen/MauiShapeView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ElmSharp;
using Microsoft.Maui.Graphics.Skia.Views;
using SkiaGraphicsView = Microsoft.Maui.Platform.Tizen.SkiaGraphicsView;

namespace Microsoft.Maui
{
Expand Down
62 changes: 62 additions & 0 deletions src/Core/src/Platform/Tizen/SkiaGraphicsView.Tizen.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
1 change: 1 addition & 0 deletions src/Core/src/Platform/Tizen/WrapperView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit dddfb51

Please sign in to comment.