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 utilities.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuWayland.hpp"
27 #include "gluRenderConfig.hpp"
39 DEFAULT_WINDOW_WIDTH = 400,
40 DEFAULT_WINDOW_HEIGHT = 300
43 EventState::EventState (void)
48 EventState::~EventState (void)
52 void EventState::setQuitFlag (bool quit)
54 de::ScopedLock lock(m_mutex);
58 bool EventState::getQuitFlag (void)
60 de::ScopedLock lock(m_mutex);
63 const struct wl_registry_listener Display::s_registryListener =
65 Display::handleGlobal,
66 Display::handleGlobalRemove
69 const struct wl_shell_surface_listener Window::s_shellSurfaceListener =
72 Window::handleConfigure,
73 Window::handlePopupDone,
76 void Display::handleGlobal (void* data, struct wl_registry* registry, uint32_t id, const char* interface, uint32_t version)
78 Display* _this = static_cast<Display*>(data);
81 if (!strcmp(interface, "wl_compositor"))
82 _this->m_compositor = static_cast<struct wl_compositor*>(wl_registry_bind(registry, id, &wl_compositor_interface, 3));
83 /* Todo: when the xdg_shell protocol has stablized, we should move wl_shell to xdg_shell. */
84 if (!strcmp(interface, "wl_shell"))
85 _this->m_shell = static_cast<struct wl_shell*>(wl_registry_bind(registry, id, &wl_shell_interface, 1));
88 void Display::handleGlobalRemove (void* data, struct wl_registry* registry, uint32_t name)
95 Display::Display (EventState& eventState, const char* name)
96 : m_eventState (eventState)
101 m_display = wl_display_connect(name);
103 throw ResourceError("Failed to open display", name, __FILE__, __LINE__);
105 m_registry = wl_display_get_registry(m_display);
107 throw ResourceError("Failed to get registry", name, __FILE__, __LINE__);
109 wl_registry_add_listener(m_registry, &s_registryListener, this);
110 wl_display_roundtrip(m_display);
112 throw ResourceError("Failed to bind compositor", name, __FILE__, __LINE__);
114 throw ResourceError("Failed to bind shell", name, __FILE__, __LINE__);
119 wl_shell_destroy(m_shell);
122 wl_compositor_destroy(m_compositor);
125 wl_registry_destroy(m_registry);
128 wl_display_disconnect(m_display);
134 Display::~Display (void)
137 wl_shell_destroy(m_shell);
140 wl_compositor_destroy(m_compositor);
143 wl_registry_destroy(m_registry);
146 wl_display_disconnect(m_display);
149 void Display::processEvents (void)
153 Window::Window (Display& display, int width, int height)
154 : m_display (display)
158 m_surface = wl_compositor_create_surface(display.getCompositor());
160 throw ResourceError("Failed to create ", "surface", __FILE__, __LINE__);
162 m_shellSurface = wl_shell_get_shell_surface(display.getShell(), m_surface);
164 throw ResourceError("Failed to create ", "shell_surface", __FILE__, __LINE__);
166 wl_shell_surface_add_listener(m_shellSurface, &s_shellSurfaceListener, this);
167 wl_shell_surface_set_title(m_shellSurface, "CTS for OpenGL (ES)");
168 wl_shell_surface_set_toplevel(m_shellSurface);
170 if (width == glu::RenderConfig::DONT_CARE)
171 width = DEFAULT_WINDOW_WIDTH;
172 if (height == glu::RenderConfig::DONT_CARE)
173 height = DEFAULT_WINDOW_HEIGHT;
175 m_window = wl_egl_window_create(m_surface, width, height);
177 throw ResourceError("Failed to create ", "window", __FILE__, __LINE__);
186 void Window::setVisibility (bool visible)
191 void Window::getDimensions (int* width, int* height) const
193 wl_egl_window_get_attached_size(m_window, width, height);
196 void Window::setDimensions (int width, int height)
198 wl_egl_window_resize(m_window, width, height, 0, 0);
201 void Window::processEvents (void)
205 void Window::handlePing (void* data, struct wl_shell_surface* shellSurface, uint32_t serial)
208 wl_shell_surface_pong(shellSurface, serial);
211 void Window::handleConfigure (void* data, struct wl_shell_surface* shellSurface, uint32_t edges, int32_t width, int32_t height)
214 DE_UNREF(shellSurface);
220 void Window::handlePopupDone (void* data, struct wl_shell_surface* shellSurface)
223 DE_UNREF(shellSurface);
226 Window::~Window (void)
229 wl_egl_window_destroy(m_window);
231 wl_shell_surface_destroy(m_shellSurface);
233 wl_surface_destroy(m_surface);