xref: /aosp_15_r20/external/deqp/framework/platform/lnx/X11/tcuLnxX11.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _TCULNXX11_HPP
2 #define _TCULNXX11_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
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 X11 utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "gluRenderConfig.hpp"
28 #include "gluPlatform.hpp"
29 #include "tcuLnx.hpp"
30 
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33 #include <X11/keysym.h>
34 #include <X11/Xatom.h>
35 
36 namespace tcu
37 {
38 namespace lnx
39 {
40 namespace x11
41 {
42 
43 class DisplayBase
44 {
45 public:
46     DisplayBase(EventState &platform);
47     virtual ~DisplayBase(void);
48     virtual void processEvents(void) = 0;
49 
50     enum DisplayState
51     {
52         DISPLAY_STATE_UNKNOWN = -1,
53         DISPLAY_STATE_UNAVAILABLE,
54         DISPLAY_STATE_AVAILABLE
55     };
56 
57 protected:
58     EventState &m_eventState;
59 
60 private:
61     DisplayBase(const DisplayBase &);
62     DisplayBase &operator=(const DisplayBase &);
63 };
64 
65 class WindowBase
66 {
67 public:
68     WindowBase(void);
69     virtual ~WindowBase(void);
70 
71     virtual void setVisibility(bool visible) = 0;
72 
73     virtual void processEvents(void)      = 0;
74     virtual DisplayBase &getDisplay(void) = 0;
75 
76     virtual void getDimensions(int *width, int *height) const = 0;
77     virtual void setDimensions(int width, int height)         = 0;
78 
79 protected:
80     bool m_visible;
81 
82 private:
83     WindowBase(const WindowBase &);
84     WindowBase &operator=(const WindowBase &);
85 };
86 
87 class XlibDisplay : public DisplayBase
88 {
89 public:
90     XlibDisplay(EventState &platform, const char *name);
91     virtual ~XlibDisplay(void);
92 
getXDisplay(void)93     ::Display *getXDisplay(void)
94     {
95         return m_display;
96     }
getDeleteAtom(void)97     Atom getDeleteAtom(void)
98     {
99         return m_deleteAtom;
100     }
101 
102     ::Visual *getVisual(VisualID visualID);
103     bool getVisualInfo(VisualID visualID, XVisualInfo &dst);
104     void processEvents(void);
105     void processEvent(XEvent &event);
106     static bool hasDisplay(const char *name);
107 
108     static DisplayState s_displayState;
109 
110 protected:
111     ::Display *m_display;
112     Atom m_deleteAtom;
113 
114 private:
115     XlibDisplay(const XlibDisplay &);
116     XlibDisplay &operator=(const XlibDisplay &);
117 };
118 
119 class XlibWindow : public WindowBase
120 {
121 public:
122     XlibWindow(XlibDisplay &display, int width, int height, ::Visual *visual);
123     ~XlibWindow(void);
124 
125     void setVisibility(bool visible);
126 
127     void processEvents(void);
getDisplay(void)128     DisplayBase &getDisplay(void)
129     {
130         return (DisplayBase &)m_display;
131     }
getXID(void)132     ::Window &getXID(void)
133     {
134         return m_window;
135     }
136 
137     void getDimensions(int *width, int *height) const;
138     void setDimensions(int width, int height);
139 
140 protected:
141     XlibDisplay &m_display;
142     ::Colormap m_colormap;
143     ::Window m_window;
144 
145 private:
146     XlibWindow(const XlibWindow &);
147     XlibWindow &operator=(const XlibWindow &);
148 };
149 
150 } // namespace x11
151 } // namespace lnx
152 } // namespace tcu
153 
154 #endif // _TCULNXX11_HPP
155