зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1877341 - Reset GLContext TLS current-context caching when calling library MakeCurrent symbols. r=gfx-reviewers,ahale
Differential Revision: https://phabricator.services.mozilla.com/D199947
This commit is contained in:
Родитель
7b399b5dab
Коммит
12fa277cdd
|
@ -2401,6 +2401,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;
|
||||
|
||||
|
|
|
@ -187,6 +187,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;
|
||||
|
|
|
@ -86,6 +86,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".
|
||||
|
|
|
@ -92,6 +92,8 @@ bool GLContextEAGL::RecreateRB() {
|
|||
|
||||
bool GLContextEAGL::MakeCurrentImpl() const {
|
||||
if (mContext) {
|
||||
GLContext::ResetTLSCurrentContext();
|
||||
|
||||
if (![EAGLContext setCurrentContext:mContext]) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1219,7 +1219,6 @@ RefPtr<GLContextEGL> GLContextEGL::CreateWithoutSurface(
|
|||
/*static*/
|
||||
void GLContextEGL::DestroySurface(EglDisplay& aEgl, const EGLSurface aSurface) {
|
||||
if (aSurface != EGL_NO_SURFACE) {
|
||||
// TODO: This breaks TLS MakeCurrent caching.
|
||||
if (!aEgl.fMakeCurrent(EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
|
||||
const EGLint err = aEgl.mLib->fGetError();
|
||||
gfxCriticalNote << "Error in eglMakeCurrent: " << gfx::hexa(err);
|
||||
|
|
|
@ -163,12 +163,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();
|
||||
|
||||
|
@ -302,6 +306,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;
|
||||
|
|
|
@ -266,7 +266,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();
|
||||
|
||||
|
@ -289,6 +288,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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче