From 67563520fff5a23956d091770eb6ad41da8a212a Mon Sep 17 00:00:00 2001 From: Shane Kelly Date: Sat, 9 Dec 2017 09:39:44 +0200 Subject: [PATCH 1/2] Stop using DisplayLocks for every MakeCurrent context call. --- src/OpenTK/Platform/X11/X11GLContext.cs | 28 +++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/OpenTK/Platform/X11/X11GLContext.cs b/src/OpenTK/Platform/X11/X11GLContext.cs index f661ee4d..e0763fa1 100644 --- a/src/OpenTK/Platform/X11/X11GLContext.cs +++ b/src/OpenTK/Platform/X11/X11GLContext.cs @@ -319,14 +319,12 @@ namespace OpenTK.Platform.X11 Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display)); bool result; - using (new XLock(Display)) + result = Glx.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero); + if (result) { - result = Glx.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero); - if (result) - { - currentWindow = null; - } + currentWindow = null; } + Debug.Print("{0}", result ? "done!" : "failed."); } else @@ -342,15 +340,16 @@ namespace OpenTK.Platform.X11 throw new InvalidOperationException("Invalid display, window or context."); } - using (new XLock(Display)) + result = Glx.MakeCurrent(Display, w.Handle, Handle); + if (result) { - result = Glx.MakeCurrent(Display, w.Handle, Handle); - if (result) - { - currentWindow = w; - } + currentWindow = w; } + + + + if (!result) { throw new GraphicsContextException("Failed to make context current."); @@ -488,10 +487,7 @@ namespace OpenTK.Platform.X11 if (IsCurrent) { - using (new XLock(display)) - { - Glx.MakeCurrent(display, IntPtr.Zero, IntPtr.Zero); - } + Glx.MakeCurrent(display, IntPtr.Zero, IntPtr.Zero); } using (new XLock(display)) { From e335698c07d96ea13d4d4998e6320476d26041fd Mon Sep 17 00:00:00 2001 From: Shane Kelly Date: Sat, 9 Dec 2017 12:19:41 +0200 Subject: [PATCH 2/2] Remove a lock on a read-only operation, in IsCurrent() --- src/OpenTK/Platform/X11/X11GLContext.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/OpenTK/Platform/X11/X11GLContext.cs b/src/OpenTK/Platform/X11/X11GLContext.cs index e0763fa1..24c3b91d 100644 --- a/src/OpenTK/Platform/X11/X11GLContext.cs +++ b/src/OpenTK/Platform/X11/X11GLContext.cs @@ -346,10 +346,6 @@ namespace OpenTK.Platform.X11 currentWindow = w; } - - - - if (!result) { throw new GraphicsContextException("Failed to make context current."); @@ -367,10 +363,7 @@ namespace OpenTK.Platform.X11 { get { - using (new XLock(Display)) - { - return Glx.GetCurrentContext() == Handle.Handle; - } + return Glx.GetCurrentContext() == Handle.Handle; } }