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 resize (const tcu::UVec2& newSize); 41 42 protected: Window(void)43 Window (void) {} 44 45 private: 46 Window (const Window&); // Not allowed 47 Window& operator= (const Window&); // Not allowed 48 }; 49 50 class Display 51 { 52 public: ~Display(void)53 virtual ~Display (void) {} 54 55 virtual Window* createWindow (const tcu::Maybe<tcu::UVec2>& initialSize = tcu::nothing<tcu::UVec2>()) const = 0; 56 57 protected: Display(void)58 Display (void) {} 59 60 private: 61 Display (const Display&); // Not allowed 62 Display& operator= (const Display&); // Not allowed 63 }; 64 65 // WSI implementation-specific APIs 66 67 template<int WsiType> 68 struct TypeTraits; 69 // { 70 // typedef <NativeDisplayType> NativeDisplayType; 71 // typedef <NativeWindowType> NativeWindowType; 72 // }; 73 74 template<int WsiType> 75 struct DisplayInterface : public Display 76 { 77 public: 78 typedef typename TypeTraits<WsiType>::NativeDisplayType NativeType; 79 getNativevk::wsi::DisplayInterface80 NativeType getNative (void) const { return m_native; } 81 82 protected: DisplayInterfacevk::wsi::DisplayInterface83 DisplayInterface (NativeType nativeDisplay) 84 : m_native(nativeDisplay) 85 {} 86 87 const NativeType m_native; 88 }; 89 90 template<int WsiType> 91 struct WindowInterface : public Window 92 { 93 public: 94 typedef typename TypeTraits<WsiType>::NativeWindowType NativeType; 95 getNativevk::wsi::WindowInterface96 NativeType getNative (void) const { return m_native; } 97 98 protected: WindowInterfacevk::wsi::WindowInterface99 WindowInterface (NativeType nativeDisplay) 100 : m_native(nativeDisplay) 101 {} 102 103 const NativeType m_native; 104 }; 105 106 // VK_KHR_xlib_surface 107 108 template<> 109 struct TypeTraits<TYPE_XLIB> 110 { 111 typedef pt::XlibDisplayPtr NativeDisplayType; 112 typedef pt::XlibWindow NativeWindowType; 113 }; 114 115 typedef DisplayInterface<TYPE_XLIB> XlibDisplayInterface; 116 typedef WindowInterface<TYPE_XLIB> XlibWindowInterface; 117 118 // VK_KHR_xcb_surface 119 120 template<> 121 struct TypeTraits<TYPE_XCB> 122 { 123 typedef pt::XcbConnectionPtr NativeDisplayType; 124 typedef pt::XcbWindow NativeWindowType; 125 }; 126 127 typedef DisplayInterface<TYPE_XCB> XcbDisplayInterface; 128 typedef WindowInterface<TYPE_XCB> XcbWindowInterface; 129 130 // VK_KHR_wayland_surface 131 132 template<> 133 struct TypeTraits<TYPE_WAYLAND> 134 { 135 typedef pt::WaylandDisplayPtr NativeDisplayType; 136 typedef pt::WaylandSurfacePtr NativeWindowType; 137 }; 138 139 typedef DisplayInterface<TYPE_WAYLAND> WaylandDisplayInterface; 140 typedef WindowInterface<TYPE_WAYLAND> WaylandWindowInterface; 141 142 // VK_KHR_mir_surface 143 144 // VK_KHR_android_surface 145 146 template<> 147 struct TypeTraits<TYPE_ANDROID> 148 { 149 typedef pt::AndroidNativeWindowPtr NativeWindowType; 150 }; 151 152 typedef WindowInterface<TYPE_ANDROID> AndroidWindowInterface; 153 154 // VK_KHR_win32_surface 155 156 template<> 157 struct TypeTraits<TYPE_WIN32> 158 { 159 typedef pt::Win32InstanceHandle NativeDisplayType; 160 typedef pt::Win32WindowHandle NativeWindowType; 161 }; 162 163 typedef DisplayInterface<TYPE_WIN32> Win32DisplayInterface; 164 typedef WindowInterface<TYPE_WIN32> Win32WindowInterface; 165 166 // VK_MVK_macos_surface 167 168 template<> 169 struct TypeTraits<TYPE_MACOS> 170 { 171 typedef void* NativeWindowType; 172 }; 173 174 typedef WindowInterface<TYPE_MACOS> MacOSWindowInterface; 175 176 } // wsi 177 } // vk 178 179 #endif // _VKWSIPLATFORM_HPP 180