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 "eglwDefs.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_EXTENSION	= (1<<1),	//!< EGL surface can be created with eglCreatePlatformWindowSurfaceEXT()
     80 		CAPABILITY_CREATE_SURFACE_PLATFORM				= (1<<2),	//!< EGL surface can be created with eglCreatePlatformWindowSurface()
     81 		CAPABILITY_GET_SURFACE_SIZE						= (1<<3),
     82 		CAPABILITY_SET_SURFACE_SIZE						= (1<<4),
     83 		CAPABILITY_GET_SCREEN_SIZE						= (1<<5),
     84 		CAPABILITY_READ_SCREEN_PIXELS					= (1<<6),
     85 		CAPABILITY_CHANGE_VISIBILITY					= (1<<7)
     86 	};
     87 
     88 	virtual								~NativeWindow					(void) {}
     89 
     90 	//! Return EGLNativeWindowType that can be used with eglCreateWindowSurface(). Default implementation throws tcu::NotSupportedError().
     91 	virtual eglw::EGLNativeWindowType	getLegacyNative					(void);
     92 
     93 	//! Return native pointer that can be used with eglCreatePlatformWindowSurfaceEXT(). Default implementation throws tcu::NotSupportedError().
     94 	virtual void*						getPlatformExtension			(void);
     95 
     96 	//! Return native pointer that can be used with eglCreatePlatformWindowSurface(). Default implementation throws tcu::NotSupportedError().
     97 	virtual void*						getPlatformNative				(void);
     98 
     99 	// Process window events. Defaults to dummy implementation, that does nothing.
    100 	virtual void						processEvents					(void) {}
    101 
    102 	// Get current size of window's logical surface. Default implementation throws tcu::NotSupportedError()
    103 	virtual tcu::IVec2					getSurfaceSize					(void) const;
    104 
    105 	// Set the size of the window's logical surface. Default implementation throws tcu::NotSupportedError()
    106 	virtual void						setSurfaceSize					(tcu::IVec2 size);
    107 
    108 	// Get the size of the window in screen pixels. Default implementation throws tcu::NotSupportedError()
    109 	virtual tcu::IVec2					getScreenSize					(void) const;
    110 
    111 	// Read screen (visible) pixels from window. Default implementation throws tcu::NotSupportedError()
    112 	virtual void						readScreenPixels				(tcu::TextureLevel* dst) const;
    113 
    114 	// Change window visibility. Default throws tcu::NotSupportedError().
    115 	virtual void						setVisibility					(WindowParams::Visibility visibility);
    116 
    117 	Capability							getCapabilities					(void) const { return m_capabilities; }
    118 
    119 protected:
    120 										NativeWindow					(Capability capabilities);
    121 
    122 private:
    123 										NativeWindow					(const NativeWindow&);
    124 	NativeWindow&						operator=						(const NativeWindow&);
    125 
    126 	const Capability					m_capabilities;
    127 };
    128 
    129 class NativeWindowFactory : public tcu::FactoryBase
    130 {
    131 public:
    132 	virtual								~NativeWindowFactory			(void);
    133 
    134 	//! Create generic NativeWindow
    135 	virtual NativeWindow*				createWindow					(NativeDisplay* nativeDisplay, const WindowParams& params) const = 0;
    136 
    137 	//! Create NativeWindow that matches given config. Defaults to generic createWindow().
    138 	virtual NativeWindow*				createWindow					(NativeDisplay* nativeDisplay, eglw::EGLDisplay display, eglw::EGLConfig config, const eglw::EGLAttrib* attribList, const WindowParams& params) const;
    139 
    140 	NativeWindow::Capability			getCapabilities					(void) const { return m_capabilities; }
    141 
    142 protected:
    143 										NativeWindowFactory				(const std::string& name, const std::string& description, NativeWindow::Capability capabilities);
    144 
    145 private:
    146 										NativeWindowFactory				(const NativeWindowFactory&);
    147 	NativeWindowFactory&				operator=						(const NativeWindowFactory&);
    148 
    149 	const NativeWindow::Capability		m_capabilities;
    150 };
    151 
    152 typedef tcu::FactoryRegistry<NativeWindowFactory> NativeWindowFactoryRegistry;
    153 
    154 } // eglu
    155 
    156 #endif // _EGLUNATIVEWINDOW_HPP
    157