d4cc94c65cc59331ae36d78215c72b047c9ab40b
[platform/upstream/VK-GL-CTS.git] / framework / platform / wayland / tcuWayland.hpp
1 #ifndef _TCUWAYLAND_HPP
2 #define _TCUWAYLAND_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 <elongbug@gmail.com>
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 "deMutex.hpp"
32
33 #include <wayland-client.h>
34 #include <wayland-egl.h>
35
36 namespace tcu
37 {
38 namespace wayland
39 {
40
41 class EventState
42 {
43 public:
44                                                         EventState                              (void);
45         virtual                                 ~EventState                             (void);
46
47         void                                    setQuitFlag                             (bool quit);
48         bool                                    getQuitFlag                             (void);
49
50 protected:
51         de::Mutex                               m_mutex;
52         bool                                    m_quit;
53
54 private:
55                                                         EventState                              (const EventState&);
56         EventState&                             operator=                               (const EventState&);
57 };
58
59 class Display
60 {
61 public:
62                                                         Display                                 (EventState& platform, const char* name);
63         virtual                                 ~Display                                (void);
64
65         struct wl_display*              getDisplay                              (void) { return m_display;              }
66         struct wl_compositor*   getCompositor                   (void) { return m_compositor;   }
67         struct wl_shell*                getShell                                (void) { return m_shell;                }
68
69         void                                    processEvents                   (void);
70
71 protected:
72         EventState&                             m_eventState;
73         struct wl_display*              m_display;
74         struct wl_registry*             m_registry;
75         struct wl_compositor*   m_compositor;
76         struct wl_shell*                m_shell;
77
78 private:
79                                                         Display                                 (const Display&);
80         Display&                                operator=                               (const Display&);
81
82         static const struct wl_registry_listener                s_registryListener;
83
84         static void                             handleGlobal                    (void* data, struct wl_registry* registry, uint32_t id, const char* interface, uint32_t version);
85         static void                             handleGlobalRemove              (void* data, struct wl_registry* registry, uint32_t name);
86 };
87
88 class Window
89 {
90 public:
91                                                         Window                                  (Display& display, int width, int height);
92                                                         ~Window                                 (void);
93
94         void                                    setVisibility                   (bool visible);
95
96         void                                    processEvents                   (void);
97         Display&                                getDisplay                              (void) { return m_display; }
98         void*                                   getWindow                               (void) { return m_window; }
99
100         void                                    getDimensions                   (int* width, int* height) const;
101         void                                    setDimensions                   (int width, int height);
102
103 protected:
104
105         Display&                                        m_display;
106         struct wl_egl_window*           m_window;
107         struct wl_surface*                      m_surface;
108         struct wl_shell_surface*        m_shellSurface;
109         bool                                            m_visible;
110
111 private:
112                                                         Window                                  (const Window&);
113         Window&                                 operator=                               (const Window&);
114
115         static const struct wl_shell_surface_listener   s_shellSurfaceListener;
116
117         static void                             handlePing                              (void* data, struct wl_shell_surface* shellSurface, uint32_t serial);
118         static void                             handleConfigure                 (void* data, struct wl_shell_surface* shellSurface, uint32_t edges, int32_t width, int32_t height);
119         static void                             handlePopupDone                 (void* data, struct wl_shell_surface* shellSurface);
120 };
121
122 } // wayland
123 } // tcu
124
125 #endif // _TCUWAYLAND_HPP