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 WindowParamseglu::WindowParams63 WindowParams(void) : width(SIZE_DONT_CARE), height(SIZE_DONT_CARE), visibility(VISIBILITY_DONT_CARE) 64 { 65 } WindowParamseglu::WindowParams66 WindowParams(int width_, int height_, Visibility visibility_) 67 : width(width_) 68 , height(height_) 69 , visibility(visibility_) 70 { 71 } 72 }; 73 74 class WindowDestroyedError : public tcu::ResourceError 75 { 76 public: WindowDestroyedError(const std::string & message)77 WindowDestroyedError(const std::string &message) : tcu::ResourceError(message) 78 { 79 } 80 }; 81 82 class NativeWindow 83 { 84 public: 85 enum Capability 86 { 87 CAPABILITY_CREATE_SURFACE_LEGACY = (1 << 0), //!< EGL surface can be created with eglCreateWindowSurface() 88 CAPABILITY_CREATE_SURFACE_PLATFORM_EXTENSION = 89 (1 << 1), //!< EGL surface can be created with eglCreatePlatformWindowSurfaceEXT() 90 CAPABILITY_CREATE_SURFACE_PLATFORM = 91 (1 << 2), //!< EGL surface can be created with eglCreatePlatformWindowSurface() 92 CAPABILITY_GET_SURFACE_SIZE = (1 << 3), 93 CAPABILITY_SET_SURFACE_SIZE = (1 << 4), 94 CAPABILITY_GET_SCREEN_SIZE = (1 << 5), 95 CAPABILITY_READ_SCREEN_PIXELS = (1 << 6), 96 CAPABILITY_CHANGE_VISIBILITY = (1 << 7) 97 }; 98 ~NativeWindow(void)99 virtual ~NativeWindow(void) 100 { 101 } 102 103 //! Return EGLNativeWindowType that can be used with eglCreateWindowSurface(). Default implementation throws tcu::NotSupportedError(). 104 virtual eglw::EGLNativeWindowType getLegacyNative(void); 105 106 //! Return native pointer that can be used with eglCreatePlatformWindowSurfaceEXT(). Default implementation throws tcu::NotSupportedError(). 107 virtual void *getPlatformExtension(void); 108 109 //! Return native pointer that can be used with eglCreatePlatformWindowSurface(). Default implementation throws tcu::NotSupportedError(). 110 virtual void *getPlatformNative(void); 111 112 // Process window events. Defaults to empty implementation, that does nothing. processEvents(void)113 virtual void processEvents(void) 114 { 115 } 116 117 // Get current size of window's logical surface. Default implementation throws tcu::NotSupportedError() 118 virtual tcu::IVec2 getSurfaceSize(void) const; 119 120 // Set the size of the window's logical surface. Default implementation throws tcu::NotSupportedError() 121 virtual void setSurfaceSize(tcu::IVec2 size); 122 123 // Get the size of the window in screen pixels. Default implementation throws tcu::NotSupportedError() 124 virtual tcu::IVec2 getScreenSize(void) const; 125 126 // Read screen (visible) pixels from window. Default implementation throws tcu::NotSupportedError() 127 virtual void readScreenPixels(tcu::TextureLevel *dst) const; 128 129 // Change window visibility. Default throws tcu::NotSupportedError(). 130 virtual void setVisibility(WindowParams::Visibility visibility); 131 getCapabilities(void) const132 Capability getCapabilities(void) const 133 { 134 return m_capabilities; 135 } 136 137 protected: 138 NativeWindow(Capability capabilities); 139 140 private: 141 NativeWindow(const NativeWindow &); 142 NativeWindow &operator=(const NativeWindow &); 143 144 const Capability m_capabilities; 145 }; 146 147 class NativeWindowFactory : public tcu::FactoryBase 148 { 149 public: 150 virtual ~NativeWindowFactory(void); 151 152 //! Create generic NativeWindow 153 virtual NativeWindow *createWindow(NativeDisplay *nativeDisplay, const WindowParams ¶ms) const = 0; 154 155 //! Create NativeWindow that matches given config. Defaults to generic createWindow(). 156 virtual NativeWindow *createWindow(NativeDisplay *nativeDisplay, eglw::EGLDisplay display, eglw::EGLConfig config, 157 const eglw::EGLAttrib *attribList, const WindowParams ¶ms) const; 158 getCapabilities(void) const159 NativeWindow::Capability getCapabilities(void) const 160 { 161 return m_capabilities; 162 } 163 164 protected: 165 NativeWindowFactory(const std::string &name, const std::string &description, NativeWindow::Capability capabilities); 166 167 private: 168 NativeWindowFactory(const NativeWindowFactory &); 169 NativeWindowFactory &operator=(const NativeWindowFactory &); 170 171 const NativeWindow::Capability m_capabilities; 172 }; 173 174 typedef tcu::FactoryRegistry<NativeWindowFactory> NativeWindowFactoryRegistry; 175 176 } // namespace eglu 177 178 #endif // _EGLUNATIVEWINDOW_HPP 179