• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief X11Egl Platform.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuX11EglPlatform.hpp"
25 #include "egluGLContextFactory.hpp"
26 #include "eglwLibrary.hpp"
27 #include "eglwFunctions.hpp"
28 #include "eglwEnums.hpp"
29 
30 namespace tcu
31 {
32 namespace x11
33 {
34 namespace egl
35 {
36 
37 typedef ::Display*	EGLNativeDisplayType;
38 typedef ::Pixmap	EGLNativePixmapType;
39 typedef ::Window	EGLNativeWindowType;
40 
41 DE_STATIC_ASSERT(sizeof(EGLNativeDisplayType)	<= sizeof(eglw::EGLNativeDisplayType));
42 DE_STATIC_ASSERT(sizeof(EGLNativePixmapType)	<= sizeof(eglw::EGLNativePixmapType));
43 DE_STATIC_ASSERT(sizeof(EGLNativeWindowType)	<= sizeof(eglw::EGLNativeWindowType));
44 
45 extern "C"
46 {
47 
48 typedef EGLW_APICALL	eglw::EGLDisplay	(EGLW_APIENTRY* eglX11GetDisplayFunc)			(EGLNativeDisplayType display_id);
49 typedef EGLW_APICALL	eglw::EGLBoolean	(EGLW_APIENTRY* eglX11CopyBuffersFunc)			(eglw::EGLDisplay dpy, eglw::EGLSurface surface, EGLNativePixmapType target);
50 typedef EGLW_APICALL	eglw::EGLSurface	(EGLW_APIENTRY* eglX11CreatePixmapSurfaceFunc)	(eglw::EGLDisplay dpy, eglw::EGLConfig config, EGLNativePixmapType pixmap, const eglw::EGLint* attrib_list);
51 typedef EGLW_APICALL	eglw::EGLSurface	(EGLW_APIENTRY* eglX11CreateWindowSurfaceFunc)	(eglw::EGLDisplay dpy, eglw::EGLConfig config, EGLNativeWindowType win, const eglw::EGLint* attrib_list);
52 
53 }
54 
55 using std::string;
56 
57 using de::MovePtr;
58 using de::UniquePtr;
59 using glu::ContextFactory;
60 using eglu::GLContextFactory;
61 using eglu::NativeDisplay;
62 using eglu::NativeDisplayFactory;
63 using eglu::NativeWindow;
64 using eglu::NativeWindowFactory;
65 using eglu::NativePixmap;
66 using eglu::NativePixmapFactory;
67 using eglu::WindowParams;
68 using tcu::TextureLevel;
69 
70 class Library : public eglw::DefaultLibrary
71 {
72 public:
Library(void)73 	Library (void)
74 		: eglw::DefaultLibrary("libEGL.so")
75 	{
76 	}
77 
copyBuffers(eglw::EGLDisplay dpy,eglw::EGLSurface surface,eglw::EGLNativePixmapType target) const78 	eglw::EGLBoolean copyBuffers (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLNativePixmapType target) const
79 	{
80 		return ((eglX11CopyBuffersFunc)m_egl.copyBuffers)(dpy, surface, reinterpret_cast<EGLNativePixmapType>(target));
81 	}
82 
createPixmapSurface(eglw::EGLDisplay dpy,eglw::EGLConfig config,eglw::EGLNativePixmapType pixmap,const eglw::EGLint * attrib_list) const83 	eglw::EGLSurface createPixmapSurface (eglw::EGLDisplay dpy, eglw::EGLConfig config, eglw::EGLNativePixmapType pixmap, const eglw::EGLint *attrib_list) const
84 	{
85 		return ((eglX11CreatePixmapSurfaceFunc)m_egl.createPixmapSurface)(dpy, config, reinterpret_cast<EGLNativePixmapType>(pixmap), attrib_list);
86 	}
87 
createWindowSurface(eglw::EGLDisplay dpy,eglw::EGLConfig config,eglw::EGLNativeWindowType win,const eglw::EGLint * attrib_list) const88 	eglw::EGLSurface createWindowSurface (eglw::EGLDisplay dpy, eglw::EGLConfig config, eglw::EGLNativeWindowType win, const eglw::EGLint *attrib_list) const
89 	{
90 		return ((eglX11CreateWindowSurfaceFunc)m_egl.createWindowSurface)(dpy, config, reinterpret_cast<EGLNativeWindowType>(win), attrib_list);
91 	}
92 
getDisplay(eglw::EGLNativeDisplayType display_id) const93 	eglw::EGLDisplay getDisplay (eglw::EGLNativeDisplayType display_id) const
94 	{
95 		return ((eglX11GetDisplayFunc)m_egl.getDisplay)(reinterpret_cast<EGLNativeDisplayType>(display_id));
96 	}
97 };
98 
99 class Display : public NativeDisplay
100 {
101 public:
102 	static const Capability CAPABILITIES 		= Capability(CAPABILITY_GET_DISPLAY_LEGACY |
103 															 CAPABILITY_GET_DISPLAY_PLATFORM);
104 
Display(MovePtr<x11::Display> x11Display)105 								Display				(MovePtr<x11::Display> x11Display)
106 									: NativeDisplay	(CAPABILITIES,
107 													 EGL_PLATFORM_X11_EXT,
108 													 "EGL_EXT_platform_x11")
109 									, m_display		(x11Display) {}
110 
getPlatformNative(void)111 	void*						getPlatformNative	(void) 	{ return m_display->getXDisplay(); }
getLegacyNative(void)112 	eglw::EGLNativeDisplayType	getLegacyNative		(void)	{ return reinterpret_cast<eglw::EGLNativeDisplayType>(m_display->getXDisplay()); }
113 
getX11Display(void)114 	x11::Display&				getX11Display		(void)			{ return *m_display;	}
getLibrary(void) const115 	const eglw::Library&		getLibrary			(void) const	{ return m_library;		}
116 
117 private:
118 	UniquePtr<x11::Display>		m_display;
119 	Library						m_library;
120 };
121 
122 class Window : public NativeWindow
123 {
124 public:
125 	static const Capability	CAPABILITIES		= Capability(CAPABILITY_CREATE_SURFACE_LEGACY |
126 															 CAPABILITY_CREATE_SURFACE_PLATFORM |
127 															 CAPABILITY_GET_SURFACE_SIZE |
128 															 CAPABILITY_SET_SURFACE_SIZE |
129 															 CAPABILITY_GET_SCREEN_SIZE);
130 
131 								Window				(Display&				display,
132 													 const WindowParams&	params,
133 													 Visual*				visual);
134 
getLegacyNative(void)135 	eglw::EGLNativeWindowType	getLegacyNative		(void) { return reinterpret_cast<eglw::EGLNativeWindowType>(m_window.getXID()); }
getPlatformNative(void)136 	void*						getPlatformNative	(void) { return &m_window.getXID();	}
137 
138 	IVec2						getSurfaceSize		(void) const;
139 	void						setSurfaceSize		(IVec2 size);
getScreenSize(void) const140 	IVec2						getScreenSize		(void) const { return getSurfaceSize(); }
141 
142 private:
143 	x11::Window					m_window;
144 };
145 
Window(Display & display,const WindowParams & params,Visual * visual)146 Window::Window (Display& display, const WindowParams& params, Visual* visual)
147 	: NativeWindow	(CAPABILITIES)
148 	, m_window		(display.getX11Display(), params.width, params.height, visual)
149 {
150 	m_window.setVisibility((params.visibility != WindowParams::VISIBILITY_HIDDEN));
151 }
152 
getSurfaceSize(void) const153 IVec2 Window::getSurfaceSize (void) const
154 {
155 	IVec2 ret;
156 	m_window.getDimensions(&ret.x(), &ret.y());
157 	return ret;
158 }
159 
setSurfaceSize(IVec2 size)160 void Window::setSurfaceSize (IVec2 size)
161 {
162 	m_window.setDimensions(size.x(), size.y());
163 }
164 
165 class WindowFactory : public NativeWindowFactory
166 {
167 public:
168 						WindowFactory		(void);
169 
170 	NativeWindow*		createWindow		(NativeDisplay*			nativeDisplay,
171 											 const WindowParams&	params) const;
172 
173 	NativeWindow*		createWindow		(NativeDisplay*			nativeDisplay,
174 											 eglw::EGLDisplay		display,
175 											 eglw::EGLConfig		config,
176 											 const eglw::EGLAttrib*	attribList,
177 											 const WindowParams&	params) const;
178 };
179 
WindowFactory(void)180 WindowFactory::WindowFactory (void)
181 	: NativeWindowFactory ("window", "X11 Window", Window::CAPABILITIES)
182 {
183 }
184 
createWindow(NativeDisplay * nativeDisplay,const WindowParams & params) const185 NativeWindow* WindowFactory::createWindow (NativeDisplay*		nativeDisplay,
186 										   const WindowParams&	params) const
187 {
188 	Display&	display	= *dynamic_cast<Display*>(nativeDisplay);
189 
190 	return new Window(display, params, DE_NULL);
191 }
192 
createWindow(NativeDisplay * nativeDisplay,eglw::EGLDisplay eglDisplay,eglw::EGLConfig config,const eglw::EGLAttrib * attribList,const WindowParams & params) const193 NativeWindow* WindowFactory::createWindow (NativeDisplay*			nativeDisplay,
194 										   eglw::EGLDisplay			eglDisplay,
195 										   eglw::EGLConfig			config,
196 										   const eglw::EGLAttrib*	attribList,
197 										   const WindowParams&		params) const
198 {
199 	DE_UNREF(attribList);
200 
201 	Display&		display		= *dynamic_cast<Display*>(nativeDisplay);
202 	eglw::EGLint	visualID	= 0;
203 	::Visual*		visual		= DE_NULL;
204 	nativeDisplay->getLibrary().getConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &visualID);
205 
206 	if (visualID != 0)
207 		visual = display.getX11Display().getVisual(visualID);
208 
209 	return new Window(display, params, visual);
210 }
211 
212 #if 0
213 class Pixmap : public NativePixmap
214 {
215 public:
216 	enum {
217 		CAPABILITIES = (CAPABILITY_CREATE_SURFACE_LEGACY |
218 						CAPABILITY_CREATE_SURFACE_PLATFORM |
219 						CAPABILITY_READ_PIXELS)
220 	};
221 
222 							Pixmap				(MovePtr<x11::Pixmap> x11Pixmap)
223 								: NativePixmap	(CAPABILITIES)
224 								, m_pixmap		(x11Pixmap) {}
225 
226 	void*					getPlatformNative	(void) { return &m_pixmap.getXID(); }
227 	void					readPixels			(TextureLevel* dst);
228 
229 private:
230 	UniquePtr<x11::Pixmap>	m_pixmap;
231 };
232 
233 class PixmapFactory : public NativePixmapFactory
234 {
235 public:
236 					PixmapFactory	(void)
237 						: NativePixmapFactory ("pixmap", "X11 Pixmap", Pixmap::CAPABILITIES) {}
238 
239 	NativePixmap*	createPixmap	(NativeDisplay* nativeDisplay,
240 									 int			width,
241 									 int			height) const;
242 };
243 
244 NativePixmap* PixmapFactory::createPixmap (NativeDisplay* nativeDisplay,
245 										   int			width,
246 										   int			height) const
247 
248 {
249 	Display*				display		= dynamic_cast<Display*>(nativeDisplay);
250 	MovePtr<x11::Pixmap>	x11Pixmap	(new x11::Pixmap(display->getX11Display(),
251 														 width, height));
252 	return new Pixmap(x11Pixmap);
253 }
254 #endif
255 
256 class DisplayFactory : public NativeDisplayFactory
257 {
258 public:
259 						DisplayFactory		(EventState& eventState);
260 
261 	NativeDisplay*		createDisplay		(const eglw::EGLAttrib* attribList) const;
262 
263 private:
264 	EventState&			m_eventState;
265 };
266 
DisplayFactory(EventState & eventState)267 DisplayFactory::DisplayFactory (EventState& eventState)
268 	: NativeDisplayFactory	("x11", "Native X11 Display",
269 							 Display::CAPABILITIES,
270 							 EGL_PLATFORM_X11_SCREEN_EXT,
271 							 "EGL_EXT_platform_x11")
272 	, m_eventState			(eventState)
273 {
274 	m_nativeWindowRegistry.registerFactory(new WindowFactory());
275 	// m_nativePixmapRegistry.registerFactory(new PixmapFactory());
276 }
277 
createDisplay(const eglw::EGLAttrib * attribList) const278 NativeDisplay* DisplayFactory::createDisplay (const eglw::EGLAttrib* attribList) const
279 {
280 	DE_UNREF(attribList);
281 
282 	//! \todo [2014-03-18 lauri] Somehow make the display configurable from command line
283 	MovePtr<x11::Display>	x11Display	(new x11::Display(m_eventState, DE_NULL));
284 
285 	return new Display(x11Display);
286 }
287 
Platform(EventState & eventState)288 Platform::Platform (EventState& eventState)
289 {
290 	m_nativeDisplayFactoryRegistry.registerFactory(new DisplayFactory(eventState));
291 }
292 
createContextFactory(void)293 MovePtr<ContextFactory> Platform::createContextFactory (void)
294 {
295 	return MovePtr<ContextFactory>(new GLContextFactory(m_nativeDisplayFactoryRegistry));
296 }
297 
298 
299 } // egl
300 } // x11
301 } // tcu
302