5 changed files with 252 additions and 19 deletions
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Avalonia.Platform; |
|||
using Avalonia.Rendering; |
|||
using MonoMac.Foundation; |
|||
|
|||
namespace Avalonia.MonoMac |
|||
{ |
|||
//TODO: Switch to using CVDisplayLink
|
|||
public class RenderLoop : IRenderLoop |
|||
{ |
|||
private readonly object _lock = new object(); |
|||
private readonly IDisposable _timer; |
|||
|
|||
public RenderLoop() |
|||
{ |
|||
_timer = AvaloniaLocator.Current.GetService<IRuntimePlatform>().StartSystemTimer(new TimeSpan(0, 0, 0, 0, 1000 / 60), |
|||
() => |
|||
{ |
|||
lock (_lock) |
|||
{ |
|||
using (new NSAutoreleasePool()) |
|||
{ |
|||
Tick?.Invoke(this, EventArgs.Empty); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public event EventHandler<EventArgs> Tick; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using MonoMac.AppKit; |
|||
using MonoMac.ObjCRuntime; |
|||
|
|||
namespace Avalonia.MonoMac |
|||
{ |
|||
public static class ThreadingUtils |
|||
{ |
|||
private static readonly IntPtr selUnlockFocusHandle = Selector.GetHandle("unlockFocus"); |
|||
private static readonly IntPtr selLockFocusIfCanDrawHandle = Selector.GetHandle("lockFocusIfCanDraw"); |
|||
private static readonly IntPtr selWindowHandle = Selector.GetHandle("window"); |
|||
private static readonly IntPtr selCanDrawHandle = Selector.GetHandle("canDraw"); |
|||
|
|||
public static bool NonUILockFocusIfCanDraw(this NSView view) |
|||
{ |
|||
return Messaging.bool_objc_msgSend(view.Handle, selLockFocusIfCanDrawHandle); |
|||
} |
|||
|
|||
public static void NonUIUnlockFocus(this NSView view) |
|||
{ |
|||
Messaging.void_objc_msgSend(view.Handle, selUnlockFocusHandle); |
|||
} |
|||
|
|||
public static NSWindow NonUIGetWindow(this NSView view) |
|||
{ |
|||
return (NSWindow) Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(view.Handle, selWindowHandle)); |
|||
} |
|||
|
|||
public static bool BaseCanDraw(this NSView view) |
|||
{ |
|||
return Messaging.bool_objc_msgSendSuper(view.SuperHandle, selCanDrawHandle); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue