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