Add missing finish() calls to multithread and multi context tests.

Bug: 20751454
Change-Id: Ic6de190c4784bee483ca2a0e74c5b4c0899f2886
diff --git a/modules/egl/teglColorClearCase.cpp b/modules/egl/teglColorClearCase.cpp
index 6d6e73b..db38ad0 100644
--- a/modules/egl/teglColorClearCase.cpp
+++ b/modules/egl/teglColorClearCase.cpp
@@ -120,6 +120,19 @@
 	}
 }
 
+static void finish (EGLint api, const ApiFunctions& func)
+{
+	switch (api)
+	{
+		case EGL_OPENGL_ES_BIT:			gles1::finish();		break;
+		case EGL_OPENGL_ES2_BIT:		gles2::finish(func.gl);	break;
+		case EGL_OPENGL_ES3_BIT_KHR:	gles2::finish(func.gl);	break;
+		case EGL_OPENVG_BIT:			vg::finish();			break;
+		default:
+			DE_ASSERT(DE_FALSE);
+	}
+}
+
 static void readPixels (EGLint api, const ApiFunctions& func, tcu::Surface& dst)
 {
 	switch (api)
@@ -185,6 +198,7 @@
 		EGLU_CHECK_MSG(egl, "eglMakeCurrent");
 
 		renderClear(api, funcs, clear);
+		finish(api, funcs);
 		clears.push_back(clear);
 	}
 
@@ -206,6 +220,8 @@
 				renderClear(api, funcs, clear);
 				clears.push_back(clear);
 			}
+
+			finish(api, funcs);
 		}
 	}
 
@@ -286,6 +302,7 @@
 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(packetIter->clears); ndx++)
 				renderClear(m_api, m_funcs, packetIter->clears[ndx]);
 
+			finish(m_api, m_funcs);
 			// Release context.
 			m_egl.makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 
diff --git a/modules/egl/teglGLES1RenderUtil.cpp b/modules/egl/teglGLES1RenderUtil.cpp
index 5066da2..7c5d1f6 100644
--- a/modules/egl/teglGLES1RenderUtil.cpp
+++ b/modules/egl/teglGLES1RenderUtil.cpp
@@ -53,6 +53,11 @@
 	glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dst.getAccess().getDataPtr());
 }
 
+void finish (void)
+{
+	glFinish();
+}
+
 #else // DEQP_SUPPORT_GLES1
 
 void clear (int x, int y, int width, int height, const tcu::Vec4& color)
@@ -69,6 +74,11 @@
 	TCU_THROW(NotSupportedError, "OpenGL ES 1.x is not supported");
 }
 
+void finish (void)
+{
+	TCU_THROW(NotSupportedError, "OpenGL ES 1.x is not supported");
+}
+
 #endif // DEQP_SUPPORT_GLES1
 
 } // gles1
diff --git a/modules/egl/teglGLES1RenderUtil.hpp b/modules/egl/teglGLES1RenderUtil.hpp
index 3254331..2cd06ab 100644
--- a/modules/egl/teglGLES1RenderUtil.hpp
+++ b/modules/egl/teglGLES1RenderUtil.hpp
@@ -36,6 +36,7 @@
 
 void	clear		(int x, int y, int width, int height, const tcu::Vec4& color);
 void	readPixels	(tcu::Surface& dst, int x, int y, int width, int height);
+void	finish		(void);
 
 } // gles1
 } // egl
diff --git a/modules/egl/teglGLES2RenderUtil.cpp b/modules/egl/teglGLES2RenderUtil.cpp
index 9246cad..627ff09 100644
--- a/modules/egl/teglGLES2RenderUtil.cpp
+++ b/modules/egl/teglGLES2RenderUtil.cpp
@@ -47,6 +47,11 @@
 	gl.readPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dst.getAccess().getDataPtr());
 }
 
+void finish (const glw::Functions& gl)
+{
+	gl.finish();
+}
+
 } // gles2
 } // egl
 } // deqp
diff --git a/modules/egl/teglGLES2RenderUtil.hpp b/modules/egl/teglGLES2RenderUtil.hpp
index 0ec420c..7c91f3f 100644
--- a/modules/egl/teglGLES2RenderUtil.hpp
+++ b/modules/egl/teglGLES2RenderUtil.hpp
@@ -41,6 +41,7 @@
 
 void	clear		(const glw::Functions& gl, int x, int y, int width, int height, const tcu::Vec4& color);
 void	readPixels	(const glw::Functions& gl, tcu::Surface& dst, int x, int y, int width, int height);
+void	finish		(const glw::Functions& gl);
 
 } // gles2
 } // egl
diff --git a/modules/egl/teglRenderTests.cpp b/modules/egl/teglRenderTests.cpp
index 81a32d7..dfc61b6 100644
--- a/modules/egl/teglRenderTests.cpp
+++ b/modules/egl/teglRenderTests.cpp
@@ -637,6 +637,20 @@
 	}
 }
 
+static void finish (const glw::Functions& gl, EGLint api)
+{
+	switch (api)
+	{
+		case EGL_OPENGL_ES2_BIT:
+		case EGL_OPENGL_ES3_BIT_KHR:
+			gl.finish();
+			break;
+
+		default:
+			throw tcu::NotSupportedError("Unsupported API");
+	}
+}
+
 tcu::PixelFormat getPixelFormat (const Library& egl, EGLDisplay display, EGLConfig config)
 {
 	tcu::PixelFormat fmt;
@@ -735,6 +749,7 @@
 		EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, context));
 
 		clear(m_gl, api, CLEAR_COLOR, CLEAR_DEPTH, CLEAR_STENCIL);
+		finish(m_gl, api);
 	}
 
 	// Render.
@@ -752,6 +767,8 @@
 				const DrawPrimitiveOp& drawOp = drawOps[iterNdx*numContexts*drawsPerCtx + ctxNdx*drawsPerCtx + drawNdx];
 				draw(m_gl, api, *programs[ctxNdx], drawOp);
 			}
+
+			finish(m_gl, api);
 		}
 	}
 
@@ -843,6 +860,8 @@
 			for (int ndx = 0; ndx < packetIter->numOps; ndx++)
 				draw(m_gl, m_api, m_program, packetIter->drawOps[ndx]);
 
+			finish(m_gl, m_api);
+
 			// Release context.
 			EGLU_CHECK_CALL(m_egl, makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
 
@@ -961,6 +980,7 @@
 		EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, context));
 
 		clear(m_gl, api, CLEAR_COLOR, CLEAR_DEPTH, CLEAR_STENCIL);
+		finish(m_gl, api);
 
 		// Release context
 		EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
diff --git a/modules/egl/teglVGRenderUtil.cpp b/modules/egl/teglVGRenderUtil.cpp
index a171ca7..cb14fb3 100644
--- a/modules/egl/teglVGRenderUtil.cpp
+++ b/modules/egl/teglVGRenderUtil.cpp
@@ -51,6 +51,11 @@
 	vgReadPixels(dst.getAccess().getDataPtr(), width*4, VG_sRGBA_8888, 0, 0, width, height);
 }
 
+void finish (void)
+{
+	vgFinish();
+}
+
 #else // DEQP_SUPPORT_VG
 
 void clear (int x, int y, int width, int height, const tcu::Vec4& color)
@@ -67,6 +72,11 @@
 	TCU_THROW(NotSupportedError, "OpenVG is not supported");
 }
 
+void finish (void)
+{
+	TCU_THROW(NotSupportedError, "OpenVG is not supported");
+}
+
 #endif // DEQP_SUPPORT_VG
 
 } // vg
diff --git a/modules/egl/teglVGRenderUtil.hpp b/modules/egl/teglVGRenderUtil.hpp
index b9a9054..acf953c 100644
--- a/modules/egl/teglVGRenderUtil.hpp
+++ b/modules/egl/teglVGRenderUtil.hpp
@@ -36,6 +36,7 @@
 
 void	clear		(int x, int y, int width, int height, const tcu::Vec4& color);
 void	readPixels	(tcu::Surface& dst, int x, int y, int width, int height);
+void	finish		(void);
 
 } // vg
 } // egl