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"
26 #include "egluGLContextFactory.hpp"
39 using glu::ContextFactory;
40 using eglu::GLContextFactory;
41 using eglu::NativeDisplay;
42 using eglu::NativeDisplayFactory;
43 using eglu::NativeWindow;
44 using eglu::NativeWindowFactory;
45 using eglu::NativePixmap;
46 using eglu::NativePixmapFactory;
47 using eglu::WindowParams;
48 using tcu::TextureLevel;
50 #ifndef EGL_PLATFORM_X11_EXT
51 # define EGL_PLATFORM_X11_EXT 0x31D5
53 #ifndef EGL_PLATFORM_X11_SCREEN_EXT
54 # define EGL_PLATFORM_X11_SCREEN_EXT 0x31D6
57 class Display : public NativeDisplay
60 static const Capability CAPABILITIES = Capability(CAPABILITY_GET_DISPLAY_LEGACY |
61 CAPABILITY_GET_DISPLAY_PLATFORM);
63 Display (MovePtr<x11::Display> x11Display)
64 : NativeDisplay (CAPABILITIES,
66 "EGL_EXT_platform_x11")
67 , m_display (x11Display) {}
69 void* getPlatformNative (void) { return m_display->getXDisplay(); }
70 EGLNativeDisplayType getLegacyNative (void) { return m_display->getXDisplay(); }
72 x11::Display& getX11Display (void) { return *m_display; }
75 UniquePtr<x11::Display> m_display;
79 class Window : public NativeWindow
82 static const Capability CAPABILITIES = Capability(CAPABILITY_CREATE_SURFACE_LEGACY |
83 CAPABILITY_CREATE_SURFACE_PLATFORM |
84 CAPABILITY_GET_SURFACE_SIZE |
85 CAPABILITY_SET_SURFACE_SIZE |
86 CAPABILITY_GET_SCREEN_SIZE);
88 Window (Display& display,
89 const WindowParams& params,
92 EGLNativeWindowType getLegacyNative (void) { return m_window.getXID(); }
93 void* getPlatformNative (void) { return &m_window.getXID(); }
94 IVec2 getSurfaceSize (void) const;
95 void setSurfaceSize (IVec2 size);
96 IVec2 getScreenSize (void) const { return getSurfaceSize(); }
102 Window::Window(Display& display, const WindowParams& params, Visual* visual)
103 : NativeWindow (CAPABILITIES)
104 , m_window (display.getX11Display(), params.width, params.height, visual)
106 m_window.setVisibility((params.visibility != WindowParams::VISIBILITY_HIDDEN));
109 IVec2 Window::getSurfaceSize (void) const
112 m_window.getDimensions(&ret.x(), &ret.y());
116 void Window::setSurfaceSize (IVec2 size)
118 m_window.setDimensions(size.x(), size.y());
121 class WindowFactory : public NativeWindowFactory
124 WindowFactory (void);
126 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
127 const WindowParams& params) const;
129 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
132 const EGLAttrib* attribList,
133 const WindowParams& params) const;
136 WindowFactory::WindowFactory (void)
137 : NativeWindowFactory ("window", "X11 Window", Window::CAPABILITIES)
141 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
142 const WindowParams& params) const
144 Display& display = *dynamic_cast<Display*>(nativeDisplay);
146 return new Window(display, params, DE_NULL);
149 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
150 EGLDisplay eglDisplay,
152 const EGLAttrib* attribList,
153 const WindowParams& params) const
155 DE_UNREF(attribList);
157 Display& display = *dynamic_cast<Display*>(nativeDisplay);
159 ::Visual* visual = DE_NULL;
160 eglGetConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &visualID);
163 visual = display.getX11Display().getVisual(visualID);
165 return new Window(display, params, visual);
169 class Pixmap : public NativePixmap
173 CAPABILITIES = (CAPABILITY_CREATE_SURFACE_LEGACY |
174 CAPABILITY_CREATE_SURFACE_PLATFORM |
175 CAPABILITY_READ_PIXELS)
178 Pixmap (MovePtr<x11::Pixmap> x11Pixmap)
179 : NativePixmap (CAPABILITIES)
180 , m_pixmap (x11Pixmap) {}
182 void* getPlatformNative (void) { return &m_pixmap.getXID(); }
183 void readPixels (TextureLevel* dst);
186 UniquePtr<x11::Pixmap> m_pixmap;
189 class PixmapFactory : public NativePixmapFactory
193 : NativePixmapFactory ("pixmap", "X11 Pixmap", Pixmap::CAPABILITIES) {}
195 NativePixmap* createPixmap (NativeDisplay* nativeDisplay,
200 NativePixmap* PixmapFactory::createPixmap (NativeDisplay* nativeDisplay,
205 Display* display = dynamic_cast<Display*>(nativeDisplay);
206 MovePtr<x11::Pixmap> x11Pixmap (new x11::Pixmap(display->getX11Display(),
208 return new Pixmap(x11Pixmap);
212 class DisplayFactory : public NativeDisplayFactory
215 DisplayFactory (EventState& eventState);
217 NativeDisplay* createDisplay (const EGLAttrib* attribList) const;
220 EventState& m_eventState;
223 DisplayFactory::DisplayFactory (EventState& eventState)
224 : NativeDisplayFactory ("x11", "Native X11 Display",
225 Display::CAPABILITIES,
226 EGL_PLATFORM_X11_SCREEN_EXT,
227 "EGL_EXT_platform_x11")
228 , m_eventState (eventState)
230 m_nativeWindowRegistry.registerFactory(new WindowFactory());
231 // m_nativePixmapRegistry.registerFactory(new PixmapFactory());
234 NativeDisplay* DisplayFactory::createDisplay (const EGLAttrib* attribList) const
236 DE_UNREF(attribList);
238 //! \todo [2014-03-18 lauri] Somehow make the display configurable from command line
239 MovePtr<x11::Display> x11Display (new x11::Display(m_eventState, DE_NULL));
241 return new Display(x11Display);
244 Platform::Platform (EventState& eventState)
246 m_nativeDisplayFactoryRegistry.registerFactory(new DisplayFactory(eventState));
249 MovePtr<ContextFactory> Platform::createContextFactory (void)
251 return MovePtr<ContextFactory>(new GLContextFactory(m_nativeDisplayFactoryRegistry));