Skip to content

Add "EGL_ANGLE_flexible_surface_compatibility" ext check #13080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Avalonia.OpenGL/Egl/EglContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal EglContext(EglDisplay display, EglInterface egl, EglContext? sharedWith
public int SampleCount { get; }
public int StencilSize { get; }
public EglDisplay Display => _disp;
public EglInterface EglInterface => _egl;

private class RestoreContext : IDisposable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.OpenGL/Egl/EglDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public EglSurface CreateWindowSurface(IntPtr window)
}
}

public EglSurface CreatePBufferFromClientBuffer (int bufferType, IntPtr handle, int[] attribs)
public unsafe EglSurface CreatePBufferFromClientBuffer (int bufferType, IntPtr handle, int* attribs)
{
using (Lock())
{
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.OpenGL/Egl/EglInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public partial IntPtr CreateContext(IntPtr display, IntPtr config,
}

[GetProcAddress("eglCreatePbufferFromClientBuffer")]
public partial IntPtr CreatePbufferFromClientBuffer(IntPtr display, int buftype, IntPtr buffer, IntPtr config, int[]? attrib_list);
public partial IntPtr CreatePbufferFromClientBuffer(IntPtr display, int buftype, IntPtr buffer, IntPtr config, int* attrib_list);

[GetProcAddress("eglQueryDisplayAttribEXT", true)]
public partial bool QueryDisplayAttribExt(IntPtr display, int attr, out IntPtr res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public unsafe AngleExternalMemoryD3D11Texture2D(EglContext context, ID3D11Textur

InternalFormat = GL_RGBA8;

_eglSurface = _context.Display.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, texture2D.GetNativeIntPtr(),
new[]
{
EGL_WIDTH, props.Width, EGL_HEIGHT, props.Height, EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, GL_RGBA, EGL_NONE, EGL_NONE,
EGL_NONE
});
var attrs = stackalloc[]
{
EGL_WIDTH, props.Width, EGL_HEIGHT, props.Height, EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, GL_RGBA, EGL_NONE, EGL_NONE,
EGL_NONE
};
_eglSurface = _context.Display.CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, texture2D.GetNativeIntPtr(), attrs);

var gl = _context.GlInterface;
int temp = 0;
Expand Down
39 changes: 29 additions & 10 deletions src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32EglDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Avalonia.OpenGL;
using Avalonia.OpenGL.Angle;
Expand All @@ -15,14 +16,16 @@ namespace Avalonia.Win32.OpenGl.Angle
{
internal class AngleWin32EglDisplay : EglDisplay
{
private readonly bool _flexibleSurfaceSupported;

protected override bool DisplayLockIsSharedWithContexts => true;

public static AngleWin32EglDisplay CreateD3D9Display(EglInterface egl)
{
var display = egl.GetPlatformDisplayExt(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero,
new[] { EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, EGL_NONE });

return new AngleWin32EglDisplay(display, new EglDisplayOptions()
return new AngleWin32EglDisplay(display, egl, new EglDisplayOptions()
{
Egl = egl,
ContextLossIsDisplayLoss = true,
Expand All @@ -35,7 +38,7 @@ public static AngleWin32EglDisplay CreateSharedD3D11Display(EglInterface egl)
var display = egl.GetPlatformDisplayExt(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero,
new[] { EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, EGL_NONE });

return new AngleWin32EglDisplay(display, new EglDisplayOptions()
return new AngleWin32EglDisplay(display, egl, new EglDisplayOptions()
{
Egl = egl,
ContextLossIsDisplayLoss = true,
Expand Down Expand Up @@ -125,7 +128,7 @@ void Cleanup()
throw OpenGlException.GetFormattedException("eglGetPlatformDisplayEXT", egl);


var rv = new AngleWin32EglDisplay(display,
var rv = new AngleWin32EglDisplay(display, egl,
new EglDisplayOptions
{
DisposeCallback = Cleanup,
Expand All @@ -148,9 +151,11 @@ void Cleanup()
}
}

private AngleWin32EglDisplay(IntPtr display, EglDisplayOptions options, AngleOptions.PlatformApi platformApi) : base(display, options)
private AngleWin32EglDisplay(IntPtr display, EglInterface egl, EglDisplayOptions options, AngleOptions.PlatformApi platformApi) : base(display, options)
{
PlatformApi = platformApi;
var extensions = egl.QueryString(display, EGL_EXTENSIONS);
_flexibleSurfaceSupported = extensions?.Contains("EGL_ANGLE_flexible_surface_compatibility") ?? false;
}

public AngleOptions.PlatformApi PlatformApi { get; }
Expand All @@ -164,18 +169,32 @@ public IntPtr GetDirect3DDevice()
return d3dDeviceHandle;
}

public EglSurface WrapDirect3D11Texture( IntPtr handle)
public unsafe EglSurface WrapDirect3D11Texture( IntPtr handle)
{
if (PlatformApi != AngleOptions.PlatformApi.DirectX11)
throw new InvalidOperationException("Current platform API is " + PlatformApi);
return CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_NONE, EGL_NONE });
ThrowInvalidPlatformApi();
var attrs = stackalloc[] { EGL_NONE, EGL_NONE };
return CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, attrs);
}

public EglSurface WrapDirect3D11Texture(IntPtr handle, int offsetX, int offsetY, int width, int height)
public unsafe EglSurface WrapDirect3D11Texture(IntPtr handle, int offsetX, int offsetY, int width, int height)
{
if (PlatformApi != AngleOptions.PlatformApi.DirectX11)
throw new InvalidOperationException("Current platform API is " + PlatformApi);
return CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, new[] { EGL_WIDTH, width, EGL_HEIGHT, height, EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE, EGL_TRUE, EGL_TEXTURE_OFFSET_X_ANGLE, offsetX, EGL_TEXTURE_OFFSET_Y_ANGLE, offsetY, EGL_NONE });
ThrowInvalidPlatformApi();
var attrs = stackalloc[]
{
EGL_WIDTH, width, EGL_HEIGHT, height, EGL_TEXTURE_OFFSET_X_ANGLE, offsetX,
EGL_TEXTURE_OFFSET_Y_ANGLE, offsetY,
_flexibleSurfaceSupported ? EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE : EGL_NONE, EGL_TRUE,
EGL_NONE
};
return CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle, attrs);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void ThrowInvalidPlatformApi()
{
throw new InvalidOperationException("Current platform API is " + PlatformApi);
}
}
}