1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright (c) 2014 The Android Open Source Project
6 * Copyright (c) 2016 The Khronos Group Inc.
7 * Copyright (c) 2016 Mun Gwan-gyeong <elongbug@gmail.com>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief wayland Egl Platform.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuWaylandEglPlatform.hpp"
27 #include "egluGLContextFactory.hpp"
28 #include "eglwLibrary.hpp"
29 #include "eglwFunctions.hpp"
30 #include "eglwEnums.hpp"
43 using glu::ContextFactory;
44 using eglu::GLContextFactory;
45 using eglu::NativeDisplay;
46 using eglu::NativeDisplayFactory;
47 using eglu::NativeWindow;
48 using eglu::NativeWindowFactory;
49 using eglu::NativePixmap;
50 using eglu::NativePixmapFactory;
51 using eglu::WindowParams;
52 using tcu::TextureLevel;
54 class Display : public NativeDisplay
57 static const Capability CAPABILITIES = Capability(CAPABILITY_GET_DISPLAY_LEGACY|
58 CAPABILITY_GET_DISPLAY_PLATFORM);
60 Display (MovePtr<wayland::Display> waylandDisplay)
61 : NativeDisplay (CAPABILITIES,
62 EGL_PLATFORM_WAYLAND_KHR,
63 "EGL_KHR_platform_wayland")
64 , m_display (waylandDisplay)
65 , m_library ("libEGL.so") {}
68 wayland::Display& getWaylandDisplay (void) { return *m_display; }
69 eglw::EGLNativeDisplayType getLegacyNative (void) { return reinterpret_cast<eglw::EGLNativeDisplayType>(m_display->getDisplay()); }
70 void* getPlatformNative (void) { return m_display->getDisplay(); }
71 const eglw::Library& getLibrary (void) const { return m_library; }
72 const eglw::EGLAttrib* getPlatformAttributes (void) const { return DE_NULL; }
75 UniquePtr<wayland::Display> m_display;
76 eglw::DefaultLibrary m_library;
79 class Window : public NativeWindow
82 static const Capability CAPABILITIES = Capability(CAPABILITY_CREATE_SURFACE_LEGACY |
83 CAPABILITY_GET_SURFACE_SIZE |
84 CAPABILITY_SET_SURFACE_SIZE |
85 CAPABILITY_GET_SCREEN_SIZE);
87 Window (Display& display,
88 const WindowParams& params);
90 eglw::EGLNativeWindowType getLegacyNative (void) { return reinterpret_cast<eglw::EGLNativeWindowType>(m_window.getWindow()); }
91 IVec2 getSurfaceSize (void) const;
92 void setSurfaceSize (IVec2 size);
93 IVec2 getScreenSize (void) const { return getSurfaceSize(); }
96 wayland::Window m_window;
99 Window::Window (Display& display, const WindowParams& params)
100 : NativeWindow (CAPABILITIES)
101 , m_window (display.getWaylandDisplay(), params.width, params.height)
105 IVec2 Window::getSurfaceSize (void) const
108 m_window.getDimensions(&ret.x(), &ret.y());
112 void Window::setSurfaceSize (IVec2 size)
114 m_window.setDimensions(size.x(), size.y());
117 class WindowFactory : public NativeWindowFactory
120 WindowFactory (void);
122 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
123 const WindowParams& params) const;
125 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
126 eglw::EGLDisplay display,
127 eglw::EGLConfig config,
128 const eglw::EGLAttrib* attribList,
129 const WindowParams& params) const;
132 WindowFactory::WindowFactory (void)
133 : NativeWindowFactory ("window", "Wayland Window", Window::CAPABILITIES)
137 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
138 const WindowParams& params) const
140 Display& display = *dynamic_cast<Display*>(nativeDisplay);
142 return new Window(display, params);
145 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
146 eglw::EGLDisplay eglDisplay,
147 eglw::EGLConfig config,
148 const eglw::EGLAttrib* attribList,
149 const WindowParams& params) const
151 DE_UNREF(eglDisplay);
153 DE_UNREF(attribList);
155 Display& display = *dynamic_cast<Display*>(nativeDisplay);
157 return new Window(display, params);
160 class DisplayFactory : public NativeDisplayFactory
163 DisplayFactory (EventState& eventState);
165 NativeDisplay* createDisplay (const eglw::EGLAttrib* attribList) const;
168 EventState& m_eventState;
171 DisplayFactory::DisplayFactory (EventState& eventState)
172 : NativeDisplayFactory ("Wayland", "Native Wayland Display",
173 Display::CAPABILITIES,
174 EGL_PLATFORM_WAYLAND_KHR,
175 "EGL_KHR_platform_wayland")
176 , m_eventState (eventState)
178 m_nativeWindowRegistry.registerFactory(new WindowFactory());
181 NativeDisplay* DisplayFactory::createDisplay (const eglw::EGLAttrib* attribList) const
183 DE_UNREF(attribList);
185 MovePtr<wayland::Display> waylandDisplay (new wayland::Display(m_eventState, DE_NULL));
187 return new Display(waylandDisplay);
190 Platform::Platform (EventState& eventState)
192 m_nativeDisplayFactoryRegistry.registerFactory(new DisplayFactory(eventState));
195 MovePtr<ContextFactory> Platform::createContextFactory (void)
197 return MovePtr<ContextFactory>(new GLContextFactory(m_nativeDisplayFactoryRegistry));