Skip to content

Commit 0f4e467

Browse files
committed
Add "EGL_ANGLE_flexible_surface_compatibility" ext check
1 parent 3430e6d commit 0f4e467

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Avalonia.OpenGL/Egl/EglContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal EglContext(EglDisplay display, EglInterface egl, EglContext? sharedWith
4848
public int SampleCount { get; }
4949
public int StencilSize { get; }
5050
public EglDisplay Display => _disp;
51+
public EglInterface EglInterface => _egl;
5152

5253
private class RestoreContext : IDisposable
5354
{

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ namespace Avalonia.Win32.OpenGl.Angle
1515
{
1616
internal class AngleWin32EglDisplay : EglDisplay
1717
{
18+
private readonly bool _flexibleSurfaceSupported;
19+
1820
protected override bool DisplayLockIsSharedWithContexts => true;
1921

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

25-
return new AngleWin32EglDisplay(display, new EglDisplayOptions()
27+
return new AngleWin32EglDisplay(display, egl, new EglDisplayOptions()
2628
{
2729
Egl = egl,
2830
ContextLossIsDisplayLoss = true,
@@ -35,7 +37,7 @@ public static AngleWin32EglDisplay CreateSharedD3D11Display(EglInterface egl)
3537
var display = egl.GetPlatformDisplayExt(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero,
3638
new[] { EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, EGL_NONE });
3739

38-
return new AngleWin32EglDisplay(display, new EglDisplayOptions()
40+
return new AngleWin32EglDisplay(display, egl, new EglDisplayOptions()
3941
{
4042
Egl = egl,
4143
ContextLossIsDisplayLoss = true,
@@ -125,7 +127,7 @@ void Cleanup()
125127
throw OpenGlException.GetFormattedException("eglGetPlatformDisplayEXT", egl);
126128

127129

128-
var rv = new AngleWin32EglDisplay(display,
130+
var rv = new AngleWin32EglDisplay(display, egl,
129131
new EglDisplayOptions
130132
{
131133
DisposeCallback = Cleanup,
@@ -148,9 +150,11 @@ void Cleanup()
148150
}
149151
}
150152

151-
private AngleWin32EglDisplay(IntPtr display, EglDisplayOptions options, AngleOptions.PlatformApi platformApi) : base(display, options)
153+
private AngleWin32EglDisplay(IntPtr display, EglInterface egl, EglDisplayOptions options, AngleOptions.PlatformApi platformApi) : base(display, options)
152154
{
153155
PlatformApi = platformApi;
156+
var extensions = egl.QueryString(display, EGL_EXTENSIONS);
157+
_flexibleSurfaceSupported = extensions?.Contains("EGL_ANGLE_flexible_surface_compatibility") ?? false;
154158
}
155159

156160
public AngleOptions.PlatformApi PlatformApi { get; }
@@ -175,7 +179,14 @@ public EglSurface WrapDirect3D11Texture(IntPtr handle, int offsetX, int offsetY,
175179
{
176180
if (PlatformApi != AngleOptions.PlatformApi.DirectX11)
177181
throw new InvalidOperationException("Current platform API is " + PlatformApi);
178-
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 });
182+
return CreatePBufferFromClientBuffer(EGL_D3D_TEXTURE_ANGLE, handle,
183+
new[]
184+
{
185+
EGL_WIDTH, width, EGL_HEIGHT, height, EGL_TEXTURE_OFFSET_X_ANGLE, offsetX,
186+
EGL_TEXTURE_OFFSET_Y_ANGLE, offsetY,
187+
_flexibleSurfaceSupported ? EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE : EGL_NONE, EGL_TRUE,
188+
EGL_NONE
189+
});
179190
}
180191
}
181192
}

0 commit comments

Comments
 (0)