-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen] Change tizen graphics backend engine (#2225)
- Loading branch information
Showing
14 changed files
with
436 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Platform/Tizen/SKCanvasViewExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
79 changes: 79 additions & 0 deletions
79
source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Core/Platform/Tizen/SKTouchHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
source/SkiaSharp.Views/SkiaSharp.Views.Tizen/CustomRenderingView.nui.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.