8 changed files with 114 additions and 20 deletions
@ -0,0 +1,64 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
using Perspex.Media; |
|||
using Perspex.Platform; |
|||
|
|||
namespace Perspex.Skia |
|||
{ |
|||
class RenderTarget : IRenderTarget |
|||
{ |
|||
private IntPtr _currentRenderTarget = IntPtr.Zero; |
|||
private Surface _currentSurface = null; |
|||
private SurfaceView _view = null; |
|||
|
|||
public RenderTarget(IPlatformHandle handle) |
|||
{ |
|||
_view = (SurfaceView) handle; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
if (_currentRenderTarget != IntPtr.Zero) |
|||
{ |
|||
MethodTable.Instance.DisposeRenderTarget(_currentRenderTarget); |
|||
_currentRenderTarget = IntPtr.Zero; |
|||
GC.SuppressFinalize(this); |
|||
} |
|||
} |
|||
|
|||
~RenderTarget() |
|||
{ |
|||
Dispose(); |
|||
} |
|||
|
|||
public DrawingContext CreateDrawingContext() |
|||
{ |
|||
var surface = _view.Holder.Surface; |
|||
if (surface == null) |
|||
throw new InvalidOperationException("Surface isn't available"); |
|||
if (_currentSurface != surface) |
|||
{ |
|||
_currentSurface = null; |
|||
if (_currentRenderTarget != IntPtr.Zero) |
|||
{ |
|||
MethodTable.Instance.DisposeRenderTarget(_currentRenderTarget); |
|||
_currentRenderTarget = IntPtr.Zero; |
|||
} |
|||
|
|||
_currentRenderTarget = MethodTable.Instance.CreateWindowRenderTarget(surface.Handle); |
|||
_currentSurface = surface; |
|||
} |
|||
return new DrawingContext( |
|||
new DrawingContextImpl(MethodTable.Instance.RenderTargetCreateRenderingContext(_currentRenderTarget))); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
using Perspex.Media; |
|||
using Perspex.Platform; |
|||
|
|||
namespace Perspex.Skia.Android |
|||
{ |
|||
public abstract class SkiaRenderView : SkiaView |
|||
{ |
|||
private IRenderTarget _renderTarget; |
|||
|
|||
public SkiaRenderView(Activity context) : base(context) |
|||
{ |
|||
_renderTarget = |
|||
PerspexLocator.Current.GetService<IPlatformRenderInterface>() |
|||
.CreateRenderer(this); |
|||
} |
|||
|
|||
protected override void Draw() |
|||
{ |
|||
if (_renderTarget == null) |
|||
return; |
|||
using (var ctx = _renderTarget.CreateDrawingContext()) |
|||
OnRender(ctx); |
|||
} |
|||
|
|||
protected abstract void OnRender(DrawingContext ctx); |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue