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