Browse Source

Use DeferredDisplay for GLX

pull/10888/head
Nikita Tsukanov 3 years ago
parent
commit
5c3ce86e51
  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;
try
{
var old = new RestoreContext(Glx, _x11.Display, _lock);
if (!Glx.MakeContextCurrent(_x11.Display, xid, xid, Handle))
var old = new RestoreContext(Glx, _x11.DeferredDisplay, _lock);
if (!Glx.MakeContextCurrent(_x11.DeferredDisplay, xid, xid, Handle))
throw new OpenGlException("glXMakeContextCurrent failed ");
success = true;
@ -124,9 +124,9 @@ namespace Avalonia.X11.Glx
public void Dispose()
{
Glx.DestroyContext(_x11.Display, Handle);
Glx.DestroyContext(_x11.DeferredDisplay, Handle);
if (_ownsPBuffer)
Glx.DestroyPbuffer(_x11.Display, _defaultXid);
Glx.DestroyPbuffer(_x11.DeferredDisplay, _defaultXid);
}
public object TryGetFeature(Type featureType)

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

@ -22,7 +22,7 @@ namespace Avalonia.X11.Glx
{
_x11 = x11;
_probeProfiles = probeProfiles.ToArray();
_displayExtensions = Glx.GetExtensions(_x11.Display);
_displayExtensions = Glx.GetExtensions(_x11.DeferredDisplay);
var baseAttribs = new[]
{
@ -46,12 +46,12 @@ namespace Avalonia.X11.Glx
baseAttribs,
})
{
var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
var ptr = Glx.ChooseFBConfig(_x11.DeferredDisplay, x11.DefaultScreen,
attribs, out var count);
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
if (_fbconfig == IntPtr.Zero || visual->depth == 32)
{
@ -71,17 +71,17 @@ namespace Avalonia.X11.Glx
if (_visual == null)
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;
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;
var attributes = new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);
Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);
Glx.CreatePbuffer(_x11.DeferredDisplay, _fbconfig, attributes);
Glx.CreatePbuffer(_x11.DeferredDisplay, _fbconfig, attributes);
XLib.XFlush(_x11.Display);
XLib.XFlush(_x11.DeferredDisplay);
DeferredContext = CreateContext(CreatePBuffer(), null,
sampleCount, stencilSize, true);
@ -108,7 +108,7 @@ namespace Avalonia.X11.Glx
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,
@ -139,7 +139,7 @@ namespace Avalonia.X11.Glx
try
{
handle = Glx.CreateContextAttribsARB(_x11.Display, _fbconfig, sharelist, true, attrs);
handle = Glx.CreateContextAttribsARB(_x11.DeferredDisplay, _fbconfig, sharelist, true, attrs);
if (handle != IntPtr.Zero)
{
_version = profile;
@ -181,6 +181,6 @@ namespace Avalonia.X11.Glx
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,
new EglGlPlatformSurface(new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
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);

Loading…
Cancel
Save