mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 17:24:29 +00:00
Bug 1390386 - Remove duplicate IsCurrent checks in MakeCurrentImpls. - r=jrmuizel
MozReview-Commit-ID: LZeLbciWnic
This commit is contained in:
parent
fbf8b4797b
commit
ea479cbf60
@ -3031,18 +3031,25 @@ GLContext::MakeCurrent(bool aForce) const
|
||||
if (MOZ_UNLIKELY( IsDestroyed() ))
|
||||
return false;
|
||||
|
||||
if (mUseTLSIsCurrent && !aForce && sCurrentContext.get() == this) {
|
||||
MOZ_ASSERT(IsCurrent());
|
||||
return true;
|
||||
if (MOZ_LIKELY( !aForce )) {
|
||||
bool isCurrent;
|
||||
if (mUseTLSIsCurrent) {
|
||||
isCurrent = (sCurrentContext.get() == this);
|
||||
} else {
|
||||
isCurrent = IsCurrentImpl();
|
||||
}
|
||||
if (MOZ_LIKELY( isCurrent )) {
|
||||
MOZ_ASSERT(IsCurrentImpl());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MakeCurrentImpl(aForce))
|
||||
if (!MakeCurrentImpl())
|
||||
return false;
|
||||
|
||||
if (mUseTLSIsCurrent) {
|
||||
sCurrentContext.set(this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -298,6 +298,9 @@ public:
|
||||
|
||||
virtual GLContextType GetContextType() const = 0;
|
||||
|
||||
virtual bool IsCurrentImpl() const = 0;
|
||||
virtual bool MakeCurrentImpl() const = 0;
|
||||
|
||||
bool IsCurrent() const {
|
||||
if (mImplicitMakeCurrent)
|
||||
return MakeCurrent();
|
||||
@ -305,7 +308,7 @@ public:
|
||||
return IsCurrentImpl();
|
||||
}
|
||||
|
||||
virtual bool IsCurrentImpl() const = 0;
|
||||
bool MakeCurrent(bool aForce = false) const;
|
||||
|
||||
/**
|
||||
* Get the default framebuffer for this context.
|
||||
@ -680,7 +683,7 @@ private:
|
||||
|
||||
#define BEFORE_GL_CALL \
|
||||
ANDROID_ONLY_PROFILER_LABEL \
|
||||
if (BeforeGLCall(MOZ_FUNCTION_NAME)) { \
|
||||
if (MOZ_LIKELY( BeforeGLCall(MOZ_FUNCTION_NAME) )) { \
|
||||
do { } while (0)
|
||||
|
||||
#define AFTER_GL_CALL \
|
||||
@ -699,7 +702,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MOZ_ASSERT(IsCurrent());
|
||||
MOZ_ASSERT(IsCurrentImpl());
|
||||
|
||||
if (mDebugFlags) {
|
||||
BeforeGLCall_Debug(funcName);
|
||||
@ -3316,11 +3319,7 @@ public:
|
||||
protected:
|
||||
typedef gfx::SurfaceFormat SurfaceFormat;
|
||||
|
||||
virtual bool MakeCurrentImpl(bool aForce) const = 0;
|
||||
|
||||
public:
|
||||
bool MakeCurrent(bool aForce = false) const;
|
||||
|
||||
virtual bool Init() = 0;
|
||||
|
||||
virtual bool SetupLookupFunction() = 0;
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
NSOpenGLContext* GetNSOpenGLContext() const { return mContext; }
|
||||
CGLContextObj GetCGLContext() const;
|
||||
|
||||
virtual bool MakeCurrentImpl(bool aForce) const override;
|
||||
virtual bool MakeCurrentImpl() const override;
|
||||
|
||||
virtual bool IsCurrentImpl() const override;
|
||||
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
|
||||
EAGLContext* GetEAGLContext() const { return mContext; }
|
||||
|
||||
virtual bool MakeCurrentImpl(bool aForce) const override;
|
||||
virtual bool MakeCurrentImpl() const override;
|
||||
|
||||
virtual bool IsCurrentImpl() const override;
|
||||
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
return mSurfaceOverride;
|
||||
}
|
||||
|
||||
virtual bool MakeCurrentImpl(bool aForce) const override;
|
||||
virtual bool MakeCurrentImpl() const override;
|
||||
|
||||
virtual bool IsCurrentImpl() const override;
|
||||
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
|
||||
bool Init() override;
|
||||
|
||||
virtual bool MakeCurrentImpl(bool aForce) const override;
|
||||
virtual bool MakeCurrentImpl() const override;
|
||||
|
||||
virtual bool IsCurrentImpl() const override;
|
||||
|
||||
|
@ -110,15 +110,11 @@ GLContextCGL::GetCGLContext() const
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextCGL::MakeCurrentImpl(bool aForce) const
|
||||
GLContextCGL::MakeCurrentImpl() const
|
||||
{
|
||||
if (!aForce && [NSOpenGLContext currentContext] == mContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mContext) {
|
||||
[mContext makeCurrentContext];
|
||||
MOZ_ASSERT(IsCurrent());
|
||||
MOZ_ASSERT(IsCurrentImpl());
|
||||
// Use non-blocking swap in "ASAP mode".
|
||||
// ASAP mode means that rendering is iterated as fast as possible.
|
||||
// ASAP mode is entered when layout.frame_rate=0 (requires restart).
|
||||
|
@ -113,12 +113,8 @@ GLContextEAGL::RecreateRB()
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextEAGL::MakeCurrentImpl(bool aForce) const
|
||||
GLContextEAGL::MakeCurrentImpl() const
|
||||
{
|
||||
if (!aForce && [EAGLContext currentContext] == mContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mContext) {
|
||||
if(![EAGLContext setCurrentContext:mContext]) {
|
||||
return false;
|
||||
|
@ -356,35 +356,27 @@ GLContextEGL::SetEGLSurfaceOverride(EGLSurface surf) {
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextEGL::MakeCurrentImpl(bool aForce) const
|
||||
GLContextEGL::MakeCurrentImpl() const
|
||||
{
|
||||
bool succeeded = true;
|
||||
const EGLSurface surface = (mSurfaceOverride != EGL_NO_SURFACE) ? mSurfaceOverride
|
||||
: mSurface;
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
MOZ_CRASH("EGL_NO_SURFACE");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assume that EGL has the same problem as WGL does,
|
||||
// where MakeCurrent with an already-current context is
|
||||
// still expensive.
|
||||
bool needsMakeCurrent = (aForce || sEGLLibrary.fGetCurrentContext() != mContext);
|
||||
if (needsMakeCurrent) {
|
||||
EGLSurface surface = mSurfaceOverride != EGL_NO_SURFACE
|
||||
? mSurfaceOverride
|
||||
: mSurface;
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
return false;
|
||||
}
|
||||
succeeded = sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
|
||||
surface, surface,
|
||||
mContext);
|
||||
if (!succeeded) {
|
||||
int eglError = sEGLLibrary.fGetError();
|
||||
if (eglError == LOCAL_EGL_CONTEXT_LOST) {
|
||||
mContextLost = true;
|
||||
NS_WARNING("EGL context has been lost.");
|
||||
} else {
|
||||
NS_WARNING("Failed to make GL context current!");
|
||||
const bool succeeded = sEGLLibrary.fMakeCurrent(EGL_DISPLAY(), surface, surface,
|
||||
mContext);
|
||||
if (!succeeded) {
|
||||
const auto eglError = sEGLLibrary.fGetError();
|
||||
if (eglError == LOCAL_EGL_CONTEXT_LOST) {
|
||||
mContextLost = true;
|
||||
NS_WARNING("EGL context has been lost.");
|
||||
} else {
|
||||
NS_WARNING("Failed to make GL context current!");
|
||||
#ifdef DEBUG
|
||||
printf_stderr("EGL Error: 0x%04x\n", eglError);
|
||||
printf_stderr("EGL Error: 0x%04x\n", eglError);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -606,35 +606,24 @@ GLContextGLX::Init()
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextGLX::MakeCurrentImpl(bool aForce) const
|
||||
GLContextGLX::MakeCurrentImpl() const
|
||||
{
|
||||
bool succeeded = true;
|
||||
|
||||
// With the ATI FGLRX driver, glxMakeCurrent is very slow even when the context doesn't change.
|
||||
// (This is not the case with other drivers such as NVIDIA).
|
||||
// So avoid calling it more than necessary. Since GLX documentation says that:
|
||||
// "glXGetCurrentContext returns client-side information.
|
||||
// It does not make a round trip to the server."
|
||||
// I assume that it's not worth using our own TLS slot here.
|
||||
if (aForce || mGLX->fGetCurrentContext() != mContext) {
|
||||
if (mGLX->IsMesa()) {
|
||||
// Read into the event queue to ensure that Mesa receives a
|
||||
// DRI2InvalidateBuffers event before drawing. See bug 1280653.
|
||||
Unused << XPending(mDisplay);
|
||||
}
|
||||
|
||||
succeeded = mGLX->fMakeCurrent(mDisplay, mDrawable, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
|
||||
if (!IsOffscreen() && mGLX->SupportsSwapControl()) {
|
||||
// Many GLX implementations default to blocking until the next
|
||||
// VBlank when calling glXSwapBuffers. We want to run unthrottled
|
||||
// in ASAP mode. See bug 1280744.
|
||||
const bool isASAP = (gfxPrefs::LayoutFrameRate() == 0);
|
||||
mGLX->fSwapInterval(mDisplay, mDrawable, isASAP ? 0 : 1);
|
||||
}
|
||||
if (mGLX->IsMesa()) {
|
||||
// Read into the event queue to ensure that Mesa receives a
|
||||
// DRI2InvalidateBuffers event before drawing. See bug 1280653.
|
||||
Unused << XPending(mDisplay);
|
||||
}
|
||||
|
||||
const bool succeeded = mGLX->fMakeCurrent(mDisplay, mDrawable, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
|
||||
if (!IsOffscreen() && mGLX->SupportsSwapControl()) {
|
||||
// Many GLX implementations default to blocking until the next
|
||||
// VBlank when calling glXSwapBuffers. We want to run unthrottled
|
||||
// in ASAP mode. See bug 1280744.
|
||||
const bool isASAP = (gfxPrefs::LayoutFrameRate() == 0);
|
||||
mGLX->fSwapInterval(mDisplay, mDrawable, isASAP ? 0 : 1);
|
||||
}
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
|
@ -323,19 +323,10 @@ GLContextWGL::Init()
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextWGL::MakeCurrentImpl(bool aForce) const
|
||||
GLContextWGL::MakeCurrentImpl() const
|
||||
{
|
||||
BOOL succeeded = true;
|
||||
|
||||
// wglGetCurrentContext seems to just pull the HGLRC out
|
||||
// of its TLS slot, so no need to do our own tls slot.
|
||||
// You would think that wglMakeCurrent would avoid doing
|
||||
// work if mContext was already current, but not so much..
|
||||
if (aForce || sWGLLib.mSymbols.fGetCurrentContext() != mContext) {
|
||||
succeeded = sWGLLib.mSymbols.fMakeCurrent(mDC, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
}
|
||||
|
||||
const bool succeeded = sWGLLib.mSymbols.fMakeCurrent(mDC, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
|
||||
bool Init() override;
|
||||
|
||||
virtual bool MakeCurrentImpl(bool aForce) const override;
|
||||
virtual bool MakeCurrentImpl() const override;
|
||||
|
||||
virtual bool IsCurrentImpl() const override;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user