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) { return m_display; } getDeleteAtom(void)94 Atom getDeleteAtom (void) { return m_deleteAtom; } 95 96 ::Visual* getVisual (VisualID visualID); 97 bool getVisualInfo (VisualID visualID, XVisualInfo& dst); 98 void processEvents (void); 99 void processEvent (XEvent& event); 100 static bool hasDisplay (const char* name); 101 102 static DisplayState s_displayState; 103 104 protected: 105 ::Display* m_display; 106 Atom m_deleteAtom; 107 108 private: 109 XlibDisplay (const XlibDisplay&); 110 XlibDisplay& operator= (const XlibDisplay&); 111 }; 112 113 class XlibWindow : public WindowBase 114 { 115 public: 116 XlibWindow (XlibDisplay& display, int width, int height, 117 ::Visual* visual); 118 ~XlibWindow (void); 119 120 void setVisibility (bool visible); 121 122 void processEvents (void); getDisplay(void)123 DisplayBase& getDisplay (void) { return (DisplayBase&)m_display; } getXID(void)124 ::Window& getXID (void) { return m_window; } 125 126 void getDimensions (int* width, int* height) const; 127 void setDimensions (int width, int height); 128 129 protected: 130 XlibDisplay& m_display; 131 ::Colormap m_colormap; 132 ::Window m_window; 133 134 private: 135 XlibWindow (const XlibWindow&); 136 XlibWindow& operator= (const XlibWindow&); 137 }; 138 139 } // x11 140 } // lnx 141 } // tcu 142 143 #endif // _TCULNXX11_HPP 144