Update GL wrapper to newest API.
[platform/upstream/VK-GL-CTS.git] / framework / platform / wayland / tcuWaylandEglPlatform.cpp
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 Platform.
24  *//*--------------------------------------------------------------------*/
25
26 #include "tcuWaylandEglPlatform.hpp"
27 #include "egluGLContextFactory.hpp"
28 #include "eglwLibrary.hpp"
29 #include "eglwFunctions.hpp"
30 #include "eglwEnums.hpp"
31
32 namespace tcu
33 {
34 namespace wayland
35 {
36 namespace egl
37 {
38
39 using std::string;
40
41 using de::MovePtr;
42 using de::UniquePtr;
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;
53
54 class Display : public NativeDisplay
55 {
56 public:
57         static const Capability CAPABILITIES            = Capability(CAPABILITY_GET_DISPLAY_LEGACY|
58                                                                                                                          CAPABILITY_GET_DISPLAY_PLATFORM);
59
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") {}
66
67         ~Display(void) {}
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; }
73
74 private:
75         UniquePtr<wayland::Display>             m_display;
76         eglw::DefaultLibrary                    m_library;
77 };
78
79 class Window : public NativeWindow
80 {
81 public:
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);
86
87                                                                 Window                          (Display&                               display,
88                                                                                                          const WindowParams&    params);
89
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(); }
94
95 private:
96         wayland::Window                         m_window;
97 };
98
99 Window::Window (Display& display, const WindowParams& params)
100         : NativeWindow  (CAPABILITIES)
101         , m_window              (display.getWaylandDisplay(), params.width, params.height)
102 {
103 }
104
105 IVec2 Window::getSurfaceSize (void) const
106 {
107         IVec2 ret;
108         m_window.getDimensions(&ret.x(), &ret.y());
109         return ret;
110 }
111
112 void Window::setSurfaceSize (IVec2 size)
113 {
114         m_window.setDimensions(size.x(), size.y());
115 }
116
117 class WindowFactory : public NativeWindowFactory
118 {
119 public:
120                                                 WindowFactory           (void);
121
122         NativeWindow*           createWindow            (NativeDisplay*                 nativeDisplay,
123                                                                                          const WindowParams&    params) const;
124
125         NativeWindow*           createWindow            (NativeDisplay*                 nativeDisplay,
126                                                                                          eglw::EGLDisplay               display,
127                                                                                          eglw::EGLConfig                config,
128                                                                                          const eglw::EGLAttrib* attribList,
129                                                                                          const WindowParams&    params) const;
130 };
131
132 WindowFactory::WindowFactory (void)
133         : NativeWindowFactory ("window", "Wayland Window", Window::CAPABILITIES)
134 {
135 }
136
137 NativeWindow* WindowFactory::createWindow (NativeDisplay*               nativeDisplay,
138                                                                                    const WindowParams&  params) const
139 {
140         Display&        display = *dynamic_cast<Display*>(nativeDisplay);
141
142         return new Window(display, params);
143 }
144
145 NativeWindow* WindowFactory::createWindow (NativeDisplay*                       nativeDisplay,
146                                                                                    eglw::EGLDisplay                     eglDisplay,
147                                                                                    eglw::EGLConfig                      config,
148                                                                                    const eglw::EGLAttrib*       attribList,
149                                                                                    const WindowParams&          params) const
150 {
151         DE_UNREF(eglDisplay);
152         DE_UNREF(config);
153         DE_UNREF(attribList);
154
155         Display&        display = *dynamic_cast<Display*>(nativeDisplay);
156
157         return new Window(display, params);
158 }
159
160 class DisplayFactory : public NativeDisplayFactory
161 {
162 public:
163                                                 DisplayFactory          (EventState& eventState);
164
165         NativeDisplay*          createDisplay           (const eglw::EGLAttrib* attribList) const;
166
167 private:
168         EventState&                     m_eventState;
169 };
170
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)
177 {
178         m_nativeWindowRegistry.registerFactory(new WindowFactory());
179 }
180
181 NativeDisplay* DisplayFactory::createDisplay (const eglw::EGLAttrib* attribList) const
182 {
183         DE_UNREF(attribList);
184
185         MovePtr<wayland::Display>       waylandDisplay  (new wayland::Display(m_eventState, DE_NULL));
186
187         return new Display(waylandDisplay);
188 }
189
190 Platform::Platform (EventState& eventState)
191 {
192         m_nativeDisplayFactoryRegistry.registerFactory(new DisplayFactory(eventState));
193 }
194
195 MovePtr<ContextFactory> Platform::createContextFactory (void)
196 {
197         return MovePtr<ContextFactory>(new GLContextFactory(m_nativeDisplayFactoryRegistry));
198 }
199
200 } // egl
201 } // wayland
202 } // tcu