@ -1,5 +1,6 @@
using System ;
using System.Runtime.InteropServices ;
using Avalonia.OpenGL ;
using Avalonia.OpenGL.Angle ;
using Windows.UI.Composition ;
using Windows.UI.Composition.Interop ;
@ -7,6 +8,61 @@ using WinRT;
namespace Avalonia.Win32
{
public class CompositionEglGlPlatformSurface : EglGlPlatformSurfaceBase
{
private readonly EglDisplay _d isplay ;
private readonly EglContext _ context ;
private readonly IEglWindowGlPlatformSurfaceInfo _ info ;
private ICompositionDrawingSurfaceInterop _ surfaceInterop ;
public CompositionEglGlPlatformSurface ( EglContext context , IEglWindowGlPlatformSurfaceInfo info ) : base ( )
{
_d isplay = context . Display ;
_ context = context ;
_ info = info ;
}
public void AttachToCompositionTree ( IntPtr hwnd )
{
_ surfaceInterop = CompositionHost . Instance . Initialize ( hwnd ) ;
}
public override IGlPlatformSurfaceRenderTarget CreateGlRenderTarget ( )
{
var glSurface = _d isplay . CreateWindowSurface ( _ info . Handle ) ;
return new CompositionRenderTarget ( _d isplay , _ context , glSurface , _ surfaceInterop , _ info ) ;
}
class CompositionRenderTarget : EglPlatformSurfaceRenderTargetBase
{
private readonly EglDisplay _d isplay ;
private readonly EglContext _ context ;
private readonly EglSurface _ glSurface ;
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 )
{
_d isplay = display ;
_ context = context ;
_ glSurface = glSurface ;
_ surfaceInterop = interopSurface ;
_ info = info ;
_ initialSize = info . Size ;
}
public override void Dispose ( ) = > _ glSurface . Dispose ( ) ;
public override bool IsCorrupted = > _ initialSize ! = _ info . Size ;
public override IGlPlatformSurfaceRenderingSession BeginDraw ( ) = > base . BeginDraw ( _ glSurface , _ info ) ;
}
}
class CompositionHost
{
internal enum DISPATCHERQUEUE_THREAD_APARTMENTTYPE
@ -75,7 +131,7 @@ namespace Avalonia.Win32
}
}
public void Initialize ( IntPtr hwnd )
public ICompositionDrawingSurfaceInterop Initialize ( IntPtr hwnd )
{
EnsureDispatcherQueue ( ) ;
if ( _d ispatcherQueueController ! = null )
@ -90,13 +146,13 @@ 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 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 > ( ) ;
surfaceInterop . BeginDraw ( new Windows . Foundation . Rect ( 0 , 0 , 1 0 0 , 1 0 0 ) , Guid . Parse ( "6f15aaf2-d208-4e89-9ab4-489535d34f9c" ) , out var texture , new Windows . Foundation . Point ( 0 , 0 ) ) ;
surfaceInterop . EndDraw ( ) ;
//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 brush = _ compositor . CreateSurfaceBrush ( surface ) ;
var visual = _ compositor . CreateSpriteVisual ( ) ;
@ -108,6 +164,7 @@ namespace Avalonia.Win32
AddElement ( 1 0 0 , 2 0 0 , 2 0 0 ) ;
return surfaceInterop ;
}
public void CreateBlur ( )