1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief X11Egl Platform.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuX11EglPlatform.hpp"
25 #include "egluGLContextFactory.hpp"
26 #include "eglwLibrary.hpp"
27 #include "eglwFunctions.hpp"
28 #include "eglwEnums.hpp"
37 typedef ::Display* EGLNativeDisplayType;
38 typedef ::Pixmap EGLNativePixmapType;
39 typedef ::Window EGLNativeWindowType;
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));
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);
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;
70 class Library : public eglw::DefaultLibrary
74 : eglw::DefaultLibrary("libEGL.so")
78 eglw::EGLBoolean copyBuffers (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLNativePixmapType target) const
80 return ((eglX11CopyBuffersFunc)m_egl.copyBuffers)(dpy, surface, reinterpret_cast<EGLNativePixmapType>(target));
83 eglw::EGLSurface createPixmapSurface (eglw::EGLDisplay dpy, eglw::EGLConfig config, eglw::EGLNativePixmapType pixmap, const eglw::EGLint *attrib_list) const
85 return ((eglX11CreatePixmapSurfaceFunc)m_egl.createPixmapSurface)(dpy, config, reinterpret_cast<EGLNativePixmapType>(pixmap), attrib_list);
88 eglw::EGLSurface createWindowSurface (eglw::EGLDisplay dpy, eglw::EGLConfig config, eglw::EGLNativeWindowType win, const eglw::EGLint *attrib_list) const
90 return ((eglX11CreateWindowSurfaceFunc)m_egl.createWindowSurface)(dpy, config, reinterpret_cast<EGLNativeWindowType>(win), attrib_list);
93 eglw::EGLDisplay getDisplay (eglw::EGLNativeDisplayType display_id) const
95 return ((eglX11GetDisplayFunc)m_egl.getDisplay)(reinterpret_cast<EGLNativeDisplayType>(display_id));
99 class Display : public NativeDisplay
102 static const Capability CAPABILITIES = Capability(CAPABILITY_GET_DISPLAY_LEGACY |
103 CAPABILITY_GET_DISPLAY_PLATFORM);
105 Display (MovePtr<XlibDisplay> x11Display)
106 : NativeDisplay (CAPABILITIES,
107 EGL_PLATFORM_X11_EXT,
108 "EGL_EXT_platform_x11")
109 , m_display (x11Display) {}
111 void* getPlatformNative (void) { return m_display->getXDisplay(); }
112 eglw::EGLNativeDisplayType getLegacyNative (void) { return reinterpret_cast<eglw::EGLNativeDisplayType>(m_display->getXDisplay()); }
114 XlibDisplay& getX11Display (void) { return *m_display; }
115 const eglw::Library& getLibrary (void) const { return m_library; }
116 const eglw::EGLAttrib* getPlatformAttributes (void) const { return DE_NULL; }
119 UniquePtr<XlibDisplay> m_display;
123 class Window : public NativeWindow
126 static const Capability CAPABILITIES = Capability(CAPABILITY_CREATE_SURFACE_LEGACY |
127 CAPABILITY_CREATE_SURFACE_PLATFORM |
128 CAPABILITY_GET_SURFACE_SIZE |
129 CAPABILITY_SET_SURFACE_SIZE |
130 CAPABILITY_GET_SCREEN_SIZE);
132 Window (Display& display,
133 const WindowParams& params,
136 eglw::EGLNativeWindowType getLegacyNative (void) { return reinterpret_cast<eglw::EGLNativeWindowType>(m_window.getXID()); }
137 void* getPlatformNative (void) { return &m_window.getXID(); }
139 IVec2 getSurfaceSize (void) const;
140 void setSurfaceSize (IVec2 size);
141 IVec2 getScreenSize (void) const { return getSurfaceSize(); }
147 Window::Window (Display& display, const WindowParams& params, Visual* visual)
148 : NativeWindow (CAPABILITIES)
149 , m_window (display.getX11Display(), params.width, params.height, visual)
151 m_window.setVisibility((params.visibility != WindowParams::VISIBILITY_HIDDEN));
154 IVec2 Window::getSurfaceSize (void) const
157 m_window.getDimensions(&ret.x(), &ret.y());
161 void Window::setSurfaceSize (IVec2 size)
163 m_window.setDimensions(size.x(), size.y());
166 class WindowFactory : public NativeWindowFactory
169 WindowFactory (void);
171 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
172 const WindowParams& params) const;
174 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
175 eglw::EGLDisplay display,
176 eglw::EGLConfig config,
177 const eglw::EGLAttrib* attribList,
178 const WindowParams& params) const;
181 WindowFactory::WindowFactory (void)
182 : NativeWindowFactory ("window", "X11 Window", Window::CAPABILITIES)
186 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
187 const WindowParams& params) const
189 Display& display = *dynamic_cast<Display*>(nativeDisplay);
191 return new Window(display, params, DE_NULL);
194 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
195 eglw::EGLDisplay eglDisplay,
196 eglw::EGLConfig config,
197 const eglw::EGLAttrib* attribList,
198 const WindowParams& params) const
200 DE_UNREF(attribList);
202 Display& display = *dynamic_cast<Display*>(nativeDisplay);
203 eglw::EGLint visualID = 0;
204 ::Visual* visual = DE_NULL;
205 nativeDisplay->getLibrary().getConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &visualID);
208 visual = display.getX11Display().getVisual(visualID);
210 return new Window(display, params, visual);
214 class Pixmap : public NativePixmap
218 CAPABILITIES = (CAPABILITY_CREATE_SURFACE_LEGACY |
219 CAPABILITY_CREATE_SURFACE_PLATFORM |
220 CAPABILITY_READ_PIXELS)
223 Pixmap (MovePtr<x11::Pixmap> x11Pixmap)
224 : NativePixmap (CAPABILITIES)
225 , m_pixmap (x11Pixmap) {}
227 void* getPlatformNative (void) { return &m_pixmap.getXID(); }
228 void readPixels (TextureLevel* dst);
231 UniquePtr<x11::Pixmap> m_pixmap;
234 class PixmapFactory : public NativePixmapFactory
238 : NativePixmapFactory ("pixmap", "X11 Pixmap", Pixmap::CAPABILITIES) {}
240 NativePixmap* createPixmap (NativeDisplay* nativeDisplay,
245 NativePixmap* PixmapFactory::createPixmap (NativeDisplay* nativeDisplay,
250 Display* display = dynamic_cast<Display*>(nativeDisplay);
251 MovePtr<x11::Pixmap> x11Pixmap (new x11::Pixmap(display->getX11Display(),
253 return new Pixmap(x11Pixmap);
257 class DisplayFactory : public NativeDisplayFactory
260 DisplayFactory (EventState& eventState);
262 NativeDisplay* createDisplay (const eglw::EGLAttrib* attribList) const;
265 EventState& m_eventState;
268 DisplayFactory::DisplayFactory (EventState& eventState)
269 : NativeDisplayFactory ("x11", "Native X11 Display",
270 Display::CAPABILITIES,
271 EGL_PLATFORM_X11_SCREEN_EXT,
272 "EGL_EXT_platform_x11")
273 , m_eventState (eventState)
275 m_nativeWindowRegistry.registerFactory(new WindowFactory());
276 // m_nativePixmapRegistry.registerFactory(new PixmapFactory());
279 NativeDisplay* DisplayFactory::createDisplay (const eglw::EGLAttrib* attribList) const
281 DE_UNREF(attribList);
283 //! \todo [2014-03-18 lauri] Somehow make the display configurable from command line
284 MovePtr<XlibDisplay> x11Display (new XlibDisplay(m_eventState, DE_NULL));
286 return new Display(x11Display);
289 Platform::Platform (EventState& eventState)
291 m_nativeDisplayFactoryRegistry.registerFactory(new DisplayFactory(eventState));
294 MovePtr<ContextFactory> Platform::createContextFactory (void)
296 return MovePtr<ContextFactory>(new GLContextFactory(m_nativeDisplayFactoryRegistry));