Browse Source

Merge pull request #10888 from AvaloniaUI/fixes/x11-actually-use-separate-connection-for-gl

Use DeferredDisplay for GLX
pull/10953/head
Steven Kirk 4 years ago
committed by GitHub
parent
commit
d8c33203b9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Avalonia.X11/Glx/GlxContext.cs
  2. 22
      src/Avalonia.X11/Glx/GlxDisplay.cs
  3. 2
      src/Avalonia.X11/X11Window.cs

8
src/Avalonia.X11/Glx/GlxContext.cs

@ -106,8 +106,8 @@ namespace Avalonia.X11.Glx
var success = false; var success = false;
try try
{ {
var old = new RestoreContext(Glx, _x11.Display, _lock); var old = new RestoreContext(Glx, _x11.DeferredDisplay, _lock);
if (!Glx.MakeContextCurrent(_x11.Display, xid, xid, Handle)) if (!Glx.MakeContextCurrent(_x11.DeferredDisplay, xid, xid, Handle))
throw new OpenGlException("glXMakeContextCurrent failed "); throw new OpenGlException("glXMakeContextCurrent failed ");
success = true; success = true;
@ -124,9 +124,9 @@ namespace Avalonia.X11.Glx
public void Dispose() public void Dispose()
{ {
Glx.DestroyContext(_x11.Display, Handle); Glx.DestroyContext(_x11.DeferredDisplay, Handle);
if (_ownsPBuffer) if (_ownsPBuffer)
Glx.DestroyPbuffer(_x11.Display, _defaultXid); Glx.DestroyPbuffer(_x11.DeferredDisplay, _defaultXid);
} }
public object TryGetFeature(Type featureType) public object TryGetFeature(Type featureType)

22
src/Avalonia.X11/Glx/GlxDisplay.cs

@ -22,7 +22,7 @@ namespace Avalonia.X11.Glx
{ {
_x11 = x11; _x11 = x11;
_probeProfiles = probeProfiles.ToArray(); _probeProfiles = probeProfiles.ToArray();
_displayExtensions = Glx.GetExtensions(_x11.Display); _displayExtensions = Glx.GetExtensions(_x11.DeferredDisplay);
var baseAttribs = new[] var baseAttribs = new[]
{ {
@ -46,12 +46,12 @@ namespace Avalonia.X11.Glx
baseAttribs, baseAttribs,
}) })
{ {
var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen, var ptr = Glx.ChooseFBConfig(_x11.DeferredDisplay, x11.DefaultScreen,
attribs, out var count); attribs, out var count);
for (var c = 0 ; c < count; c++) for (var c = 0 ; c < count; c++)
{ {
var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]); var visual = Glx.GetVisualFromFBConfig(_x11.DeferredDisplay, ptr[c]);
// We prefer 32 bit visuals // We prefer 32 bit visuals
if (_fbconfig == IntPtr.Zero || visual->depth == 32) if (_fbconfig == IntPtr.Zero || visual->depth == 32)
{ {
@ -71,17 +71,17 @@ namespace Avalonia.X11.Glx
if (_visual == null) if (_visual == null)
throw new OpenGlException("Unable to get visual info from FBConfig"); throw new OpenGlException("Unable to get visual info from FBConfig");
if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0) if (Glx.GetFBConfigAttrib(_x11.DeferredDisplay, _fbconfig, GLX_SAMPLES, out var samples) == 0)
sampleCount = samples; sampleCount = samples;
if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0) if (Glx.GetFBConfigAttrib(_x11.DeferredDisplay, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
stencilSize = stencil; stencilSize = stencil;
var attributes = new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 }; var attributes = new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes); Glx.CreatePbuffer(_x11.DeferredDisplay, _fbconfig, attributes);
Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes); Glx.CreatePbuffer(_x11.DeferredDisplay, _fbconfig, attributes);
XLib.XFlush(_x11.Display); XLib.XFlush(_x11.DeferredDisplay);
DeferredContext = CreateContext(CreatePBuffer(), null, DeferredContext = CreateContext(CreatePBuffer(), null,
sampleCount, stencilSize, true); sampleCount, stencilSize, true);
@ -108,7 +108,7 @@ namespace Avalonia.X11.Glx
private IntPtr CreatePBuffer() private IntPtr CreatePBuffer()
{ {
return Glx.CreatePbuffer(_x11.Display, _fbconfig, new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 }); return Glx.CreatePbuffer(_x11.DeferredDisplay, _fbconfig, new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 });
} }
public GlxContext CreateContext() => CreateContext(CreatePBuffer(), null, DeferredContext.SampleCount, public GlxContext CreateContext() => CreateContext(CreatePBuffer(), null, DeferredContext.SampleCount,
@ -139,7 +139,7 @@ namespace Avalonia.X11.Glx
try try
{ {
handle = Glx.CreateContextAttribsARB(_x11.Display, _fbconfig, sharelist, true, attrs); handle = Glx.CreateContextAttribsARB(_x11.DeferredDisplay, _fbconfig, sharelist, true, attrs);
if (handle != IntPtr.Zero) if (handle != IntPtr.Zero)
{ {
_version = profile; _version = profile;
@ -181,6 +181,6 @@ namespace Avalonia.X11.Glx
throw new OpenGlException("Unable to create direct GLX context"); throw new OpenGlException("Unable to create direct GLX context");
} }
public void SwapBuffers(IntPtr xid) => Glx.SwapBuffers(_x11.Display, xid); public void SwapBuffers(IntPtr xid) => Glx.SwapBuffers(_x11.DeferredDisplay, xid);
} }
} }

2
src/Avalonia.X11/X11Window.cs

@ -183,7 +183,7 @@ namespace Avalonia.X11
surfaces.Insert(0, surfaces.Insert(0,
new EglGlPlatformSurface(new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle))); new EglGlPlatformSurface(new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
if (glx != null) if (glx != null)
surfaces.Insert(0, new GlxGlPlatformSurface(new SurfaceInfo(this, _x11.Display, _handle, _renderHandle))); surfaces.Insert(0, new GlxGlPlatformSurface(new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
surfaces.Add(Handle); surfaces.Add(Handle);

Loading…
Cancel
Save