teglResizeTests.cpp revision ab44fc6da25bb126919615ad2ded101695251161
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program EGL Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Tests for resizing the native window of a surface.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglResizeTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglSimpleConfigCase.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuPlatform.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuInterval.hpp"
3302d3463743e013ba6e6e8be1f0b466a1855a3512Pyry Haulos#include "tcuTextureUtil.hpp"
34ab44fc6da25bb126919615ad2ded101695251161Jarkko Pöyry#include "tcuResultCollector.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeDisplay.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeWindow.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativePixmap.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUnique.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUtil.hpp"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "eglwLibrary.hpp"
433c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "eglwEnums.hpp"
443c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp"
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp"
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deThread.h"
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp"
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream>
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace egl
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing std::vector;
633c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing std::string;
643c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing std::ostringstream;
653c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing de::MovePtr;
663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::CommandLine;
673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::ConstPixelBufferAccess;
683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::Interval;
693c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::IVec2;
703c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::Vec3;
713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::Vec4;
723c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::UVec4;
733c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::ResultCollector;
743c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::Surface;
753c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::TestLog;
763c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::AttribMap;
773c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::NativeDisplay;
783c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::NativeWindow;
793c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::ScopedCurrentContext;
803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::UniqueSurface;
813c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::UniqueContext;
823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::NativeWindowFactory;
833c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing eglu::WindowParams;
843c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing namespace eglw;
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef	eglu::WindowParams::Visibility	Visibility;
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef	TestCase::IterateResult			IterateResult;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ResizeParams
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string	name;
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string	description;
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IVec2	oldSize;
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IVec2	newSize;
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ResizeTest : public TestCase
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								ResizeTest	(EglTestContext&		eglTestCtx,
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									: TestCase	(eglTestCtx,
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 params.name.c_str(),
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 params.description.c_str())
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									, m_oldSize	(params.oldSize)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									, m_newSize	(params.newSize)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									, m_display	(EGL_NO_DISPLAY)
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									, m_config	(DE_NULL)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									, m_log		(m_testCtx.getLog())
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									, m_status	(m_log) {}
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						init		(void);
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						deinit		(void);
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual EGLenum				surfaceType	(void) const { return EGL_WINDOW_BIT; }
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						resize		(IVec2 size);
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2					m_oldSize;
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2					m_newSize;
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLDisplay					m_display;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLConfig					m_config;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MovePtr<NativeWindow>		m_nativeWindow;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MovePtr<UniqueSurface>		m_surface;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MovePtr<UniqueContext>		m_context;
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&					m_log;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ResultCollector				m_status;
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::Functions				m_gl;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1313c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLConfig getEGLConfig (const Library& egl, const EGLDisplay eglDisplay, EGLenum surfaceType)
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	AttribMap attribMap;
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	attribMap[EGL_SURFACE_TYPE]		= surfaceType;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	attribMap[EGL_RENDERABLE_TYPE]	= EGL_OPENGL_ES2_BIT;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return eglu::chooseSingleConfig(egl, eglDisplay, attribMap);
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTest::init (void)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestCase::init();
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&				egl				= m_eglTestCtx.getLibrary();
1463c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const CommandLine&			cmdLine			= m_testCtx.getCommandLine();
1473c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLDisplay			eglDisplay		= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
1483c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLConfig				eglConfig		= getEGLConfig(egl, eglDisplay, surfaceType());
1493c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLint				ctxAttribs[]	=
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGL_CONTEXT_CLIENT_VERSION, 2,
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGL_NONE
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1543c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLContext					eglContext		= egl.createContext(eglDisplay,
1553c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																   eglConfig,
1563c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																   EGL_NO_CONTEXT,
1573c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																   ctxAttribs);
1583c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_MSG(egl, "eglCreateContext()");
1593c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	MovePtr<UniqueContext>		context			(new UniqueContext(egl, eglDisplay, eglContext));
1603c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLint				configId		= eglu::getConfigAttribInt(egl,
1613c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																		   eglDisplay,
1623c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																		   eglConfig,
1633c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																		   EGL_CONFIG_ID);
1643c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Visibility			visibility		= eglu::parseWindowVisibility(cmdLine);
1653c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	NativeDisplay&				nativeDisplay	= m_eglTestCtx.getNativeDisplay();
1663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const NativeWindowFactory*	windowFactory	= eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(),
1673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																				  cmdLine);
1683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1693c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	if (!windowFactory)
1703c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		TCU_THROW(NotSupportedError, "Windows not supported");
1713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1723c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const WindowParams			windowParams	(m_oldSize.x(), m_oldSize.y(), visibility);
1733c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	MovePtr<NativeWindow>		nativeWindow	(windowFactory->createWindow(&nativeDisplay,
1743c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			 eglDisplay,
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			 eglConfig,
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			 DE_NULL,
1773c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			 windowParams));
1783c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLSurface			eglSurface		= eglu::createWindowSurface(nativeDisplay,
1793c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			*nativeWindow,
1803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			eglDisplay,
1813c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			eglConfig,
1823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			DE_NULL);
1833c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	MovePtr<UniqueSurface>		surface			(new UniqueSurface(egl, eglDisplay, eglSurface));
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Chose EGLConfig with id " << configId << ".\n"
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Created initial surface with size " << m_oldSize
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << TestLog::EndMessage;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1903c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0));
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_config		= eglConfig;
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_surface		= surface;
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context		= context;
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_display		= eglDisplay;
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_nativeWindow	= nativeWindow;
1963c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_MSG(egl, "init");
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTest::deinit (void)
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2013c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	if (m_display != EGL_NO_DISPLAY)
2023c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		m_eglTestCtx.getLibrary().terminate(m_display);
2033c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_config		= DE_NULL;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_display		= EGL_NO_DISPLAY;
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.clear();
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_surface.clear();
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_nativeWindow.clear();
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTest::resize (IVec2 size)
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_nativeWindow->setSurfaceSize(size);
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getPlatform().processEvents();
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Resized surface to size " << size
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << TestLog::EndMessage;
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ChangeSurfaceSizeCase : public ResizeTest
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ChangeSurfaceSizeCase	(EglTestContext&		eglTestCtx,
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						: ResizeTest(eglTestCtx, params) {}
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate					(void);
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid drawRectangle (const glw::Functions& gl, IVec2 pos, IVec2 size, Vec3 color)
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(color.x(), color.y(), color.z(), 1.0);
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.scissor(pos.x(), pos.y(), size.x(), size.y());
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enable(GL_SCISSOR_TEST);
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.disable(GL_SCISSOR_TEST);
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(),
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Rectangle drawing with glScissor and glClear failed.");
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid initSurface (const glw::Functions& gl, IVec2 oldSize)
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec3	frameColor	(0.0f, 0.0f, 1.0f);
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec3	fillColor	(1.0f, 0.0f, 0.0f);
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec3	markColor	(0.0f, 1.0f, 0.0f);
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(0, 0), oldSize, frameColor);
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(2, 2), oldSize - IVec2(4, 4), fillColor);
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(0, 0), IVec2(8, 4), markColor);
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, oldSize - IVec2(16, 16), IVec2(8, 4), markColor);
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(0, oldSize.y() - 16), IVec2(8, 4), markColor);
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(oldSize.x() - 16, 0), IVec2(8, 4), markColor);
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool compareRectangles (const ConstPixelBufferAccess& rectA,
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						const ConstPixelBufferAccess& rectB)
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int width		= rectA.getWidth();
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int height	= rectA.getHeight();
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int depth		= rectA.getDepth();
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (rectB.getWidth() != width || rectB.getHeight() != height || rectB.getDepth() != depth)
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int z = 0; z < depth; ++z)
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int y = 0; y < height; ++y)
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int x = 0; x < width; ++x)
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (rectA.getPixel(x, y, z) != rectB.getPixel(x, y, z))
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					return false;
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return true;
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Check whether `oldSurface` and `newSurface` share a common corner.
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool compareCorners (const Surface& oldSurface, const Surface& newSurface)
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	oldWidth	= oldSurface.getWidth();
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	oldHeight	= oldSurface.getHeight();
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	newWidth	= newSurface.getWidth();
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	newHeight	= newSurface.getHeight();
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	minWidth	= de::min(oldWidth, newWidth);
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	minHeight	= de::min(oldHeight, newHeight);
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int xCorner = 0; xCorner < 2; ++xCorner)
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int oldX = xCorner == 0 ? 0 : oldWidth - minWidth;
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int newX = xCorner == 0 ? 0 : newWidth - minWidth;
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int yCorner = 0; yCorner < 2; ++yCorner)
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int				oldY		= yCorner == 0 ? 0 : oldHeight - minHeight;
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int				newY		= yCorner == 0 ? 0 : newHeight - minHeight;
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ConstPixelBufferAccess	oldAccess	=
29502d3463743e013ba6e6e8be1f0b466a1855a3512Pyry Haulos				getSubregion(oldSurface.getAccess(), oldX, oldY, minWidth, minHeight);
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ConstPixelBufferAccess	newAccess	=
29702d3463743e013ba6e6e8be1f0b466a1855a3512Pyry Haulos				getSubregion(newSurface.getAccess(), newX, newY, minWidth, minHeight);
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (compareRectangles(oldAccess, newAccess))
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return true;
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3073c827367444ee418f129b2c238299f49d3264554Jarkko PoyrySurface readSurface (const glw::Functions& gl, IVec2 size)
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Surface ret (size.x(), size.y());
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.readPixels(0, 0, size.x(), size.y(), GL_RGBA, GL_UNSIGNED_BYTE,
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				  ret.getAccess().getDataPtr());
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels() failed");
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return ret;
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool hasBits (T bitSet, T requiredBits)
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (bitSet & requiredBits) == requiredBits;
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3233c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIVec2 getNativeSurfaceSize (const NativeWindow& nativeWindow,
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							IVec2				reqSize)
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (hasBits(nativeWindow.getCapabilities(), NativeWindow::CAPABILITY_GET_SURFACE_SIZE))
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return nativeWindow.getSurfaceSize();
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return reqSize; // assume we got the requested size
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3313c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosIVec2 checkSurfaceSize (const Library&		egl,
3323c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos						EGLDisplay			eglDisplay,
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						EGLSurface			eglSurface,
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						const NativeWindow&	nativeWindow,
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						IVec2				reqSize,
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						ResultCollector&	status)
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2		nativeSize	= getNativeSurfaceSize(nativeWindow, reqSize);
3393c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	IVec2			eglSize		= eglu::getSurfaceSize(egl, eglDisplay, eglSurface);
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream	oss;
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	oss << "Size of EGL surface " << eglSize
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< " differs from size of native window " << nativeSize;
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	status.check(eglSize == nativeSize, oss.str());
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return eglSize;
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3493c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIterateResult ChangeSurfaceSizeCase::iterate (void)
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3513c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&			egl			= m_eglTestCtx.getLibrary();
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Surface					oldSurface;
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Surface					newSurface;
3543c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	ScopedCurrentContext	currentCtx	(egl, m_display, **m_surface, **m_surface, **m_context);
3553c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	IVec2					oldEglSize	= checkSurfaceSize(egl,
3563c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos														   m_display,
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   **m_surface,
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   *m_nativeWindow,
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   m_oldSize,
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   m_status);
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	initSurface(m_gl, oldEglSize);
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	this->resize(m_newSize);
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	egl.swapBuffers(m_display, **m_surface);
3673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_MSG(egl, "eglSwapBuffers()");
3683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	checkSurfaceSize(egl, m_display, **m_surface, *m_nativeWindow, m_newSize, m_status);
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.setTestContextResult(m_testCtx);
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass PreserveBackBufferCase : public ResizeTest
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					PreserveBackBufferCase	(EglTestContext&		eglTestCtx,
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						: ResizeTest(eglTestCtx, params) {}
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate					(void);
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLenum			surfaceType				(void) const;
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLenum PreserveBackBufferCase::surfaceType (void) const
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIterateResult PreserveBackBufferCase::iterate (void)
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3923c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&			egl			= m_eglTestCtx.getLibrary();
3933c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	ScopedCurrentContext	currentCtx	(egl, m_display, **m_surface, **m_surface, **m_context);
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, surfaceAttrib(m_display, **m_surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED));
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(m_gl.getError(), "GL state erroneous upon initialization!");
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4003c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const IVec2 oldEglSize = eglu::getSurfaceSize(egl, m_display, **m_surface);
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		initSurface(m_gl, oldEglSize);
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_gl.finish();
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_gl.getError(), "glFinish() failed");
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const Surface oldSurface = readSurface(m_gl, oldEglSize);
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4093c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			egl.swapBuffers(m_display, **m_surface);
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			this->resize(m_newSize);
4113c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			egl.swapBuffers(m_display, **m_surface);
4123c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			EGLU_CHECK_MSG(egl, "eglSwapBuffers()");
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4153c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos				const IVec2		newEglSize	= eglu::getSurfaceSize(egl, m_display, **m_surface);
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const Surface	newSurface	= readSurface(m_gl, newEglSize);
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_log << TestLog::ImageSet("Corner comparison",
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										   "Comparing old and new surfaces at all corners")
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  << TestLog::Image("Before resizing", "Before resizing", oldSurface)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  << TestLog::Image("After resizing", "After resizing", newSurface)
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  << TestLog::EndImageSet;
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_status.check(compareCorners(oldSurface, newSurface),
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							   "Resizing the native window changed the contents of "
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							   "the EGL surface");
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.setTestContextResult(m_testCtx);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef tcu::Vector<Interval, 2> IvVec2;
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UpdateResolutionCase : public ResizeTest
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					UpdateResolutionCase	(EglTestContext&		eglTestCtx,
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						: ResizeTest(eglTestCtx, params) {}
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate					(void);
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IvVec2			getNativePixelsPerInch	(void);
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4503c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIvVec2 ivVec2 (const IVec2& vec)
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return IvVec2(double(vec.x()), double(vec.y()));
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4553c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInterval approximateInt (int i)
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (Interval(i) + Interval(-1.0, 1.0)) & Interval(0.0, TCU_INFINITY);
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIvVec2 UpdateResolutionCase::getNativePixelsPerInch	(void)
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4623c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl			= m_eglTestCtx.getLibrary();
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		inchPer10km	= 254 * EGL_DISPLAY_SCALING;
4643c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const IVec2		bufSize		= eglu::getSurfaceSize(egl, m_display, **m_surface);
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2		winSize		= m_nativeWindow->getScreenSize();
4663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const IVec2		bufPp10km	= eglu::getSurfaceResolution(egl, m_display, **m_surface);
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Interval	margin		(-1.0, 1.0); // The resolution may be rounded
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IvVec2	bufPpiI		= (IvVec2(approximateInt(bufPp10km.x()),
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  approximateInt(bufPp10km.y()))
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								   / Interval(inchPer10km));
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IvVec2	winPpiI		= ivVec2(winSize) * bufPpiI / ivVec2(bufSize);
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2		winPpi		(int(winPpiI.x().midpoint()), int(winPpiI.y().midpoint()));
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "EGL surface size: "							<< bufSize		<< "\n"
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "EGL surface pixel density (pixels / 10 km): "	<< bufPp10km	<< "\n"
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Native window size: "							<< winSize		<< "\n"
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Native pixel density (ppi): "					<< winPpi		<< "\n"
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << TestLog::EndMessage;
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.checkResult(bufPp10km.x() >= 1 && bufPp10km.y() >= 1,
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 QP_TEST_RESULT_QUALITY_WARNING,
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 "Surface pixel density is less than one pixel per 10 km. "
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 "Is the surface really visible from space?");
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return winPpiI;
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIterateResult UpdateResolutionCase::iterate (void)
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4913c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&			egl			= m_eglTestCtx.getLibrary();
4923c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	ScopedCurrentContext	currentCtx	(egl, m_display, **m_surface, **m_surface, **m_context);
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!hasBits(m_nativeWindow->getCapabilities(),
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 NativeWindow::CAPABILITY_GET_SCREEN_SIZE))
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_THROW(NotSupportedError, "Unable to determine surface size in screen pixels");
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4993c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const IVec2 oldEglSize = eglu::getSurfaceSize(egl, m_display, **m_surface);
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		initSurface(m_gl, oldEglSize);
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const IvVec2 oldPpi = this->getNativePixelsPerInch();
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		this->resize(m_newSize);
5053c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_CALL(egl, swapBuffers(m_display, **m_surface));
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const IvVec2 newPpi = this->getNativePixelsPerInch();
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_status.check(oldPpi.x().intersects(newPpi.x()) &&
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						   oldPpi.y().intersects(newPpi.y()),
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						   "Window PPI differs after resizing");
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.setTestContextResult(m_testCtx);
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryResizeTests::ResizeTests (EglTestContext& eglTestCtx)
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(eglTestCtx, "resize", "Tests resizing the native surface")
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <class Case>
5243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCaseGroup* createCaseGroup(EglTestContext&	eglTestCtx,
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							   const string&	name,
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							   const string&	desc)
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ResizeParams		params[]	=
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "shrink",			"Shrink in both dimensions",
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(128, 128),	IVec2(32, 32) },
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "grow",			"Grow in both dimensions",
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(32, 32),	IVec2(128, 128) },
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stretch_width",	"Grow horizontally, shrink vertically",
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(32, 128),	IVec2(128, 32) },
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stretch_height",	"Grow vertically, shrink horizontally",
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(128, 32),	IVec2(32, 128) },
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestCaseGroup* const	group		=
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		new TestCaseGroup(eglTestCtx, name.c_str(), desc.c_str());
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(params); ++ndx)
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group->addChild(new Case(eglTestCtx, params[ndx]));
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return group;
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTests::init (void)
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(createCaseGroup<ChangeSurfaceSizeCase>(m_eglTestCtx,
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"surface_size",
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"EGL surface size update"));
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(createCaseGroup<PreserveBackBufferCase>(m_eglTestCtx,
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 "back_buffer",
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 "Back buffer contents"));
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(createCaseGroup<UpdateResolutionCase>(m_eglTestCtx,
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												   "pixel_density",
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												   "Pixel density"));
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
563