Home | History | Annotate | Download | only in egl
      1 #ifndef _EGLUNATIVEWINDOW_HPP
      2 #define _EGLUNATIVEWINDOW_HPP
      3 /*-------------------------------------------------------------------------
      4  * drawElements Quality Program Tester Core
      5  * ----------------------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief EGL native window abstraction
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "tcuDefs.hpp"
     27 #include "tcuFactoryRegistry.hpp"
     28 #include "egluHeaderWrapper.hpp"
     29 #include "tcuVector.hpp"
     30 
     31 namespace tcu
     32 {
     33 class TextureLevel;
     34 }
     35 
     36 namespace eglu
     37 {
     38 
     39 class NativePixmap;
     40 class NativeDisplay;
     41 
     42 struct WindowParams
     43 {
     44 	enum Visibility
     45 	{
     46 		VISIBILITY_HIDDEN = 0,
     47 		VISIBILITY_VISIBLE,
     48 		VISIBILITY_FULLSCREEN,
     49 		VISIBILITY_DONT_CARE,
     50 
     51 		VISIBILITY_LAST
     52 	};
     53 
     54 	enum
     55 	{
     56 		SIZE_DONT_CARE = - 1
     57 	};
     58 
     59 	int			width;		//!< Positive size, or SIZE_DONT_CARE
     60 	int			height;		//!< Positive size, or SIZE_DONT_CARE
     61 	Visibility	visibility;	//!< Visibility for window
     62 
     63 	WindowParams (void) : width(SIZE_DONT_CARE), height(SIZE_DONT_CARE), visibility(VISIBILITY_DONT_CARE) {}
     64 	WindowParams (int width_, int height_, Visibility visibility_) : width(width_), height(height_), visibility(visibility_) {}
     65 };
     66 
     67 class WindowDestroyedError : public tcu::ResourceError
     68 {
     69 public:
     70 	WindowDestroyedError (const std::string& message) : tcu::ResourceError(message) {}
     71 };
     72 
     73 class NativeWindow
     74 {
     75 public:
     76 	enum Capability
     77 	{
     78 		CAPABILITY_CREATE_SURFACE_LEGACY	= (1<<0),	//!< EGL surface can be created with eglCreateWindowSurface()
     79 		CAPABILITY_CREATE_SURFACE_PLATFORM	= (1<<1),	//!< EGL surface can be created with eglCreatePlatformWindowSurface()
     80 		CAPABILITY_GET_SURFACE_SIZE			= (1<<2),
     81 		CAPABILITY_SET_SURFACE_SIZE			= (1<<3),
     82 		CAPABILITY_GET_SCREEN_SIZE			= (1<<4),
     83 		CAPABILITY_READ_SCREEN_PIXELS		= (1<<5),
     84 		CAPABILITY_CHANGE_VISIBILITY		= (1<<6)
     85 	};
     86 
     87 	virtual						~NativeWindow					(void) {}
     88 
     89 	//! Return EGLNativeWindowType that can be used with eglCreateWindowSurface(). Default implementation throws tcu::NotSupportedError().
     90 	virtual EGLNativeWindowType	getLegacyNative					(void);
     91 
     92 	//! Return native pointer that can be used with eglCreatePlatformWindowSurface(). Default implementation throws tcu::NotSupportedError().
     93 	virtual void*				getPlatformNative				(void);
     94 
     95 	// Process window events. Defaults to dummy implementation, that does nothing.
     96 	virtual void				processEvents					(void) {}
     97 
     98 	// Get current size of window's logical surface. Default implementation throws tcu::NotSupportedError()
     99 	virtual tcu::IVec2			getSurfaceSize					(void) const;
    100 
    101 	// Set the size of the window's logical surface. Default implementation throws tcu::NotSupportedError()
    102 	virtual void				setSurfaceSize					(tcu::IVec2 size);
    103 
    104 	// Get the size of the window in screen pixels. Default implementation throws tcu::NotSupportedError()
    105 	virtual tcu::IVec2			getScreenSize					(void) const;
    106 
    107 	// Read screen (visible) pixels from window. Default implementation throws tcu::NotSupportedError()
    108 	virtual void				readScreenPixels				(tcu::TextureLevel* dst) const;
    109 
    110 	// Change window visibility. Default throws tcu::NotSupportedError().
    111 	virtual void				setVisibility					(WindowParams::Visibility visibility);
    112 
    113 	Capability					getCapabilities					(void) const { return m_capabilities; }
    114 
    115 protected:
    116 								NativeWindow					(Capability capabilities);
    117 
    118 private:
    119 								NativeWindow					(const NativeWindow&);
    120 	NativeWindow&				operator=						(const NativeWindow&);
    121 
    122 	const Capability			m_capabilities;
    123 };
    124 
    125 class NativeWindowFactory : public tcu::FactoryBase
    126 {
    127 public:
    128 	virtual							~NativeWindowFactory			(void);
    129 
    130 	//! Create generic NativeWindow
    131 	virtual NativeWindow*			createWindow					(NativeDisplay* nativeDisplay, const WindowParams& params) const = 0;
    132 
    133 	//! Create NativeWindow that matches given config. Defaults to generic createWindow().
    134 	virtual NativeWindow*			createWindow					(NativeDisplay* nativeDisplay, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, const WindowParams& params) const;
    135 
    136 	NativeWindow::Capability		getCapabilities					(void) const { return m_capabilities; }
    137 
    138 protected:
    139 									NativeWindowFactory				(const std::string& name, const std::string& description, NativeWindow::Capability capabilities);
    140 
    141 private:
    142 									NativeWindowFactory				(const NativeWindowFactory&);
    143 	NativeWindowFactory&			operator=						(const NativeWindowFactory&);
    144 
    145 	const NativeWindow::Capability	m_capabilities;
    146 };
    147 
    148 typedef tcu::FactoryRegistry<NativeWindowFactory> NativeWindowFactoryRegistry;
    149 
    150 } // eglu
    151 
    152 #endif // _EGLUNATIVEWINDOW_HPP
    153