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