1 #ifndef _VKWSIPLATFORM_HPP 2 #define _VKWSIPLATFORM_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2016 Google Inc. 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 WSI Platform Abstraction. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "vkDefs.hpp" 27 #include "tcuVector.hpp" 28 #include "tcuMaybe.hpp" 29 30 namespace vk 31 { 32 namespace wsi 33 { 34 35 class Window 36 { 37 public: ~Window(void)38 virtual ~Window (void) {} 39 40 virtual void setVisible (bool visible); 41 virtual void setForeground (void); 42 virtual void resize (const tcu::UVec2& newSize); 43 44 protected: Window(void)45 Window (void) {} 46 47 private: 48 Window (const Window&); // Not allowed 49 Window& operator= (const Window&); // Not allowed 50 }; 51 52 class Display 53 { 54 public: ~Display(void)55 virtual ~Display (void) {} 56 57 virtual Window* createWindow (const tcu::Maybe<tcu::UVec2>& initialSize = tcu::nothing<tcu::UVec2>()) const = 0; 58 59 protected: Display(void)60 Display (void) {} 61 62 private: 63 Display (const Display&); // Not allowed 64 Display& operator= (const Display&); // Not allowed 65 }; 66 67 // WSI implementation-specific APIs 68 69 template<int WsiType> 70 struct TypeTraits; 71 // { 72 // typedef <NativeDisplayType> NativeDisplayType; 73 // typedef <NativeWindowType> NativeWindowType; 74 // }; 75 76 template<int WsiType> 77 struct DisplayInterface : public Display 78 { 79 public: 80 typedef typename TypeTraits<WsiType>::NativeDisplayType NativeType; 81 getNativevk::wsi::DisplayInterface82 NativeType getNative (void) const { return m_native; } 83 84 protected: DisplayInterfacevk::wsi::DisplayInterface85 DisplayInterface (NativeType nativeDisplay) 86 : m_native(nativeDisplay) 87 {} 88 89 const NativeType m_native; 90 }; 91 92 template<int WsiType> 93 struct WindowInterface : public Window 94 { 95 public: 96 typedef typename TypeTraits<WsiType>::NativeWindowType NativeType; 97 getNativevk::wsi::WindowInterface98 NativeType getNative (void) const { return m_native; } 99 100 protected: WindowInterfacevk::wsi::WindowInterface101 WindowInterface (NativeType nativeDisplay) 102 : m_native(nativeDisplay) 103 {} 104 105 const NativeType m_native; 106 }; 107 108 // VK_KHR_xlib_surface 109 110 template<> 111 struct TypeTraits<TYPE_XLIB> 112 { 113 typedef pt::XlibDisplayPtr NativeDisplayType; 114 typedef pt::XlibWindow NativeWindowType; 115 }; 116 117 typedef DisplayInterface<TYPE_XLIB> XlibDisplayInterface; 118 typedef WindowInterface<TYPE_XLIB> XlibWindowInterface; 119 120 // VK_KHR_xcb_surface 121 122 template<> 123 struct TypeTraits<TYPE_XCB> 124 { 125 typedef pt::XcbConnectionPtr NativeDisplayType; 126 typedef pt::XcbWindow NativeWindowType; 127 }; 128 129 typedef DisplayInterface<TYPE_XCB> XcbDisplayInterface; 130 typedef WindowInterface<TYPE_XCB> XcbWindowInterface; 131 132 // VK_KHR_wayland_surface 133 134 template<> 135 struct TypeTraits<TYPE_WAYLAND> 136 { 137 typedef pt::WaylandDisplayPtr NativeDisplayType; 138 typedef pt::WaylandSurfacePtr NativeWindowType; 139 }; 140 141 typedef DisplayInterface<TYPE_WAYLAND> WaylandDisplayInterface; 142 typedef WindowInterface<TYPE_WAYLAND> WaylandWindowInterface; 143 144 // VK_KHR_mir_surface 145 146 // VK_KHR_android_surface 147 148 template<> 149 struct TypeTraits<TYPE_ANDROID> 150 { 151 typedef pt::AndroidNativeWindowPtr NativeWindowType; 152 }; 153 154 typedef WindowInterface<TYPE_ANDROID> AndroidWindowInterface; 155 156 // VK_KHR_win32_surface 157 158 template<> 159 struct TypeTraits<TYPE_WIN32> 160 { 161 typedef pt::Win32InstanceHandle NativeDisplayType; 162 typedef pt::Win32WindowHandle NativeWindowType; 163 }; 164 165 typedef DisplayInterface<TYPE_WIN32> Win32DisplayInterface; 166 typedef WindowInterface<TYPE_WIN32> Win32WindowInterface; 167 168 // VK_MVK_macos_surface 169 170 template<> 171 struct TypeTraits<TYPE_MACOS> 172 { 173 typedef void* NativeWindowType; 174 }; 175 176 typedef WindowInterface<TYPE_MACOS> MacOSWindowInterface; 177 178 } // wsi 179 } // vk 180 181 #endif // _VKWSIPLATFORM_HPP 182