1 #ifndef _TCUX11_HPP 2 #define _TCUX11_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 "deMutex.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 x11 39 { 40 enum 41 { 42 DEFAULT_WINDOW_WIDTH = 400, 43 DEFAULT_WINDOW_HEIGHT = 300 44 }; 45 46 class EventState 47 { 48 public: 49 EventState (void); 50 virtual ~EventState (void); 51 void setQuitFlag (bool quit); 52 bool getQuitFlag (void); 53 54 protected: 55 de::Mutex m_mutex; 56 bool m_quit; 57 58 private: 59 EventState (const EventState&); 60 EventState& operator= (const EventState&); 61 }; 62 63 class DisplayBase 64 { 65 public: 66 DisplayBase (EventState& platform); 67 virtual ~DisplayBase (void); 68 virtual void processEvents (void) = 0; 69 70 protected: 71 EventState& m_eventState; 72 73 private: 74 DisplayBase (const DisplayBase&); 75 DisplayBase& operator= (const DisplayBase&); 76 }; 77 78 class WindowBase 79 { 80 public: 81 WindowBase (void); 82 virtual ~WindowBase (void); 83 84 virtual void setVisibility (bool visible) = 0; 85 86 virtual void processEvents (void) = 0; 87 virtual DisplayBase& getDisplay (void) = 0; 88 89 virtual void getDimensions (int* width, int* height) const = 0; 90 virtual void setDimensions (int width, int height) = 0; 91 92 protected: 93 bool m_visible; 94 95 private: 96 WindowBase (const WindowBase&); 97 WindowBase& operator= (const WindowBase&); 98 }; 99 100 class XlibDisplay : public DisplayBase 101 { 102 public: 103 XlibDisplay (EventState& platform, const char* name); 104 virtual ~XlibDisplay (void); 105 getXDisplay(void)106 ::Display* getXDisplay (void) { return m_display; } getDeleteAtom(void)107 Atom getDeleteAtom (void) { return m_deleteAtom; } 108 109 ::Visual* getVisual (VisualID visualID); 110 bool getVisualInfo (VisualID visualID, XVisualInfo& dst); 111 void processEvents (void); 112 void processEvent (XEvent& event); 113 114 protected: 115 ::Display* m_display; 116 Atom m_deleteAtom; 117 118 private: 119 XlibDisplay (const XlibDisplay&); 120 XlibDisplay& operator= (const XlibDisplay&); 121 }; 122 123 class XlibWindow : public WindowBase 124 { 125 public: 126 XlibWindow (XlibDisplay& display, int width, int height, 127 ::Visual* visual); 128 ~XlibWindow (void); 129 130 void setVisibility (bool visible); 131 132 void processEvents (void); getDisplay(void)133 DisplayBase& getDisplay (void) { return (DisplayBase&)m_display; } getXID(void)134 ::Window& getXID (void) { return m_window; } 135 136 void getDimensions (int* width, int* height) const; 137 void setDimensions (int width, int height); 138 139 protected: 140 XlibDisplay& m_display; 141 ::Colormap m_colormap; 142 ::Window m_window; 143 144 private: 145 XlibWindow (const XlibWindow&); 146 XlibWindow& operator= (const XlibWindow&); 147 }; 148 149 } // x11 150 } // tcu 151 152 #endif // _TCUX11_HPP 153