@ -23,7 +23,8 @@ namespace Avalonia.Win32.DirectX
private IUnknown ? _ renderTexture ;
private IUnknown ? _ renderTexture ;
private RECT _ clientRect ;
private RECT _ clientRect ;
private EglSurface ? _ surface ;
public DxgiRenderTarget ( EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfo window , EglContext context , DxgiConnection connection ) : base ( context )
public DxgiRenderTarget ( EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfo window , EglContext context , DxgiConnection connection ) : base ( context )
{
{
_ window = window ;
_ window = window ;
@ -83,7 +84,6 @@ namespace Avalonia.Win32.DirectX
}
}
var contextLock = Context . EnsureCurrent ( ) ;
var contextLock = Context . EnsureCurrent ( ) ;
EglSurface ? surface = null ;
IDisposable ? transaction = null ;
IDisposable ? transaction = null ;
var success = false ;
var success = false ;
try
try
@ -96,6 +96,9 @@ namespace Avalonia.Win32.DirectX
if ( _ renderTexture is not null )
if ( _ renderTexture is not null )
{
{
_ surface ? . Dispose ( ) ;
_ surface = null ;
_ renderTexture . Dispose ( ) ;
_ renderTexture . Dispose ( ) ;
_ renderTexture = null ;
_ renderTexture = null ;
}
}
@ -114,19 +117,24 @@ namespace Avalonia.Win32.DirectX
var texture = _ renderTexture ;
var texture = _ renderTexture ;
if ( texture is null )
if ( texture is null )
{
{
_ surface ? . Dispose ( ) ;
_ surface = null ;
Guid textureGuid = ID3D11Texture2DGuid ;
Guid textureGuid = ID3D11Texture2DGuid ;
texture = MicroComRuntime . CreateProxyFor < IUnknown > ( _ swapChain . GetBuffer ( 0 , & textureGuid ) , true ) ;
texture = MicroComRuntime . CreateProxyFor < IUnknown > ( _ swapChain . GetBuffer ( 0 , & textureGuid ) , true ) ;
}
}
_ renderTexture = texture ;
_ renderTexture = texture ;
// I also have to get the pointer to this texture directly
if ( _ surface is null )
surface = ( ( AngleWin32EglDisplay ) Context . Display ) . WrapDirect3D11Texture ( MicroComRuntime . GetNativeIntPtr ( _ renderTexture ) ,
{
0 , 0 , size . Width , size . Height ) ;
// I also have to get the pointer to this texture directly
_ surface = ( ( AngleWin32EglDisplay ) Context . Display ) . WrapDirect3D11Texture ( MicroComRuntime . GetNativeIntPtr ( _ renderTexture ) ,
0 , 0 , size . Width , size . Height ) ;
}
var res = base . BeginDraw ( surface , _ window . Size , _ window . Scaling , ( ) = >
var res = base . BeginDraw ( _ surface , _ window . Size , _ window . Scaling , ( ) = >
{
{
_ swapChain . Present ( ( ushort ) 0 U , ( ushort ) 0 U ) ;
_ swapChain . Present ( ( ushort ) 0 U , ( ushort ) 0 U ) ;
surface . Dispose ( ) ;
transaction ? . Dispose ( ) ;
transaction ? . Dispose ( ) ;
contextLock ? . Dispose ( ) ;
contextLock ? . Dispose ( ) ;
} , true ) ;
} , true ) ;
@ -137,7 +145,8 @@ namespace Avalonia.Win32.DirectX
{
{
if ( ! success )
if ( ! success )
{
{
surface ? . Dispose ( ) ;
_ surface ? . Dispose ( ) ;
_ surface = null ;
if ( _ renderTexture is not null )
if ( _ renderTexture is not null )
{
{
_ renderTexture . Dispose ( ) ;
_ renderTexture . Dispose ( ) ;
@ -155,6 +164,7 @@ namespace Avalonia.Win32.DirectX
_d xgiDevice ? . Dispose ( ) ;
_d xgiDevice ? . Dispose ( ) ;
_d xgiFactory ? . Dispose ( ) ;
_d xgiFactory ? . Dispose ( ) ;
_ swapChain ? . Dispose ( ) ;
_ swapChain ? . Dispose ( ) ;
_ surface ? . Dispose ( ) ;
_ renderTexture ? . Dispose ( ) ;
_ renderTexture ? . Dispose ( ) ;
}
}