From 5c3ce86e51e411d71d97dbf3df824c3c12d14838 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Mon, 3 Apr 2023 11:23:08 +0600 Subject: [PATCH] Use DeferredDisplay for GLX --- src/Avalonia.X11/Glx/GlxContext.cs | 8 ++++---- src/Avalonia.X11/Glx/GlxDisplay.cs | 22 +++++++++++----------- src/Avalonia.X11/X11Window.cs | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Avalonia.X11/Glx/GlxContext.cs b/src/Avalonia.X11/Glx/GlxContext.cs index b1cb330b00..035354f337 100644 --- a/src/Avalonia.X11/Glx/GlxContext.cs +++ b/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) diff --git a/src/Avalonia.X11/Glx/GlxDisplay.cs b/src/Avalonia.X11/Glx/GlxDisplay.cs index 7749749eaa..9bcd8f3763 100644 --- a/src/Avalonia.X11/Glx/GlxDisplay.cs +++ b/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); } } diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 8bd84215ed..07561bcf05 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/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);