|
|
@ -26,31 +26,44 @@ namespace Avalonia.OpenGL |
|
|
public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget() |
|
|
public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget() |
|
|
{ |
|
|
{ |
|
|
var glSurface = _display.CreateWindowSurface(_info.Handle); |
|
|
var glSurface = _display.CreateWindowSurface(_info.Handle); |
|
|
return new RenderTarget(_context, glSurface, _info); |
|
|
return new RenderTarget(_display, _context, glSurface, _info); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class RenderTarget : IGlPlatformSurfaceRenderTarget |
|
|
class RenderTarget : IGlPlatformSurfaceRenderTargetWithCorruptionInfo |
|
|
{ |
|
|
{ |
|
|
|
|
|
private readonly EglDisplay _display; |
|
|
private readonly EglContext _context; |
|
|
private readonly EglContext _context; |
|
|
private readonly EglSurface _glSurface; |
|
|
private readonly EglSurface _glSurface; |
|
|
private readonly IEglWindowGlPlatformSurfaceInfo _info; |
|
|
private readonly IEglWindowGlPlatformSurfaceInfo _info; |
|
|
|
|
|
private PixelSize _initialSize; |
|
|
|
|
|
|
|
|
public RenderTarget(EglContext context, EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info) |
|
|
public RenderTarget(EglDisplay display, EglContext context, |
|
|
|
|
|
EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info) |
|
|
{ |
|
|
{ |
|
|
|
|
|
_display = display; |
|
|
_context = context; |
|
|
_context = context; |
|
|
_glSurface = glSurface; |
|
|
_glSurface = glSurface; |
|
|
_info = info; |
|
|
_info = info; |
|
|
|
|
|
_initialSize = info.Size; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Dispose() => _glSurface.Dispose(); |
|
|
public void Dispose() => _glSurface.Dispose(); |
|
|
|
|
|
|
|
|
|
|
|
public bool IsCorrupted => _initialSize != _info.Size; |
|
|
|
|
|
|
|
|
public IGlPlatformSurfaceRenderingSession BeginDraw() |
|
|
public IGlPlatformSurfaceRenderingSession BeginDraw() |
|
|
{ |
|
|
{ |
|
|
var l = _context.Lock(); |
|
|
var l = _context.Lock(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (IsCorrupted) |
|
|
|
|
|
throw new RenderTargetCorruptedException(); |
|
|
_context.MakeCurrent(_glSurface); |
|
|
_context.MakeCurrent(_glSurface); |
|
|
return new Session(_context, _glSurface, _info, l); |
|
|
_display.EglInterface.WaitClient(); |
|
|
|
|
|
_display.EglInterface.WaitGL(); |
|
|
|
|
|
_display.EglInterface.WaitNative(); |
|
|
|
|
|
|
|
|
|
|
|
return new Session(_display, _context, _glSurface, _info, l); |
|
|
} |
|
|
} |
|
|
catch |
|
|
catch |
|
|
{ |
|
|
{ |
|
|
@ -61,15 +74,19 @@ namespace Avalonia.OpenGL |
|
|
|
|
|
|
|
|
class Session : IGlPlatformSurfaceRenderingSession |
|
|
class Session : IGlPlatformSurfaceRenderingSession |
|
|
{ |
|
|
{ |
|
|
private readonly IGlContext _context; |
|
|
private readonly EglContext _context; |
|
|
private readonly EglSurface _glSurface; |
|
|
private readonly EglSurface _glSurface; |
|
|
private readonly IEglWindowGlPlatformSurfaceInfo _info; |
|
|
private readonly IEglWindowGlPlatformSurfaceInfo _info; |
|
|
|
|
|
private readonly EglDisplay _display; |
|
|
private IDisposable _lock; |
|
|
private IDisposable _lock; |
|
|
|
|
|
|
|
|
public Session(IGlContext context, EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info, |
|
|
|
|
|
|
|
|
public Session(EglDisplay display, EglContext context, |
|
|
|
|
|
EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info, |
|
|
IDisposable @lock) |
|
|
IDisposable @lock) |
|
|
{ |
|
|
{ |
|
|
_context = context; |
|
|
_context = context; |
|
|
|
|
|
_display = display; |
|
|
_glSurface = glSurface; |
|
|
_glSurface = glSurface; |
|
|
_info = info; |
|
|
_info = info; |
|
|
_lock = @lock; |
|
|
_lock = @lock; |
|
|
@ -78,7 +95,11 @@ namespace Avalonia.OpenGL |
|
|
public void Dispose() |
|
|
public void Dispose() |
|
|
{ |
|
|
{ |
|
|
_context.Display.GlInterface.Flush(); |
|
|
_context.Display.GlInterface.Flush(); |
|
|
|
|
|
_display.EglInterface.WaitGL(); |
|
|
_glSurface.SwapBuffers(); |
|
|
_glSurface.SwapBuffers(); |
|
|
|
|
|
_display.EglInterface.WaitClient(); |
|
|
|
|
|
_display.EglInterface.WaitGL(); |
|
|
|
|
|
_display.EglInterface.WaitNative(); |
|
|
_context.Display.ClearContext(); |
|
|
_context.Display.ClearContext(); |
|
|
_lock.Dispose(); |
|
|
_lock.Dispose(); |
|
|
} |
|
|
} |
|
|
|