@ -28,36 +28,99 @@ namespace Avalonia.Win32
}
public override IGlPlatformSurfaceRenderTarget CreateGlRenderTarget ( )
{
var glSurface = _d isplay . CreateWindowSurface ( _ info . Handle ) ;
return new CompositionRenderTarget ( _d isplay , _ context , glSurface , _ surfaceInterop , _ info ) ;
{
return new CompositionRenderTarget ( _d isplay , _ context , _ surfaceInterop , _ info ) ;
}
class CompositionRenderTarget : EglPlatformSurfaceRenderTargetBase
{
private readonly EglDisplay _d isplay ;
private readonly EglContext _ context ;
private readonly EglSurface _ glSurface ;
private readonly EglContext _ context ;
private readonly IEglWindowGlPlatformSurfaceInfo _ info ;
private PixelSize _ initialSize ;
private readonly ICompositionDrawingSurfaceInterop _ surfaceInterop ;
public CompositionRenderTarget ( EglDisplay display , EglContext context ,
EglSurface glSurface , ICompositionDrawingSurfaceInterop interopSurface , IEglWindowGlPlatformSurfaceInfo info ) : base ( display , context )
public CompositionRenderTarget ( EglDisplay display , EglContext context , ICompositionDrawingSurfaceInterop interopSurface , IEglWindowGlPlatformSurfaceInfo info ) : base ( display , context )
{
_d isplay = display ;
_ context = context ;
_ glSurface = glSurface ;
_ context = context ;
_ surfaceInterop = interopSurface ;
_ info = info ;
_ initialSize = info . Size ;
}
public override void Dispose ( ) = > _ glSurface . Dispose ( ) ;
public override bool IsCorrupted = > _ initialSize ! = _ info . Size ;
public override IGlPlatformSurfaceRenderingSession BeginDraw ( )
{
var l = _ context . Lock ( ) ;
var iid = Guid . Parse ( "6f15aaf2-d208-4e89-9ab4-489535d34f9c" ) ;
var updateRect = new RECT { right = _ info . Size . Width , bottom = _ info . Size . Height } ;
var offset = new POINT ( ) ;
_ surfaceInterop . Resize ( new POINT { X = _ info . Size . Width , Y = _ info . Size . Height } ) ;
_ surfaceInterop . BeginDraw (
ref updateRect ,
ref iid ,
out IntPtr texture , ref offset ) ;
public override bool IsCorrupted = > _ initialSize ! = _ info . Size ;
var surface = ( _d isplay as AngleWin32EglDisplay ) . WrapDirect3D11Texture ( texture ) ;
public override IGlPlatformSurfaceRenderingSession BeginDraw ( ) = > base . BeginDraw ( _ glSurface , _ info ) ;
var restoreContext = _ context . MakeCurrent ( surface ) ;
return new Session ( _d isplay , _ context , null , _ info , l , restoreContext , ( ) = > { } , true ) ;
}
public override void Dispose ( )
{
_ surfaceInterop . EndDraw ( ) ;
base . Dispose ( ) ;
}
}
class Session : IGlPlatformSurfaceRenderingSession
{
private readonly EglContext _ context ;
private readonly EglSurface _ glSurface ;
private readonly EglGlPlatformSurfaceBase . IEglWindowGlPlatformSurfaceInfo _ info ;
private readonly EglDisplay _d isplay ;
private readonly IDisposable _l ock ;
private readonly IDisposable _ restoreContext ;
private readonly Action _ onFinish ;
public Session ( EglDisplay display , EglContext context ,
EglSurface glSurface , EglGlPlatformSurfaceBase . IEglWindowGlPlatformSurfaceInfo info ,
IDisposable @lock , IDisposable restoreContext , Action onFinish , bool isYFlipped )
{
IsYFlipped = isYFlipped ;
_ context = context ;
_d isplay = display ;
_ glSurface = glSurface ;
_ info = info ;
_l ock = @lock ;
_ restoreContext = restoreContext ;
_ onFinish = onFinish ;
}
public void Dispose ( )
{
_ context . GlInterface . Flush ( ) ;
_d isplay . EglInterface . WaitGL ( ) ;
_ glSurface ? . SwapBuffers ( ) ;
_d isplay . EglInterface . WaitClient ( ) ;
_d isplay . EglInterface . WaitGL ( ) ;
_d isplay . EglInterface . WaitNative ( EglConsts . EGL_CORE_NATIVE_ENGINE ) ;
_ restoreContext . Dispose ( ) ;
_l ock . Dispose ( ) ;
_ onFinish ? . Invoke ( ) ;
}
public IGlContext Context = > _ context ;
public PixelSize Size = > _ info . Size ;
public double Scaling = > _ info . Scaling ;
public bool IsYFlipped { get ; }
}
}
@ -146,12 +209,11 @@ namespace Avalonia.Win32
var gDevice = interop . CreateGraphicsDevice ( display . GetDirect3DDevice ( ) ) ;
var surface = gDevice . CreateDrawingSurface ( new Windows . Foundation . Size ( 1 0 0 , 1 0 0 ) , Windows . Graphics . DirectX . DirectXPixelFormat . B8G8R8A8UIntNormalized , Windows . Graphics . DirectX . DirectXAlphaMode . Premultiplied ) ;
var surfaceInterop = surface . As < ICompositionDrawingSurfaceInterop > ( ) ;
var surface = gDevice . CreateDrawingSurface ( new Windows . Foundation . Size ( 1 0 0 , 1 0 0 ) ,
Windows . Graphics . DirectX . DirectXPixelFormat . B8G8R8A8UIntNormalized ,
Windows . Graphics . DirectX . DirectXAlphaMode . Premultiplied ) ;
//surfaceInterop.BeginDraw(new Windows.Foundation.Rect(0, 0, 100, 100), Guid.Parse("6f15aaf2-d208-4e89-9ab4-489535d34f9c"), out var texture, new Windows.Foundation.Point(0, 0));
//surfaceInterop.EndDraw();
var surfaceInterop = surface . As < ICompositionDrawingSurfaceInterop > ( ) ;
var brush = _ compositor . CreateSurfaceBrush ( surface ) ;