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