1 #ifndef _TCULNXWAYLAND_HPP 2 #define _TCULNXWAYLAND_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright (c) 2014 The Android Open Source Project 8 * Copyright (c) 2016 The Khronos Group Inc. 9 * Copyright (c) 2016 Mun Gwan-gyeong <[email protected]> 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); 12 * you may not use this file except in compliance with the License. 13 * You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * 23 *//*! 24 * \file 25 * \brief wayland utilities. 26 *//*--------------------------------------------------------------------*/ 27 28 #include "tcuDefs.hpp" 29 #include "gluRenderConfig.hpp" 30 #include "gluPlatform.hpp" 31 #include "tcuLnx.hpp" 32 33 #include <wayland-client.h> 34 #include <wayland-egl.h> 35 #include "xdg-shell.h" 36 37 namespace tcu 38 { 39 namespace lnx 40 { 41 namespace wayland 42 { 43 44 class Display 45 { 46 public: 47 Display(EventState &platform, const char *name); 48 virtual ~Display(void); 49 getDisplay(void)50 struct wl_display *getDisplay(void) 51 { 52 return m_display; 53 } getCompositor(void)54 struct wl_compositor *getCompositor(void) 55 { 56 return m_compositor; 57 } getShell(void)58 struct xdg_wm_base *getShell(void) 59 { 60 return m_shell; 61 } 62 63 void processEvents(void); 64 static bool hasDisplay(const char *name); 65 66 enum DisplayState 67 { 68 DISPLAY_STATE_UNKNOWN = -1, 69 DISPLAY_STATE_UNAVAILABLE, 70 DISPLAY_STATE_AVAILABLE 71 }; 72 static DisplayState s_displayState; 73 74 protected: 75 EventState &m_eventState; 76 struct wl_display *m_display; 77 struct wl_registry *m_registry; 78 struct wl_compositor *m_compositor; 79 struct xdg_wm_base *m_shell; 80 81 private: 82 Display(const Display &); 83 Display &operator=(const Display &); 84 85 static const struct wl_registry_listener s_registryListener; 86 87 static void handleGlobal(void *data, struct wl_registry *registry, uint32_t id, const char *interface, 88 uint32_t version); 89 static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name); 90 }; 91 92 class Window 93 { 94 public: 95 Window(Display &display, int width, int height); 96 ~Window(void); 97 98 void setVisibility(bool visible); 99 100 void processEvents(void); getDisplay(void)101 Display &getDisplay(void) 102 { 103 return m_display; 104 } getSurface(void)105 void *getSurface(void) 106 { 107 return m_surface; 108 } getWindow(void)109 void *getWindow(void) 110 { 111 return m_window; 112 } 113 114 void getDimensions(int *width, int *height) const; 115 void setDimensions(int width, int height); 116 117 protected: 118 Display &m_display; 119 struct wl_egl_window *m_window; 120 struct wl_surface *m_surface; 121 struct xdg_surface *m_xdgSurface; 122 struct xdg_toplevel *m_topLevel; 123 bool m_configured; 124 bool m_visible; 125 126 private: 127 Window(const Window &); 128 Window &operator=(const Window &); 129 130 static const struct xdg_surface_listener s_xdgSurfaceListener; 131 static const struct xdg_wm_base_listener s_wmBaseListener; 132 133 static void handlePing(void *data, struct xdg_wm_base *shellSurface, uint32_t serial); 134 static void handleConfigure(void *data, struct xdg_surface *shellSurface, uint32_t serial); 135 136 static bool s_addWMBaseListener; 137 }; 138 139 } // namespace wayland 140 } // namespace lnx 141 } // namespace tcu 142 143 #endif // _TCULNXWAYLAND_HPP 144