• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 eglu::GLContextFactory;
48 using eglu::NativeDisplay;
49 using eglu::NativeDisplayFactory;
50 using eglu::NativePixmap;
51 using eglu::NativePixmapFactory;
52 using eglu::NativeWindow;
53 using eglu::NativeWindowFactory;
54 using eglu::WindowParams;
55 using glu::ContextFactory;
56 using tcu::TextureLevel;
57 
58 class Display : public NativeDisplay
59 {
60 public:
61     static const Capability CAPABILITIES =
62         Capability(CAPABILITY_GET_DISPLAY_LEGACY | CAPABILITY_GET_DISPLAY_PLATFORM_EXT);
63 
Display(MovePtr<wayland::Display> waylandDisplay)64     Display(MovePtr<wayland::Display> waylandDisplay)
65         : NativeDisplay(CAPABILITIES, EGL_PLATFORM_WAYLAND_KHR, "EGL_KHR_platform_wayland")
66         , m_display(waylandDisplay)
67         , m_library("libEGL.so")
68     {
69     }
70 
~Display(void)71     ~Display(void)
72     {
73     }
getWaylandDisplay(void)74     wayland::Display &getWaylandDisplay(void)
75     {
76         return *m_display;
77     }
getLegacyNative(void)78     eglw::EGLNativeDisplayType getLegacyNative(void)
79     {
80         return reinterpret_cast<eglw::EGLNativeDisplayType>(m_display->getDisplay());
81     }
getPlatformNative(void)82     void *getPlatformNative(void)
83     {
84         return m_display->getDisplay();
85     }
getLibrary(void) const86     const eglw::Library &getLibrary(void) const
87     {
88         return m_library;
89     }
getPlatformAttributes(void) const90     const eglw::EGLAttrib *getPlatformAttributes(void) const
91     {
92         return nullptr;
93     }
94 
95 private:
96     UniquePtr<wayland::Display> m_display;
97     eglw::DefaultLibrary m_library;
98 };
99 
100 class Window : public NativeWindow
101 {
102 public:
103     static const Capability CAPABILITIES = Capability(CAPABILITY_CREATE_SURFACE_LEGACY | CAPABILITY_GET_SURFACE_SIZE |
104                                                       CAPABILITY_SET_SURFACE_SIZE | CAPABILITY_GET_SCREEN_SIZE);
105 
106     Window(Display &display, const WindowParams &params);
107 
getLegacyNative(void)108     eglw::EGLNativeWindowType getLegacyNative(void)
109     {
110         return reinterpret_cast<eglw::EGLNativeWindowType>(m_window.getWindow());
111     }
112     IVec2 getSurfaceSize(void) const;
113     void setSurfaceSize(IVec2 size);
getScreenSize(void) const114     IVec2 getScreenSize(void) const
115     {
116         return getSurfaceSize();
117     }
118 
119 private:
120     wayland::Window m_window;
121 };
122 
Window(Display & display,const WindowParams & params)123 Window::Window(Display &display, const WindowParams &params)
124     : NativeWindow(CAPABILITIES)
125     , m_window(display.getWaylandDisplay(), params.width, params.height)
126 {
127 }
128 
getSurfaceSize(void) const129 IVec2 Window::getSurfaceSize(void) const
130 {
131     IVec2 ret;
132     m_window.getDimensions(&ret.x(), &ret.y());
133     return ret;
134 }
135 
setSurfaceSize(IVec2 size)136 void Window::setSurfaceSize(IVec2 size)
137 {
138     m_window.setDimensions(size.x(), size.y());
139 }
140 
141 class WindowFactory : public NativeWindowFactory
142 {
143 public:
144     WindowFactory(void);
145 
146     NativeWindow *createWindow(NativeDisplay *nativeDisplay, const WindowParams &params) const;
147 
148     NativeWindow *createWindow(NativeDisplay *nativeDisplay, eglw::EGLDisplay display, eglw::EGLConfig config,
149                                const eglw::EGLAttrib *attribList, const WindowParams &params) const;
150 };
151 
WindowFactory(void)152 WindowFactory::WindowFactory(void) : NativeWindowFactory("window", "Wayland Window", Window::CAPABILITIES)
153 {
154 }
155 
createWindow(NativeDisplay * nativeDisplay,const WindowParams & params) const156 NativeWindow *WindowFactory::createWindow(NativeDisplay *nativeDisplay, const WindowParams &params) const
157 {
158     Display &display = *dynamic_cast<Display *>(nativeDisplay);
159 
160     return new Window(display, params);
161 }
162 
createWindow(NativeDisplay * nativeDisplay,eglw::EGLDisplay eglDisplay,eglw::EGLConfig config,const eglw::EGLAttrib * attribList,const WindowParams & params) const163 NativeWindow *WindowFactory::createWindow(NativeDisplay *nativeDisplay, eglw::EGLDisplay eglDisplay,
164                                           eglw::EGLConfig config, const eglw::EGLAttrib *attribList,
165                                           const WindowParams &params) const
166 {
167     DE_UNREF(eglDisplay);
168     DE_UNREF(config);
169     DE_UNREF(attribList);
170 
171     Display &display = *dynamic_cast<Display *>(nativeDisplay);
172 
173     return new Window(display, params);
174 }
175 
176 class DisplayFactory : public NativeDisplayFactory
177 {
178 public:
179     DisplayFactory(EventState &eventState);
180 
181     NativeDisplay *createDisplay(const eglw::EGLAttrib *attribList) const;
182 
183 private:
184     EventState &m_eventState;
185 };
186 
DisplayFactory(EventState & eventState)187 DisplayFactory::DisplayFactory(EventState &eventState)
188     : NativeDisplayFactory("Wayland", "Native Wayland Display", Display::CAPABILITIES, EGL_PLATFORM_WAYLAND_KHR,
189                            "EGL_KHR_platform_wayland")
190     , m_eventState(eventState)
191 {
192     m_nativeWindowRegistry.registerFactory(new WindowFactory());
193 }
194 
createDisplay(const eglw::EGLAttrib * attribList) const195 NativeDisplay *DisplayFactory::createDisplay(const eglw::EGLAttrib *attribList) const
196 {
197     DE_UNREF(attribList);
198 
199     MovePtr<wayland::Display> waylandDisplay(new wayland::Display(m_eventState, nullptr));
200 
201     return new Display(waylandDisplay);
202 }
203 
createDisplayFactory(EventState & eventState)204 NativeDisplayFactory *createDisplayFactory(EventState &eventState)
205 {
206     return new DisplayFactory(eventState);
207 }
208 
209 } // namespace egl
210 } // namespace wayland
211 } // namespace lnx
212 } // namespace tcu
213