13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _EGLUNATIVEWINDOW_HPP
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _EGLUNATIVEWINDOW_HPP
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief EGL native window abstraction
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuFactoryRegistry.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluHeaderWrapper.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureLevel;
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace eglu
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NativePixmap;
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NativeDisplay;
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct WindowParams
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Visibility
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		VISIBILITY_HIDDEN = 0,
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		VISIBILITY_VISIBLE,
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		VISIBILITY_FULLSCREEN,
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		VISIBILITY_DONT_CARE,
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		VISIBILITY_LAST
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SIZE_DONT_CARE = - 1
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			width;		//!< Positive size, or SIZE_DONT_CARE
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			height;		//!< Positive size, or SIZE_DONT_CARE
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Visibility	visibility;	//!< Visibility for window
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	WindowParams (void) : width(SIZE_DONT_CARE), height(SIZE_DONT_CARE), visibility(VISIBILITY_DONT_CARE) {}
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	WindowParams (int width_, int height_, Visibility visibility_) : width(width_), height(height_), visibility(visibility_) {}
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulosclass WindowDestroyedError : public tcu::ResourceError
68217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos{
69217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulospublic:
70217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos	WindowDestroyedError (const std::string& message) : tcu::ResourceError(message) {}
71217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos};
72217426c2d19d5247e094e363615d7a0b84daf3a7Pyry Haulos
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NativeWindow
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Capability
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_CREATE_SURFACE_LEGACY	= (1<<0),	//!< EGL surface can be created with eglCreateWindowSurface()
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_CREATE_SURFACE_PLATFORM	= (1<<1),	//!< EGL surface can be created with eglCreatePlatformWindowSurface()
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_GET_SURFACE_SIZE			= (1<<2),
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_SET_SURFACE_SIZE			= (1<<3),
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_GET_SCREEN_SIZE			= (1<<4),
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_READ_SCREEN_PIXELS		= (1<<5),
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CAPABILITY_CHANGE_VISIBILITY		= (1<<6)
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual						~NativeWindow					(void) {}
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//! Return EGLNativeWindowType that can be used with eglCreateWindowSurface(). Default implementation throws tcu::NotSupportedError().
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual EGLNativeWindowType	getLegacyNative					(void);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//! Return native pointer that can be used with eglCreatePlatformWindowSurface(). Default implementation throws tcu::NotSupportedError().
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void*				getPlatformNative				(void);
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Process window events. Defaults to dummy implementation, that does nothing.
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void				processEvents					(void) {}
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Get current size of window's logical surface. Default implementation throws tcu::NotSupportedError()
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual tcu::IVec2			getSurfaceSize					(void) const;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Set the size of the window's logical surface. Default implementation throws tcu::NotSupportedError()
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void				setSurfaceSize					(tcu::IVec2 size);
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Get the size of the window in screen pixels. Default implementation throws tcu::NotSupportedError()
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual tcu::IVec2			getScreenSize					(void) const;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Read screen (visible) pixels from window. Default implementation throws tcu::NotSupportedError()
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void				readScreenPixels				(tcu::TextureLevel* dst) const;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Change window visibility. Default throws tcu::NotSupportedError().
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void				setVisibility					(WindowParams::Visibility visibility);
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Capability					getCapabilities					(void) const { return m_capabilities; }
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								NativeWindow					(Capability capabilities);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								NativeWindow					(const NativeWindow&);
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NativeWindow&				operator=						(const NativeWindow&);
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const Capability			m_capabilities;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NativeWindowFactory : public tcu::FactoryBase
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual							~NativeWindowFactory			(void);
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//! Create generic NativeWindow
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual NativeWindow*			createWindow					(NativeDisplay* nativeDisplay, const WindowParams& params) const = 0;
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//! Create NativeWindow that matches given config. Defaults to generic createWindow().
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual NativeWindow*			createWindow					(NativeDisplay* nativeDisplay, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, const WindowParams& params) const;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NativeWindow::Capability		getCapabilities					(void) const { return m_capabilities; }
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									NativeWindowFactory				(const std::string& name, const std::string& description, NativeWindow::Capability capabilities);
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									NativeWindowFactory				(const NativeWindowFactory&);
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NativeWindowFactory&			operator=						(const NativeWindowFactory&);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const NativeWindow::Capability	m_capabilities;
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef tcu::FactoryRegistry<NativeWindowFactory> NativeWindowFactoryRegistry;
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // eglu
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _EGLUNATIVEWINDOW_HPP
153