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();
166485844e764f2821545146b832726a36012f86238Mika Isojärvi	const NativeWindowFactory&	windowFactory	= eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(),
1673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																				  cmdLine);
1683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1693c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const WindowParams			windowParams	(m_oldSize.x(), m_oldSize.y(), visibility);
170485844e764f2821545146b832726a36012f86238Mika Isojärvi	MovePtr<NativeWindow>		nativeWindow	(windowFactory.createWindow(&nativeDisplay,
1713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			 eglDisplay,
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			 eglConfig,
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			 DE_NULL,
1743c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			 windowParams));
1753c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLSurface			eglSurface		= eglu::createWindowSurface(nativeDisplay,
1763c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			*nativeWindow,
1773c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			eglDisplay,
1783c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			eglConfig,
1793c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos																			DE_NULL);
1803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	MovePtr<UniqueSurface>		surface			(new UniqueSurface(egl, eglDisplay, eglSurface));
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Chose EGLConfig with id " << configId << ".\n"
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Created initial surface with size " << m_oldSize
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << TestLog::EndMessage;
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0));
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_config		= eglConfig;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_surface		= surface;
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context		= context;
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_display		= eglDisplay;
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_nativeWindow	= nativeWindow;
1933c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_MSG(egl, "init");
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTest::deinit (void)
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1983c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	if (m_display != EGL_NO_DISPLAY)
1993c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		m_eglTestCtx.getLibrary().terminate(m_display);
2003c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_config		= DE_NULL;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_display		= EGL_NO_DISPLAY;
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.clear();
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_surface.clear();
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_nativeWindow.clear();
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTest::resize (IVec2 size)
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_nativeWindow->setSurfaceSize(size);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getPlatform().processEvents();
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Resized surface to size " << size
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << TestLog::EndMessage;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ChangeSurfaceSizeCase : public ResizeTest
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ChangeSurfaceSizeCase	(EglTestContext&		eglTestCtx,
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						: ResizeTest(eglTestCtx, params) {}
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate					(void);
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid drawRectangle (const glw::Functions& gl, IVec2 pos, IVec2 size, Vec3 color)
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(color.x(), color.y(), color.z(), 1.0);
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.scissor(pos.x(), pos.y(), size.x(), size.y());
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enable(GL_SCISSOR_TEST);
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.disable(GL_SCISSOR_TEST);
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(),
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Rectangle drawing with glScissor and glClear failed.");
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid initSurface (const glw::Functions& gl, IVec2 oldSize)
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec3	frameColor	(0.0f, 0.0f, 1.0f);
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec3	fillColor	(1.0f, 0.0f, 0.0f);
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Vec3	markColor	(0.0f, 1.0f, 0.0f);
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(0, 0), oldSize, frameColor);
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(2, 2), oldSize - IVec2(4, 4), fillColor);
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(0, 0), IVec2(8, 4), markColor);
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, oldSize - IVec2(16, 16), IVec2(8, 4), markColor);
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(0, oldSize.y() - 16), IVec2(8, 4), markColor);
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawRectangle(gl, IVec2(oldSize.x() - 16, 0), IVec2(8, 4), markColor);
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool compareRectangles (const ConstPixelBufferAccess& rectA,
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						const ConstPixelBufferAccess& rectB)
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int width		= rectA.getWidth();
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int height	= rectA.getHeight();
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int depth		= rectA.getDepth();
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (rectB.getWidth() != width || rectB.getHeight() != height || rectB.getDepth() != depth)
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int z = 0; z < depth; ++z)
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int y = 0; y < height; ++y)
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int x = 0; x < width; ++x)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (rectA.getPixel(x, y, z) != rectB.getPixel(x, y, z))
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					return false;
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return true;
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Check whether `oldSurface` and `newSurface` share a common corner.
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool compareCorners (const Surface& oldSurface, const Surface& newSurface)
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	oldWidth	= oldSurface.getWidth();
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	oldHeight	= oldSurface.getHeight();
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	newWidth	= newSurface.getWidth();
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	newHeight	= newSurface.getHeight();
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	minWidth	= de::min(oldWidth, newWidth);
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	minHeight	= de::min(oldHeight, newHeight);
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int xCorner = 0; xCorner < 2; ++xCorner)
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int oldX = xCorner == 0 ? 0 : oldWidth - minWidth;
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int newX = xCorner == 0 ? 0 : newWidth - minWidth;
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int yCorner = 0; yCorner < 2; ++yCorner)
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int				oldY		= yCorner == 0 ? 0 : oldHeight - minHeight;
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int				newY		= yCorner == 0 ? 0 : newHeight - minHeight;
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ConstPixelBufferAccess	oldAccess	=
29202d3463743e013ba6e6e8be1f0b466a1855a3512Pyry Haulos				getSubregion(oldSurface.getAccess(), oldX, oldY, minWidth, minHeight);
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ConstPixelBufferAccess	newAccess	=
29402d3463743e013ba6e6e8be1f0b466a1855a3512Pyry Haulos				getSubregion(newSurface.getAccess(), newX, newY, minWidth, minHeight);
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (compareRectangles(oldAccess, newAccess))
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return true;
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko PoyrySurface readSurface (const glw::Functions& gl, IVec2 size)
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Surface ret (size.x(), size.y());
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.readPixels(0, 0, size.x(), size.y(), GL_RGBA, GL_UNSIGNED_BYTE,
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				  ret.getAccess().getDataPtr());
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels() failed");
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return ret;
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool hasBits (T bitSet, T requiredBits)
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (bitSet & requiredBits) == requiredBits;
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIVec2 getNativeSurfaceSize (const NativeWindow& nativeWindow,
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							IVec2				reqSize)
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (hasBits(nativeWindow.getCapabilities(), NativeWindow::CAPABILITY_GET_SURFACE_SIZE))
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return nativeWindow.getSurfaceSize();
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return reqSize; // assume we got the requested size
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3283c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosIVec2 checkSurfaceSize (const Library&		egl,
3293c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos						EGLDisplay			eglDisplay,
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						EGLSurface			eglSurface,
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						const NativeWindow&	nativeWindow,
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						IVec2				reqSize,
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						ResultCollector&	status)
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2		nativeSize	= getNativeSurfaceSize(nativeWindow, reqSize);
3363c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	IVec2			eglSize		= eglu::getSurfaceSize(egl, eglDisplay, eglSurface);
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream	oss;
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	oss << "Size of EGL surface " << eglSize
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< " differs from size of native window " << nativeSize;
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	status.check(eglSize == nativeSize, oss.str());
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return eglSize;
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIterateResult ChangeSurfaceSizeCase::iterate (void)
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3483c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&			egl			= m_eglTestCtx.getLibrary();
3493c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	ScopedCurrentContext	currentCtx	(egl, m_display, **m_surface, **m_surface, **m_context);
3503c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	IVec2					oldEglSize	= checkSurfaceSize(egl,
3513c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos														   m_display,
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   **m_surface,
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   *m_nativeWindow,
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   m_oldSize,
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   m_status);
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	initSurface(m_gl, oldEglSize);
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	this->resize(m_newSize);
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3613c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	egl.swapBuffers(m_display, **m_surface);
3623c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_MSG(egl, "eglSwapBuffers()");
3633c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	checkSurfaceSize(egl, m_display, **m_surface, *m_nativeWindow, m_newSize, m_status);
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.setTestContextResult(m_testCtx);
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass PreserveBackBufferCase : public ResizeTest
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					PreserveBackBufferCase	(EglTestContext&		eglTestCtx,
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						: ResizeTest(eglTestCtx, params) {}
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate					(void);
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLenum			surfaceType				(void) const;
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLenum PreserveBackBufferCase::surfaceType (void) const
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIterateResult PreserveBackBufferCase::iterate (void)
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3873c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&			egl			= m_eglTestCtx.getLibrary();
3883c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	ScopedCurrentContext	currentCtx	(egl, m_display, **m_surface, **m_surface, **m_context);
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, surfaceAttrib(m_display, **m_surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED));
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(m_gl.getError(), "GL state erroneous upon initialization!");
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3953c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const IVec2 oldEglSize = eglu::getSurfaceSize(egl, m_display, **m_surface);
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		initSurface(m_gl, oldEglSize);
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_gl.finish();
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_gl.getError(), "glFinish() failed");
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const Surface oldSurface = readSurface(m_gl, oldEglSize);
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4043c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			egl.swapBuffers(m_display, **m_surface);
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			this->resize(m_newSize);
4063c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			egl.swapBuffers(m_display, **m_surface);
4073c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			EGLU_CHECK_MSG(egl, "eglSwapBuffers()");
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4103c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos				const IVec2		newEglSize	= eglu::getSurfaceSize(egl, m_display, **m_surface);
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const Surface	newSurface	= readSurface(m_gl, newEglSize);
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_log << TestLog::ImageSet("Corner comparison",
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										   "Comparing old and new surfaces at all corners")
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  << TestLog::Image("Before resizing", "Before resizing", oldSurface)
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  << TestLog::Image("After resizing", "After resizing", newSurface)
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					  << TestLog::EndImageSet;
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4195882676a4a2c43be0a8819b5e53a035f8a4761b4Mika Isojärvi				m_status.checkResult(compareCorners(oldSurface, newSurface),
4205882676a4a2c43be0a8819b5e53a035f8a4761b4Mika Isojärvi									 QP_TEST_RESULT_QUALITY_WARNING,
4215882676a4a2c43be0a8819b5e53a035f8a4761b4Mika Isojärvi									 "Resizing the native window changed the contents of "
4225882676a4a2c43be0a8819b5e53a035f8a4761b4Mika Isojärvi									 "the EGL surface");
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.setTestContextResult(m_testCtx);
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef tcu::Vector<Interval, 2> IvVec2;
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UpdateResolutionCase : public ResizeTest
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					UpdateResolutionCase	(EglTestContext&		eglTestCtx,
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const ResizeParams&	params)
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						: ResizeTest(eglTestCtx, params) {}
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate					(void);
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IvVec2			getNativePixelsPerInch	(void);
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIvVec2 ivVec2 (const IVec2& vec)
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return IvVec2(double(vec.x()), double(vec.y()));
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4513c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInterval approximateInt (int i)
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453193f59811b2c0fe57808a06923b82ed00c41bd0fJarkko Pöyry	const Interval margin(-1.0, 1.0); // The resolution may be rounded
454193f59811b2c0fe57808a06923b82ed00c41bd0fJarkko Pöyry
455193f59811b2c0fe57808a06923b82ed00c41bd0fJarkko Pöyry	return (Interval(i) + margin) & Interval(0.0, TCU_INFINITY);
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIvVec2 UpdateResolutionCase::getNativePixelsPerInch	(void)
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4603c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl			= m_eglTestCtx.getLibrary();
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		inchPer10km	= 254 * EGL_DISPLAY_SCALING;
4623c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const IVec2		bufSize		= eglu::getSurfaceSize(egl, m_display, **m_surface);
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2		winSize		= m_nativeWindow->getScreenSize();
4643c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const IVec2		bufPp10km	= eglu::getSurfaceResolution(egl, m_display, **m_surface);
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IvVec2	bufPpiI		= (IvVec2(approximateInt(bufPp10km.x()),
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  approximateInt(bufPp10km.y()))
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								   / Interval(inchPer10km));
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IvVec2	winPpiI		= ivVec2(winSize) * bufPpiI / ivVec2(bufSize);
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const IVec2		winPpi		(int(winPpiI.x().midpoint()), int(winPpiI.y().midpoint()));
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "EGL surface size: "							<< bufSize		<< "\n"
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "EGL surface pixel density (pixels / 10 km): "	<< bufPp10km	<< "\n"
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Native window size: "							<< winSize		<< "\n"
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << "Native pixel density (ppi): "					<< winPpi		<< "\n"
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  << TestLog::EndMessage;
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.checkResult(bufPp10km.x() >= 1 && bufPp10km.y() >= 1,
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 QP_TEST_RESULT_QUALITY_WARNING,
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 "Surface pixel density is less than one pixel per 10 km. "
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 "Is the surface really visible from space?");
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return winPpiI;
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4863c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIterateResult UpdateResolutionCase::iterate (void)
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4883c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&			egl			= m_eglTestCtx.getLibrary();
4893c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	ScopedCurrentContext	currentCtx	(egl, m_display, **m_surface, **m_surface, **m_context);
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!hasBits(m_nativeWindow->getCapabilities(),
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				 NativeWindow::CAPABILITY_GET_SCREEN_SIZE))
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_THROW(NotSupportedError, "Unable to determine surface size in screen pixels");
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4963c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const IVec2 oldEglSize = eglu::getSurfaceSize(egl, m_display, **m_surface);
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		initSurface(m_gl, oldEglSize);
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const IvVec2 oldPpi = this->getNativePixelsPerInch();
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		this->resize(m_newSize);
5023c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_CALL(egl, swapBuffers(m_display, **m_surface));
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const IvVec2 newPpi = this->getNativePixelsPerInch();
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_status.check(oldPpi.x().intersects(newPpi.x()) &&
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						   oldPpi.y().intersects(newPpi.y()),
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						   "Window PPI differs after resizing");
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_status.setTestContextResult(m_testCtx);
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryResizeTests::ResizeTests (EglTestContext& eglTestCtx)
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(eglTestCtx, "resize", "Tests resizing the native surface")
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <class Case>
5213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCaseGroup* createCaseGroup(EglTestContext&	eglTestCtx,
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							   const string&	name,
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							   const string&	desc)
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ResizeParams		params[]	=
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "shrink",			"Shrink in both dimensions",
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(128, 128),	IVec2(32, 32) },
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "grow",			"Grow in both dimensions",
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(32, 32),	IVec2(128, 128) },
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stretch_width",	"Grow horizontally, shrink vertically",
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(32, 128),	IVec2(128, 32) },
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stretch_height",	"Grow vertically, shrink horizontally",
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		  IVec2(128, 32),	IVec2(32, 128) },
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestCaseGroup* const	group		=
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		new TestCaseGroup(eglTestCtx, name.c_str(), desc.c_str());
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(params); ++ndx)
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group->addChild(new Case(eglTestCtx, params[ndx]));
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return group;
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTests::init (void)
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(createCaseGroup<ChangeSurfaceSizeCase>(m_eglTestCtx,
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"surface_size",
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"EGL surface size update"));
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(createCaseGroup<PreserveBackBufferCase>(m_eglTestCtx,
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 "back_buffer",
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 "Back buffer contents"));
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(createCaseGroup<UpdateResolutionCase>(m_eglTestCtx,
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												   "pixel_density",
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												   "Pixel density"));
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
560