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-12 07:35:02 +00:00
parent cf3beedd47
commit 07a5849be8
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,
@ -2401,7 +2408,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

@ -180,6 +180,8 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
public:
static MOZ_THREAD_LOCAL(const GLContext*) sCurrentContext;
static void InvalidateCurrentContext();
const GLContextDesc mDesc;
bool mImplicitMakeCurrent = false;
@ -190,9 +192,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;
}
}