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 "tcuCommandLine.hpp" 28 #include "tcuVector.hpp" 29 #include "tcuMaybe.hpp" 30 31 namespace vk 32 { 33 namespace wsi 34 { 35 36 class Window 37 { 38 public: ~Window(void)39 virtual ~Window (void) {} 40 41 virtual void setVisible (bool visible); 42 virtual void setForeground (void); 43 virtual void resize (const tcu::UVec2& newSize); 44 45 protected: Window(void)46 Window (void) {} 47 48 private: 49 Window (const Window&); // Not allowed 50 Window& operator= (const Window&); // Not allowed 51 }; 52 53 class Display 54 { 55 public: ~Display(void)56 virtual ~Display (void) {} 57 58 virtual Window* createWindow (const tcu::Maybe<tcu::UVec2>& initialSize = tcu::Nothing) const = 0; 59 60 protected: Display(void)61 Display (void) {} 62 63 private: 64 Display (const Display&); // Not allowed 65 Display& operator= (const Display&); // Not allowed 66 }; 67 68 // WSI implementation-specific APIs 69 70 template<int WsiType> 71 struct TypeTraits; 72 // { 73 // typedef <NativeDisplayType> NativeDisplayType; 74 // typedef <NativeWindowType> NativeWindowType; 75 // }; 76 77 template<int WsiType> 78 struct DisplayInterface : public Display 79 { 80 public: 81 typedef typename TypeTraits<WsiType>::NativeDisplayType NativeType; 82 getNativevk::wsi::DisplayInterface83 NativeType getNative (void) const { return m_native; } 84 85 protected: DisplayInterfacevk::wsi::DisplayInterface86 DisplayInterface (NativeType nativeDisplay) 87 : m_native(nativeDisplay) 88 {} 89 90 const NativeType m_native; 91 }; 92 93 template<int WsiType> 94 struct WindowInterface : public Window 95 { 96 public: 97 typedef typename TypeTraits<WsiType>::NativeWindowType NativeType; 98 getNativevk::wsi::WindowInterface99 NativeType getNative (void) const { return m_native; } 100 101 protected: WindowInterfacevk::wsi::WindowInterface102 WindowInterface (NativeType nativeDisplay) 103 : m_native(nativeDisplay) 104 {} 105 106 const NativeType m_native; 107 }; 108 109 // VK_KHR_xlib_surface 110 111 template<> 112 struct TypeTraits<TYPE_XLIB> 113 { 114 typedef pt::XlibDisplayPtr NativeDisplayType; 115 typedef pt::XlibWindow NativeWindowType; 116 }; 117 118 typedef DisplayInterface<TYPE_XLIB> XlibDisplayInterface; 119 typedef WindowInterface<TYPE_XLIB> XlibWindowInterface; 120 121 // VK_KHR_xcb_surface 122 123 template<> 124 struct TypeTraits<TYPE_XCB> 125 { 126 typedef pt::XcbConnectionPtr NativeDisplayType; 127 typedef pt::XcbWindow NativeWindowType; 128 }; 129 130 typedef DisplayInterface<TYPE_XCB> XcbDisplayInterface; 131 typedef WindowInterface<TYPE_XCB> XcbWindowInterface; 132 133 // VK_KHR_wayland_surface 134 135 template<> 136 struct TypeTraits<TYPE_WAYLAND> 137 { 138 typedef pt::WaylandDisplayPtr NativeDisplayType; 139 typedef pt::WaylandSurfacePtr NativeWindowType; 140 }; 141 142 typedef DisplayInterface<TYPE_WAYLAND> WaylandDisplayInterface; 143 typedef WindowInterface<TYPE_WAYLAND> WaylandWindowInterface; 144 145 // VK_EXT_acquire_drm_display 146 147 template<> 148 struct TypeTraits<TYPE_DIRECT_DRM> 149 { 150 typedef VkDisplayKHR NativeDisplayType; 151 }; 152 153 struct DirectDrmDisplayInterface : public DisplayInterface<TYPE_DIRECT_DRM> 154 { 155 public: DirectDrmDisplayInterfacevk::wsi::DirectDrmDisplayInterface156 DirectDrmDisplayInterface (void) 157 : DisplayInterface(DE_NULL) 158 {} initializeDisplayvk::wsi::DirectDrmDisplayInterface159 virtual void initializeDisplay (const InstanceInterface& vki, VkInstance instance, const tcu::CommandLine& cmdLine) 160 { 161 DE_UNREF(vki); 162 DE_UNREF(instance); 163 DE_UNREF(cmdLine); 164 } 165 }; 166 167 // VK_KHR_mir_surface 168 169 // VK_KHR_android_surface 170 171 template<> 172 struct TypeTraits<TYPE_ANDROID> 173 { 174 typedef pt::AndroidNativeWindowPtr NativeWindowType; 175 }; 176 177 typedef WindowInterface<TYPE_ANDROID> AndroidWindowInterface; 178 179 // VK_KHR_win32_surface 180 181 template<> 182 struct TypeTraits<TYPE_WIN32> 183 { 184 typedef pt::Win32InstanceHandle NativeDisplayType; 185 typedef pt::Win32WindowHandle NativeWindowType; 186 }; 187 188 typedef DisplayInterface<TYPE_WIN32> Win32DisplayInterface; 189 typedef WindowInterface<TYPE_WIN32> Win32WindowInterface; 190 191 // VK_MVK_macos_surface 192 193 template<> 194 struct TypeTraits<TYPE_MACOS> 195 { 196 typedef void* NativeWindowType; 197 }; 198 199 typedef WindowInterface<TYPE_MACOS> MacOSWindowInterface; 200 201 // VK_OpenHarmony_OHOS_surface 202 203 template<> 204 struct TypeTraits<TYPE_OHOS> 205 { 206 typedef pt::OhosNativeWindowPtr NativeWindowType; 207 }; 208 209 typedef WindowInterface<TYPE_OHOS> OhosWindowInterface; 210 211 } // wsi 212 } // vk 213 214 #endif // _VKWSIPLATFORM_HPP 215