1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
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>
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 wayland Egl Display Factory.
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuLnxWaylandEglDisplayFactory.hpp"
27 #include "tcuLnxWayland.hpp"
28 #include "egluGLContextFactory.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwFunctions.hpp"
31 #include "eglwEnums.hpp"
32 #include "deUniquePtr.hpp"
33
34 namespace tcu
35 {
36 namespace lnx
37 {
38 namespace wayland
39 {
40 namespace egl
41 {
42
43 using std::string;
44
45 using de::MovePtr;
46 using de::UniquePtr;
47 using glu::ContextFactory;
48 using eglu::GLContextFactory;
49 using eglu::NativeDisplay;
50 using eglu::NativeDisplayFactory;
51 using eglu::NativeWindow;
52 using eglu::NativeWindowFactory;
53 using eglu::NativePixmap;
54 using eglu::NativePixmapFactory;
55 using eglu::WindowParams;
56 using tcu::TextureLevel;
57
58 class Display : public NativeDisplay
59 {
60 public:
61 static const Capability CAPABILITIES = Capability(CAPABILITY_GET_DISPLAY_LEGACY|
62 CAPABILITY_GET_DISPLAY_PLATFORM);
63
Display(MovePtr<wayland::Display> waylandDisplay)64 Display (MovePtr<wayland::Display> waylandDisplay)
65 : NativeDisplay (CAPABILITIES,
66 EGL_PLATFORM_WAYLAND_KHR,
67 "EGL_KHR_platform_wayland")
68 , m_display (waylandDisplay)
69 , m_library ("libEGL.so") {}
70
~Display(void)71 ~Display(void) {}
getWaylandDisplay(void)72 wayland::Display& getWaylandDisplay (void) { return *m_display; }
getLegacyNative(void)73 eglw::EGLNativeDisplayType getLegacyNative (void) { return reinterpret_cast<eglw::EGLNativeDisplayType>(m_display->getDisplay()); }
getPlatformNative(void)74 void* getPlatformNative (void) { return m_display->getDisplay(); }
getLibrary(void) const75 const eglw::Library& getLibrary (void) const { return m_library; }
getPlatformAttributes(void) const76 const eglw::EGLAttrib* getPlatformAttributes (void) const { return DE_NULL; }
77
78 private:
79 UniquePtr<wayland::Display> m_display;
80 eglw::DefaultLibrary m_library;
81 };
82
83 class Window : public NativeWindow
84 {
85 public:
86 static const Capability CAPABILITIES = Capability(CAPABILITY_CREATE_SURFACE_LEGACY |
87 CAPABILITY_GET_SURFACE_SIZE |
88 CAPABILITY_SET_SURFACE_SIZE |
89 CAPABILITY_GET_SCREEN_SIZE);
90
91 Window (Display& display,
92 const WindowParams& params);
93
getLegacyNative(void)94 eglw::EGLNativeWindowType getLegacyNative (void) { return reinterpret_cast<eglw::EGLNativeWindowType>(m_window.getWindow()); }
95 IVec2 getSurfaceSize (void) const;
96 void setSurfaceSize (IVec2 size);
getScreenSize(void) const97 IVec2 getScreenSize (void) const { return getSurfaceSize(); }
98
99 private:
100 wayland::Window m_window;
101 };
102
Window(Display & display,const WindowParams & params)103 Window::Window (Display& display, const WindowParams& params)
104 : NativeWindow (CAPABILITIES)
105 , m_window (display.getWaylandDisplay(), params.width, params.height)
106 {
107 }
108
getSurfaceSize(void) const109 IVec2 Window::getSurfaceSize (void) const
110 {
111 IVec2 ret;
112 m_window.getDimensions(&ret.x(), &ret.y());
113 return ret;
114 }
115
setSurfaceSize(IVec2 size)116 void Window::setSurfaceSize (IVec2 size)
117 {
118 m_window.setDimensions(size.x(), size.y());
119 }
120
121 class WindowFactory : public NativeWindowFactory
122 {
123 public:
124 WindowFactory (void);
125
126 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
127 const WindowParams& params) const;
128
129 NativeWindow* createWindow (NativeDisplay* nativeDisplay,
130 eglw::EGLDisplay display,
131 eglw::EGLConfig config,
132 const eglw::EGLAttrib* attribList,
133 const WindowParams& params) const;
134 };
135
WindowFactory(void)136 WindowFactory::WindowFactory (void)
137 : NativeWindowFactory ("window", "Wayland Window", Window::CAPABILITIES)
138 {
139 }
140
createWindow(NativeDisplay * nativeDisplay,const WindowParams & params) const141 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
142 const WindowParams& params) const
143 {
144 Display& display = *dynamic_cast<Display*>(nativeDisplay);
145
146 return new Window(display, params);
147 }
148
createWindow(NativeDisplay * nativeDisplay,eglw::EGLDisplay eglDisplay,eglw::EGLConfig config,const eglw::EGLAttrib * attribList,const WindowParams & params) const149 NativeWindow* WindowFactory::createWindow (NativeDisplay* nativeDisplay,
150 eglw::EGLDisplay eglDisplay,
151 eglw::EGLConfig config,
152 const eglw::EGLAttrib* attribList,
153 const WindowParams& params) const
154 {
155 DE_UNREF(eglDisplay);
156 DE_UNREF(config);
157 DE_UNREF(attribList);
158
159 Display& display = *dynamic_cast<Display*>(nativeDisplay);
160
161 return new Window(display, params);
162 }
163
164 class DisplayFactory : public NativeDisplayFactory
165 {
166 public:
167 DisplayFactory (EventState& eventState);
168
169 NativeDisplay* createDisplay (const eglw::EGLAttrib* attribList) const;
170
171 private:
172 EventState& m_eventState;
173 };
174
DisplayFactory(EventState & eventState)175 DisplayFactory::DisplayFactory (EventState& eventState)
176 : NativeDisplayFactory ("Wayland", "Native Wayland Display",
177 Display::CAPABILITIES,
178 EGL_PLATFORM_WAYLAND_KHR,
179 "EGL_KHR_platform_wayland")
180 , m_eventState (eventState)
181 {
182 m_nativeWindowRegistry.registerFactory(new WindowFactory());
183 }
184
createDisplay(const eglw::EGLAttrib * attribList) const185 NativeDisplay* DisplayFactory::createDisplay (const eglw::EGLAttrib* attribList) const
186 {
187 DE_UNREF(attribList);
188
189 MovePtr<wayland::Display> waylandDisplay (new wayland::Display(m_eventState, DE_NULL));
190
191 return new Display(waylandDisplay);
192 }
193
createDisplayFactory(EventState & eventState)194 NativeDisplayFactory* createDisplayFactory (EventState& eventState)
195 {
196 return new DisplayFactory(eventState);
197 }
198
199 } // egl
200 } // wayland
201 } // lnx
202 } // tcu
203