summaryrefslogtreecommitdiffstats
path: root/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/GLContext.cpp6
-rw-r--r--gfx/gl/GLContext.h2
-rw-r--r--gfx/gl/GLContextProviderCGL.mm2
-rw-r--r--gfx/gl/GLContextProviderEAGL.mm2
-rw-r--r--gfx/gl/GLContextProviderWGL.cpp10
-rw-r--r--gfx/gl/GLLibraryEGL.h8
-rw-r--r--gfx/gl/GLXLibrary.h3
7 files changed, 28 insertions, 5 deletions
diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp
index f67aedd0b2..d11c131c45 100644
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -2432,6 +2432,12 @@ uint32_t GetBytesPerTexel(GLenum format, GLenum type) {
return 0;
}
+void GLContext::ResetTLSCurrentContext() {
+ if (sCurrentContext.init()) {
+ sCurrentContext.set(nullptr);
+ }
+}
+
bool GLContext::MakeCurrent(bool aForce) const {
if (MOZ_UNLIKELY(IsContextLost())) return false;
diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h
index d88b96019f..41dbe92bee 100644
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -185,6 +185,8 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
bool mImplicitMakeCurrent = false;
bool mUseTLSIsCurrent;
+ static void ResetTLSCurrentContext();
+
class TlsScope final {
const WeakPtr<GLContext> mGL;
const bool mWasTlsOk;
diff --git a/gfx/gl/GLContextProviderCGL.mm b/gfx/gl/GLContextProviderCGL.mm
index 1b4049de3e..a01701f571 100644
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -84,6 +84,8 @@ CGLContextObj GLContextCGL::GetCGLContext() const {
bool GLContextCGL::MakeCurrentImpl() const {
if (mContext) {
+ GLContext::ResetTLSCurrentContext();
+
[mContext makeCurrentContext];
MOZ_ASSERT(IsCurrentImpl());
// Use non-blocking swap in "ASAP mode".
diff --git a/gfx/gl/GLContextProviderEAGL.mm b/gfx/gl/GLContextProviderEAGL.mm
index 4aabe89df1..b90adaacf3 100644
--- a/gfx/gl/GLContextProviderEAGL.mm
+++ b/gfx/gl/GLContextProviderEAGL.mm
@@ -90,6 +90,8 @@ bool GLContextEAGL::RecreateRB() {
bool GLContextEAGL::MakeCurrentImpl() const {
if (mContext) {
+ GLContext::ResetTLSCurrentContext();
+
if (![EAGLContext setCurrentContext:mContext]) {
return false;
}
diff --git a/gfx/gl/GLContextProviderWGL.cpp b/gfx/gl/GLContextProviderWGL.cpp
index 2720cab14e..5d90ee5169 100644
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -158,12 +158,16 @@ bool WGLLibrary::EnsureInitialized() {
const auto curCtx = mSymbols.fGetCurrentContext();
const auto curDC = mSymbols.fGetCurrentDC();
+ GLContext::ResetTLSCurrentContext();
+
if (!mSymbols.fMakeCurrent(mRootDc, mDummyGlrc)) {
NS_WARNING("wglMakeCurrent failed");
return false;
}
- const auto resetContext =
- MakeScopeExit([&]() { mSymbols.fMakeCurrent(curDC, curCtx); });
+ const auto resetContext = MakeScopeExit([&]() {
+ GLContext::ResetTLSCurrentContext();
+ mSymbols.fMakeCurrent(curDC, curCtx);
+ });
const auto loader = GetSymbolLoader();
@@ -297,6 +301,8 @@ GLContextWGL::~GLContextWGL() {
}
bool GLContextWGL::MakeCurrentImpl() const {
+ GLContext::ResetTLSCurrentContext();
+
const bool succeeded = sWGLLib.mSymbols.fMakeCurrent(mDC, mContext);
NS_ASSERTION(succeeded, "Failed to make GL context current!");
return succeeded;
diff --git a/gfx/gl/GLLibraryEGL.h b/gfx/gl/GLLibraryEGL.h
index 28f84b27f4..0a853e67c9 100644
--- a/gfx/gl/GLLibraryEGL.h
+++ b/gfx/gl/GLLibraryEGL.h
@@ -11,7 +11,7 @@
#include "base/platform_thread.h" // for PlatformThreadId
#include "gfxEnv.h"
-#include "GLTypes.h"
+#include "GLContext.h"
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/Maybe.h"
@@ -264,7 +264,6 @@ class GLLibraryEGL final {
const bool CHECK_CONTEXT_OWNERSHIP = true;
if (CHECK_CONTEXT_OWNERSHIP) {
const MutexAutoLock lock(mMutex);
-
const auto tid = PlatformThread::CurrentId();
const auto prevCtx = fGetCurrentContext();
@@ -287,6 +286,11 @@ class GLLibraryEGL final {
}
}
+ // Always reset the TLS current context.
+ // If we're called by TLS-caching MakeCurrent, after we return true,
+ // the caller will set the TLS correctly anyway.
+ GLContext::ResetTLSCurrentContext();
+
WRAP(fMakeCurrent(dpy, draw, read, ctx));
}
diff --git a/gfx/gl/GLXLibrary.h b/gfx/gl/GLXLibrary.h
index 7a004762ff..d2577c935c 100644
--- a/gfx/gl/GLXLibrary.h
+++ b/gfx/gl/GLXLibrary.h
@@ -6,7 +6,7 @@
#ifndef GFX_GLXLIBRARY_H
#define GFX_GLXLIBRARY_H
-#include "GLContextTypes.h"
+#include "GLContext.h"
#include "mozilla/Assertions.h"
#include "mozilla/DataMutex.h"
#include "mozilla/gfx/XlibDisplay.h"
@@ -65,6 +65,7 @@ class GLXLibrary final {
Bool fMakeCurrent(Display* display, GLXDrawable drawable,
GLXContext context) const {
DECL_WRAPPER_SCOPE(display)
+ GLContext::ResetTLSCurrentContext();
return mSymbols.fMakeCurrent(display, drawable, context);
}