Commit 5635dbb9 by Peng Huang Committed by Commit Bot

Only call context::unMakeCurrent() if context is changed.

Bug: angleproject:5509 Change-Id: Ifbc6aa23a218498c5e2f6a094296045b2d5dfacf Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2633421 Commit-Queue: Peng Huang <penghuang@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent b5424bb4
...@@ -575,7 +575,10 @@ egl::Error Context::onDestroy(const egl::Display *display) ...@@ -575,7 +575,10 @@ egl::Error Context::onDestroy(const egl::Display *display)
mGLES1Renderer->onDestroy(this, &mState); mGLES1Renderer->onDestroy(this, &mState);
} }
ANGLE_TRY(unMakeCurrent(display)); if (mIsCurrent)
{
ANGLE_TRY(unMakeCurrent(display));
}
for (auto fence : mFenceNVMap) for (auto fence : mFenceNVMap)
{ {
...@@ -691,6 +694,11 @@ egl::Error Context::makeCurrent(egl::Display *display, ...@@ -691,6 +694,11 @@ egl::Error Context::makeCurrent(egl::Display *display,
mHasBeenCurrent = true; mHasBeenCurrent = true;
} }
if (mIsCurrent)
{
ANGLE_TRY(unsetDefaultFramebuffer());
}
mFrameCapture->onMakeCurrent(this, drawSurface); mFrameCapture->onMakeCurrent(this, drawSurface);
// TODO(jmadill): Rework this when we support ContextImpl // TODO(jmadill): Rework this when we support ContextImpl
...@@ -709,11 +717,15 @@ egl::Error Context::makeCurrent(egl::Display *display, ...@@ -709,11 +717,15 @@ egl::Error Context::makeCurrent(egl::Display *display,
return angle::ResultToEGL(implResult); return angle::ResultToEGL(implResult);
} }
mIsCurrent = true;
return egl::NoError(); return egl::NoError();
} }
egl::Error Context::unMakeCurrent(const egl::Display *display) egl::Error Context::unMakeCurrent(const egl::Display *display)
{ {
ASSERT(mIsCurrent);
ANGLE_TRY(angle::ResultToEGL(mImplementation->onUnMakeCurrent(this))); ANGLE_TRY(angle::ResultToEGL(mImplementation->onUnMakeCurrent(this)));
ANGLE_TRY(unsetDefaultFramebuffer()); ANGLE_TRY(unsetDefaultFramebuffer());
...@@ -729,6 +741,8 @@ egl::Error Context::unMakeCurrent(const egl::Display *display) ...@@ -729,6 +741,8 @@ egl::Error Context::unMakeCurrent(const egl::Display *display)
mDisplay->returnZeroFilledBuffer(mZeroFilledBuffer.release()); mDisplay->returnZeroFilledBuffer(mZeroFilledBuffer.release());
} }
mIsCurrent = false;
return egl::NoError(); return egl::NoError();
} }
......
...@@ -771,6 +771,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl ...@@ -771,6 +771,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
mutable size_t mRefCount; mutable size_t mRefCount;
OverlayType mOverlay; OverlayType mOverlay;
bool mIsCurrent = false;
}; };
// Thread-local current valid context bound to the thread. // Thread-local current valid context bound to the thread.
......
...@@ -1282,14 +1282,11 @@ Error Display::makeCurrent(gl::Context *previousContext, ...@@ -1282,14 +1282,11 @@ Error Display::makeCurrent(gl::Context *previousContext,
// If the context is changing we need to update the reference counts. If it's not, e.g. just // If the context is changing we need to update the reference counts. If it's not, e.g. just
// changing the surfaces leave the reference count alone. Otherwise the reference count might go // changing the surfaces leave the reference count alone. Otherwise the reference count might go
// to zero even though we know we are not done with the context. // to zero even though we know we are not done with the context.
bool updateRefCount = context != previousContext; bool contextChanged = context != previousContext;
if (previousContext != nullptr) if (previousContext != nullptr && contextChanged)
{ {
ANGLE_TRY(previousContext->unMakeCurrent(this)); ANGLE_TRY(previousContext->unMakeCurrent(this));
if (updateRefCount) ANGLE_TRY(releaseContext(previousContext));
{
ANGLE_TRY(releaseContext(previousContext));
}
} }
ANGLE_TRY(mImplementation->makeCurrent(this, drawSurface, readSurface, context)); ANGLE_TRY(mImplementation->makeCurrent(this, drawSurface, readSurface, context));
...@@ -1297,7 +1294,7 @@ Error Display::makeCurrent(gl::Context *previousContext, ...@@ -1297,7 +1294,7 @@ Error Display::makeCurrent(gl::Context *previousContext,
if (context != nullptr) if (context != nullptr)
{ {
ANGLE_TRY(context->makeCurrent(this, drawSurface, readSurface)); ANGLE_TRY(context->makeCurrent(this, drawSurface, readSurface));
if (updateRefCount) if (contextChanged)
{ {
context->addRef(); context->addRef();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment