Bug 1829026 - Allow invalidating the current TLS context on establishing TLS scope. r=aosmond

On a given thread, if there are outside users of OpenGL (such as WebRender) that don't go
through the GLContext interface to set the current context, the TLS current context value
may be incorrect. To solve this, we need to assume that on establishing some TLS scopes,
that the current context value is unreliable and invalidate it so that it gets properly
reset.

Differential Revision: https://phabricator.services.mozilla.com/D194350
This commit is contained in:
Lee Salzman 2023-12-18 18:10:46 +00:00
parent f88c86a77e
commit 772134201a
2 changed files with 14 additions and 2 deletions

View File

@ -308,6 +308,13 @@ GLContext::~GLContext() {
}
}
/*static*/
void GLContext::InvalidateCurrentContext() {
if (sCurrentContext.init()) {
sCurrentContext.set(nullptr);
}
}
/*static*/
void GLContext::StaticDebugCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
@ -2406,7 +2413,7 @@ bool GLContext::MakeCurrent(bool aForce) const {
}
if (MOZ_LIKELY(isCurrent)) {
MOZ_ASSERT(IsCurrentImpl() ||
!MakeCurrentImpl()); // Might have lost context.
MakeCurrentImpl()); // Might have lost context.
return true;
}
}

View File

@ -181,6 +181,8 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
public:
static MOZ_THREAD_LOCAL(const GLContext*) sCurrentContext;
static void InvalidateCurrentContext();
const GLContextDesc mDesc;
bool mImplicitMakeCurrent = false;
@ -191,9 +193,12 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
const bool mWasTlsOk;
public:
explicit TlsScope(GLContext* const gl)
explicit TlsScope(GLContext* const gl, bool invalidate = false)
: mGL(gl), mWasTlsOk(gl && gl->mUseTLSIsCurrent) {
if (mGL) {
if (invalidate) {
InvalidateCurrentContext();
}
mGL->mUseTLSIsCurrent = true;
}
}