Release Surface when calling makeCurrent with null.
Refactorings to egl::Surface to enable ref-counting were causing
a situation where we could have two Window surfaces alive at the
same time. This would confuse the window procedure logic in
SurfaceD3D. Releasing the surface fixes this issue and conforms
closely to the wording on the spec on when Surfaces should be
deleted. Also add a test for message loops and surfaces.
BUG=475085
BUG=angleproject:963
Change-Id: Icdee3a7db97c9b54d779dabf1e1f82a89fefc546
Reviewed-on: https://chromium-review.googlesource.com/265064
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index 16a7d65..6915706 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -174,6 +174,8 @@
void Context::makeCurrent(egl::Surface *surface)
{
+ ASSERT(surface != nullptr);
+
if (!mHasBeenCurrent)
{
initRendererString();
@@ -187,12 +189,16 @@
// TODO(jmadill): do not allocate new pointers here
Framebuffer *framebufferZero = new DefaultFramebuffer(mCaps, mRenderer, surface);
-
setFramebufferZero(framebufferZero);
-
mRenderBuffer = surface->getRenderBuffer();
}
+void Context::releaseSurface()
+{
+ setFramebufferZero(nullptr);
+ mRenderBuffer = EGL_NONE;
+}
+
// NOTE: this function should not assume that this context is current!
void Context::markContextLost()
{
@@ -666,17 +672,19 @@
// First, check to see if the old default framebuffer
// was set for draw or read framebuffer, and change
// the bindings to point to the new one before deleting it.
- if (mState.getDrawFramebuffer()->id() == 0)
+ if (mState.getDrawFramebuffer() == nullptr ||
+ mState.getDrawFramebuffer()->id() == 0)
{
mState.setDrawFramebufferBinding(buffer);
}
- if (mState.getReadFramebuffer()->id() == 0)
+ if (mState.getReadFramebuffer() == nullptr ||
+ mState.getReadFramebuffer()->id() == 0)
{
mState.setReadFramebufferBinding(buffer);
}
- delete mFramebufferMap[0];
+ SafeDelete(mFramebufferMap[0]);
mFramebufferMap[0] = buffer;
}
@@ -884,7 +892,7 @@
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
- // Indexed integer queries all refer to current state, so this function is a
+ // Indexed integer queries all refer to current state, so this function is a
// mere passthrough.
return mState.getIndexedIntegerv(target, index, data);
}
@@ -893,7 +901,7 @@
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
- // Indexed integer queries all refer to current state, so this function is a
+ // Indexed integer queries all refer to current state, so this function is a
// mere passthrough.
return mState.getIndexedInteger64v(target, index, data);
}
@@ -1321,7 +1329,7 @@
void Context::detachBuffer(GLuint buffer)
{
- // Buffer detachment is handled by Context, because the buffer must also be
+ // Buffer detachment is handled by Context, because the buffer must also be
// attached from any VAOs in existence, and Context holds the VAO map.
// [OpenGL ES 2.0.24] section 2.9 page 22:
@@ -1365,8 +1373,8 @@
void Context::detachVertexArray(GLuint vertexArray)
{
- // Vertex array detachment is handled by Context, because 0 is a valid
- // VAO, and a pointer to it must be passed from Context to State at
+ // Vertex array detachment is handled by Context, because 0 is a valid
+ // VAO, and a pointer to it must be passed from Context to State at
// binding time.
// [OpenGL ES 3.0.2] section 2.10 page 43: