DisplayWGL: Allow MakeCurrent(null).
Previously we would ignore unsetting calls to MakeCurrent. But this
would prevent ANGLE from unsetting driver state on the current thread.
Fix this by checking for 0/null explicitly in DisplayWGL::makeCurrent.
This turned up when running test configs without recreating the
Display.
Bug: angleproject:3261
Change-Id: I7f747dc7649a06f019f1b89655cb71dd3b151aa0
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1520992
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/renderer/gl/wgl/DisplayWGL.cpp b/src/libANGLE/renderer/gl/wgl/DisplayWGL.cpp
index 2a41387..e6bdc22 100644
--- a/src/libANGLE/renderer/gl/wgl/DisplayWGL.cpp
+++ b/src/libANGLE/renderer/gl/wgl/DisplayWGL.cpp
@@ -641,13 +641,7 @@
return egl::EglNotInitialized() << "Could not create D3D11 device, " << gl::FmtHR(result);
}
- egl::Error error = registerD3DDevice(mD3D11Device, &mD3D11DeviceHandle);
- if (error.isError())
- {
- return error;
- }
-
- return egl::NoError();
+ return registerD3DDevice(mD3D11Device, &mD3D11DeviceHandle);
}
void DisplayWGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
@@ -709,6 +703,10 @@
SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface);
newDC = drawSurfaceWGL->getDC();
}
+ else
+ {
+ newDC = mDeviceContext;
+ }
HGLRC newContext = currentContext.glrc;
if (context)
@@ -716,9 +714,15 @@
ContextWGL *contextWGL = GetImplAs<ContextWGL>(context);
newContext = contextWGL->getContext();
}
+ else
+ {
+ newContext = 0;
+ }
if (newDC != currentContext.dc || newContext != currentContext.glrc)
{
+ ASSERT(newDC != 0);
+
if (!mFunctionsWGL->makeCurrent(newDC, newContext))
{
// TODO(geofflang): What error type here?
diff --git a/src/tests/egl_tests/EGLQueryContextTest.cpp b/src/tests/egl_tests/EGLQueryContextTest.cpp
index 601ab84..4d2099f 100644
--- a/src/tests/egl_tests/EGLQueryContextTest.cpp
+++ b/src/tests/egl_tests/EGLQueryContextTest.cpp
@@ -51,10 +51,14 @@
void TearDown() override
{
- eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglDestroyContext(mDisplay, mContext);
- eglDestroySurface(mDisplay, mSurface);
- eglTerminate(mDisplay);
+ if (mDisplay != EGL_NO_DISPLAY)
+ {
+ eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroyContext(mDisplay, mContext);
+ eglDestroySurface(mDisplay, mSurface);
+ eglTerminate(mDisplay);
+ }
+ ASSERT_EGL_SUCCESS() << "Error during test TearDown";
}
EGLDisplay mDisplay;
@@ -102,6 +106,7 @@
EXPECT_TRUE(eglQueryContext(mDisplay, mContext, EGL_RENDER_BUFFER, &contextRenderBuffer) !=
EGL_FALSE);
EXPECT_TRUE(renderBuffer == contextRenderBuffer);
+ ASSERT_EGL_SUCCESS();
}
TEST_P(EGLQueryContextTest, BadDisplay)