3 changed files with 92 additions and 30 deletions
@ -0,0 +1,64 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using CoreAnimation; |
||||
|
using CoreGraphics; |
||||
|
using Foundation; |
||||
|
using GLKit; |
||||
|
using ObjCRuntime; |
||||
|
using OpenGLES; |
||||
|
using Perspex.Platform; |
||||
|
using UIKit; |
||||
|
|
||||
|
namespace Perspex.Skia.iOS |
||||
|
{ |
||||
|
public abstract class SkiaView : GLKView |
||||
|
{ |
||||
|
[DllImport("__Internal")] |
||||
|
static extern IntPtr GetPerspexEAGLContext(); |
||||
|
|
||||
|
bool _drawQueued; |
||||
|
CADisplayLink _link; |
||||
|
static EAGLContext GetContext() |
||||
|
{ |
||||
|
//Ensure initialization
|
||||
|
MethodTable.Instance.SetOption((MethodTable.Option)0x10009999, IntPtr.Zero); |
||||
|
var ctx = GetPerspexEAGLContext(); |
||||
|
var rv = Runtime.GetNSObject<EAGLContext>(ctx); |
||||
|
rv.DangerousRetain(); |
||||
|
return rv; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
protected SkiaView() : base(UIScreen.MainScreen.ApplicationFrame, GetContext()) |
||||
|
{ |
||||
|
(_link = CADisplayLink.Create(() => OnFrame())).AddToRunLoop(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); |
||||
|
} |
||||
|
|
||||
|
protected void OnFrame() |
||||
|
{ |
||||
|
if (_drawQueued) |
||||
|
{ |
||||
|
_drawQueued = false; |
||||
|
Display(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected void DrawOnNextFrame() |
||||
|
{ |
||||
|
_drawQueued = true; |
||||
|
} |
||||
|
|
||||
|
protected IPlatformHandle PerspexPlatformHandle { get; } |
||||
|
= new PlatformHandle(IntPtr.Zero, "Null (iOS-specific)"); |
||||
|
|
||||
|
|
||||
|
protected abstract void Draw(); |
||||
|
|
||||
|
public override void Draw(CGRect rect) |
||||
|
{ |
||||
|
Draw(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue