Browse Source

Add "EGL_ANGLE_flexible_surface_compatibility" ext check (#13080)

* Add "EGL_ANGLE_flexible_surface_compatibility" ext check

* Use stackalloc with CreatePBufferFromClientBuffer attributes

* Fix broken API
revert-13066-fixes/13064-logical-scrollable
Max Katz 3 years ago
committed by GitHub
parent
commit
ceab482834
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/Avalonia.OpenGL/Egl/EglContext.cs
  2. 12
      src/Avalonia.OpenGL/Egl/EglDisplay.cs
  3. 7
      src/Avalonia.OpenGL/Egl/EglInterface.cs
  4. 14
      src/Windows/Avalonia.Win32/OpenGl/Angle/AngleExternalD3D11Texture2D.cs
  5. 39
      src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32EglDisplay.cs

1
src/Avalonia.OpenGL/Egl/EglContext.cs

@ -48,6 +48,7 @@ namespace Avalonia.OpenGL.Egl
public int SampleCount { get; }
public int StencilSize { get; }
public EglDisplay Display => _disp;
public EglInterface EglInterface => _egl;
private class RestoreContext : IDisposable
{

12
src/Avalonia.OpenGL/Egl/EglDisplay.cs

@ -113,12 +113,20 @@ namespace Avalonia.OpenGL.Egl
return new EglSurface(this, s);
}
}
public unsafe EglSurface CreatePBufferFromClientBuffer(int bufferType, IntPtr handle, int[] attribs)
{
fixed (int* attrs = attribs)
{
return CreatePBufferFromClientBuffer(bufferType, handle, attrs);
}
}
public EglSurface CreatePBufferFromClientBuffer (int bufferType, IntPtr handle, int[] attribs)
public unsafe EglSurface CreatePBufferFromClientBuffer (int bufferType, IntPtr handle, int* attribs)
{
using (Lock())
{
var s = EglInterface.CreatePbufferFromClientBuffer(Handle, bufferType, handle,
var s = EglInterface.CreatePbufferFromClientBufferPtr(Handle, bufferType, handle,
Config, attribs);
if (s == IntPtr.Zero)

7
src/Avalonia.OpenGL/Egl/EglInterface.cs

@ -122,10 +122,13 @@ namespace Avalonia.OpenGL.Egl
return null;
return Marshal.PtrToStringAnsi(rv);
}
[GetProcAddress("eglCreatePbufferFromClientBuffer")]
public partial IntPtr CreatePbufferFromClientBuffer(IntPtr display, int buftype, IntPtr buffer, IntPtr config, int[]? attrib_list);
[GetProcAddress("eglCreatePbufferFromClientBuffer")]
public partial IntPtr CreatePbufferFromClientBufferPtr(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);

14
src/Windows/Avalonia.Win32/OpenGl/Angle/AngleExternalD3D11Texture2D.cs

@ -28,13 +28,13 @@ internal class AngleExternalMemoryD3D11Texture2D : IGlExternalImageTexture
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;

39
src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32EglDisplay.cs

@ -2,6 +2,7 @@ using System;
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;
@ -15,6 +16,8 @@ namespace Avalonia.Win32.OpenGl.Angle
{
internal class AngleWin32EglDisplay : EglDisplay
{
private readonly bool _flexibleSurfaceSupported;
protected override bool DisplayLockIsSharedWithContexts => true;
public static AngleWin32EglDisplay CreateD3D9Display(EglInterface egl)
@ -22,7 +25,7 @@ namespace Avalonia.Win32.OpenGl.Angle
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,
@ -35,7 +38,7 @@ namespace Avalonia.Win32.OpenGl.Angle
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,
@ -125,7 +128,7 @@ namespace Avalonia.Win32.OpenGl.Angle
throw OpenGlException.GetFormattedException("eglGetPlatformDisplayEXT", egl);
var rv = new AngleWin32EglDisplay(display,
var rv = new AngleWin32EglDisplay(display, egl,
new EglDisplayOptions
{
DisposeCallback = Cleanup,
@ -148,9 +151,11 @@ namespace Avalonia.Win32.OpenGl.Angle
}
}
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; }
@ -164,18 +169,32 @@ namespace Avalonia.Win32.OpenGl.Angle
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);
}
}
}

Loading…
Cancel
Save