Merge "Add runtime to CtsDeqpTestCases"
[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 enum
42 {
43         DEFAULT_WINDOW_WIDTH    = 400,
44         DEFAULT_WINDOW_HEIGHT   = 300
45 };
46
47 class EventState
48 {
49 public:
50                                                         EventState                              (void);
51         virtual                                 ~EventState                             (void);
52
53         void                                    setQuitFlag                             (bool quit);
54         bool                                    getQuitFlag                             (void);
55
56 protected:
57         de::Mutex                               m_mutex;
58         bool                                    m_quit;
59
60 private:
61                                                         EventState                              (const EventState&);
62         EventState&                             operator=                               (const EventState&);
63 };
64
65 class Display
66 {
67 public:
68                                                         Display                                 (EventState& platform, const char* name);
69         virtual                                 ~Display                                (void);
70
71         struct wl_display*              getDisplay                              (void) { return m_display;              }
72         struct wl_compositor*   getCompositor                   (void) { return m_compositor;   }
73         struct wl_shell*                getShell                                (void) { return m_shell;                }
74
75         void                                    processEvents                   (void);
76
77 protected:
78         EventState&                             m_eventState;
79         struct wl_display*              m_display;
80         struct wl_registry*             m_registry;
81         struct wl_compositor*   m_compositor;
82         struct wl_shell*                m_shell;
83
84 private:
85                                                         Display                                 (const Display&);
86         Display&                                operator=                               (const Display&);
87
88         static const struct wl_registry_listener                s_registryListener;
89
90         static void                             handleGlobal                    (void* data, struct wl_registry* registry, uint32_t id, const char* interface, uint32_t version);
91         static void                             handleGlobalRemove              (void* data, struct wl_registry* registry, uint32_t name);
92 };
93
94 class Window
95 {
96 public:
97                                                         Window                                  (Display& display, int width, int height);
98                                                         ~Window                                 (void);
99
100         void                                    setVisibility                   (bool visible);
101
102         void                                    processEvents                   (void);
103         Display&                                getDisplay                              (void) { return m_display; }
104         void*                                   getSurface                              (void) { return m_surface; }
105         void*                                   getWindow                               (void) { return m_window; }
106
107         void                                    getDimensions                   (int* width, int* height) const;
108         void                                    setDimensions                   (int width, int height);
109
110 protected:
111
112         Display&                                        m_display;
113         struct wl_egl_window*           m_window;
114         struct wl_surface*                      m_surface;
115         struct wl_shell_surface*        m_shellSurface;
116         bool                                            m_visible;
117
118 private:
119                                                         Window                                  (const Window&);
120         Window&                                 operator=                               (const Window&);
121
122         static const struct wl_shell_surface_listener   s_shellSurfaceListener;
123
124         static void                             handlePing                              (void* data, struct wl_shell_surface* shellSurface, uint32_t serial);
125         static void                             handleConfigure                 (void* data, struct wl_shell_surface* shellSurface, uint32_t edges, int32_t width, int32_t height);
126         static void                             handlePopupDone                 (void* data, struct wl_shell_surface* shellSurface);
127 };
128
129 } // wayland
130 } // tcu
131
132 #endif // _TCUWAYLAND_HPP