Panda3D
x11GraphicsPipe.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file x11GraphicsPipe.h
10  * @author rdb
11  * @date 2009-07-07
12  */
13 
14 #ifndef X11GRAPHICSPIPE_H
15 #define X11GRAPHICSPIPE_H
16 
17 #include "pandabase.h"
18 #include "graphicsWindow.h"
19 #include "graphicsPipe.h"
20 #include "lightMutex.h"
21 #include "lightReMutex.h"
22 #include "windowHandle.h"
23 #include "get_x11.h"
24 #include "config_x11display.h"
25 
26 // Excerpt the few definitions we need for the extensions.
27 #define XF86DGADirectMouse 0x0004
28 
29 typedef struct _XcursorFile XcursorFile;
30 typedef struct _XcursorImage XcursorImage;
31 typedef struct _XcursorImages XcursorImages;
32 
33 typedef unsigned short Rotation;
34 typedef unsigned short SizeID;
35 typedef unsigned long XRRModeFlags;
36 typedef XID RROutput;
37 typedef XID RRCrtc;
38 typedef XID RRMode;
39 
40 typedef struct _XRRScreenConfiguration XRRScreenConfiguration;
41 typedef struct {
42  int width, height;
43  int mwidth, mheight;
45 
46 typedef struct _XRRModeInfo {
47  RRMode id;
48  unsigned int width;
49  unsigned int height;
50  unsigned long dotClock;
51  unsigned int hSyncStart;
52  unsigned int hSyncEnd;
53  unsigned int hTotal;
54  unsigned int hSkew;
55  unsigned int vSyncStart;
56  unsigned int vSyncEnd;
57  unsigned int vTotal;
58  char *name;
59  unsigned int nameLength;
60  XRRModeFlags modeFlags;
61 } XRRModeInfo;
62 
63 typedef struct _XRRScreenResources {
64  Time timestamp;
65  Time configTimestamp;
66  int ncrtc;
67  RRCrtc *crtcs;
68  int noutput;
69  RROutput *outputs;
70  int nmode;
71  XRRModeInfo *modes;
73 
74 typedef struct _XRRCrtcInfo {
75  Time timestamp;
76  int x, y;
77  unsigned int width, height;
78  RRMode mode;
79  Rotation rotation;
80  int noutput;
81  RROutput *outputs;
82  Rotation rotations;
83  int npossible;
84  RROutput *possible;
85 } XRRCrtcInfo;
86 
87 typedef void (*pfn_XRRFreeScreenResources)(XRRScreenResources *resources);
88 typedef void (*pfn_XRRFreeCrtcInfo)(XRRCrtcInfo *crtcInfo);
89 
91 
92 /**
93  * This graphics pipe represents the interface for creating graphics windows
94  * on an X-based client.
95  */
96 class x11GraphicsPipe : public GraphicsPipe {
97 public:
98  x11GraphicsPipe(const std::string &display = std::string());
99  virtual ~x11GraphicsPipe();
100 
101  INLINE X11_Display *get_display() const;
102  INLINE int get_screen() const;
103  INLINE X11_Window get_root() const;
104  INLINE XIM get_im() const;
105 
106  INLINE X11_Cursor get_hidden_cursor();
107 
108  INLINE bool supports_relative_mouse() const;
109  INLINE bool enable_relative_mouse();
110  INLINE void disable_relative_mouse();
111 
112  static INLINE int disable_x_error_messages();
113  static INLINE int enable_x_error_messages();
114  static INLINE int get_x_error_count();
115 
116  std::unique_ptr<XRRScreenResources, pfn_XRRFreeScreenResources> get_screen_resources() const;
117  std::unique_ptr<XRRCrtcInfo, pfn_XRRFreeCrtcInfo> get_crtc_info(XRRScreenResources *res, RRCrtc crtc) const;
118 
119  RRCrtc find_fullscreen_crtc(const LPoint2i &point,
120  int &x, int &y, int &width, int &height);
121 
122 public:
123  virtual PreferredWindowThread get_preferred_window_thread() const;
124 
125 public:
126  // Atom specifications.
127  Atom _wm_delete_window;
128  Atom _net_wm_pid;
129  Atom _net_wm_window_type;
130  Atom _net_wm_window_type_splash;
131  Atom _net_wm_window_type_fullscreen;
132  Atom _net_wm_state;
133  Atom _net_wm_state_fullscreen;
134  Atom _net_wm_state_above;
135  Atom _net_wm_state_below;
136  Atom _net_wm_state_add;
137  Atom _net_wm_state_remove;
138  Atom _net_wm_bypass_compositor;
139 
140  // Extension functions.
141  typedef int (*pfn_XcursorGetDefaultSize)(X11_Display *);
142  typedef XcursorImages *(*pfn_XcursorXcFileLoadImages)(XcursorFile *, int);
143  typedef X11_Cursor (*pfn_XcursorImagesLoadCursor)(X11_Display *, const XcursorImages *);
144  typedef void (*pfn_XcursorImagesDestroy)(XcursorImages *);
145  typedef XcursorImage *(*pfn_XcursorImageCreate)(int, int);
146  typedef X11_Cursor (*pfn_XcursorImageLoadCursor)(X11_Display *, const XcursorImage *);
147  typedef void (*pfn_XcursorImageDestroy)(XcursorImage *);
148 
149  int _xcursor_size;
150  pfn_XcursorXcFileLoadImages _XcursorXcFileLoadImages;
151  pfn_XcursorImagesLoadCursor _XcursorImagesLoadCursor;
152  pfn_XcursorImagesDestroy _XcursorImagesDestroy;
153  pfn_XcursorImageCreate _XcursorImageCreate;
154  pfn_XcursorImageLoadCursor _XcursorImageLoadCursor;
155  pfn_XcursorImageDestroy _XcursorImageDestroy;
156 
157  typedef Bool (*pfn_XRRQueryExtension)(X11_Display *, int*, int*);
158  typedef Status (*pfn_XRRQueryVersion)(X11_Display *, int*, int*);
159  typedef XRRScreenSize *(*pfn_XRRSizes)(X11_Display*, int, int*);
160  typedef short *(*pfn_XRRRates)(X11_Display*, int, int, int*);
161  typedef XRRScreenConfiguration *(*pfn_XRRGetScreenInfo)(X11_Display*, X11_Window);
162  typedef SizeID (*pfn_XRRConfigCurrentConfiguration)(XRRScreenConfiguration*, Rotation*);
163  typedef Status (*pfn_XRRSetScreenConfig)(X11_Display*, XRRScreenConfiguration *,
164  Drawable, int, Rotation, Time);
165 
166  bool _have_xrandr;
167  pfn_XRRSizes _XRRSizes;
168  pfn_XRRRates _XRRRates;
169  pfn_XRRGetScreenInfo _XRRGetScreenInfo;
170  pfn_XRRConfigCurrentConfiguration _XRRConfigCurrentConfiguration;
171  pfn_XRRSetScreenConfig _XRRSetScreenConfig;
172 
173 protected:
174  X11_Display *_display;
175  int _screen;
176  X11_Window _root;
177  XIM _im;
178 
179  X11_Cursor _hidden_cursor;
180 
181  typedef Bool (*pfn_XF86DGAQueryVersion)(X11_Display *, int*, int*);
182  typedef Status (*pfn_XF86DGADirectVideo)(X11_Display *, int, int);
183  pfn_XF86DGADirectVideo _XF86DGADirectVideo;
184 
185  typedef XRRScreenResources *(*pfn_XRRGetScreenResources)(X11_Display*, X11_Window);
186  typedef XRRCrtcInfo *(*pfn_XRRGetCrtcInfo)(X11_Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
187 
188  pfn_XRRGetScreenResources _XRRGetScreenResourcesCurrent;
189  pfn_XRRFreeScreenResources _XRRFreeScreenResources;
190  pfn_XRRGetCrtcInfo _XRRGetCrtcInfo;
191  pfn_XRRFreeCrtcInfo _XRRFreeCrtcInfo;
192 
193 private:
194  void make_hidden_cursor();
195  void release_hidden_cursor();
196 
197  static void install_error_handlers();
198  static int error_handler(X11_Display *display, XErrorEvent *error);
199  static int io_error_handler(X11_Display *display);
200 
201  typedef int ErrorHandlerFunc(X11_Display *, XErrorEvent *);
202  typedef int IOErrorHandlerFunc(X11_Display *);
203  static bool _error_handlers_installed;
204  static ErrorHandlerFunc *_prev_error_handler;
205  static IOErrorHandlerFunc *_prev_io_error_handler;
206 
207  static bool _x_error_messages_enabled;
208  static int _x_error_count;
209 
210 public:
211  // This Mutex protects any X library calls, which all have to be single-
212  // threaded. In particular, it protects glXMakeCurrent().
213  static LightReMutex _x_mutex;
214 
215 public:
216  static TypeHandle get_class_type() {
217  return _type_handle;
218  }
219  static void init_type() {
220  GraphicsPipe::init_type();
221  register_type(_type_handle, "x11GraphicsPipe",
222  GraphicsPipe::get_class_type());
223  }
224  virtual TypeHandle get_type() const {
225  return get_class_type();
226  }
227  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
228 
229 private:
230  static TypeHandle _type_handle;
231 };
232 
233 #include "x11GraphicsPipe.I"
234 
235 #endif
FrameBufferProperties
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
Definition: frameBufferProperties.h:26
x11GraphicsPipe::get_x_error_count
static int get_x_error_count()
Returns the number of times an error indication has been raised by the X11 system since application s...
Definition: x11GraphicsPipe.I:124
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
x11GraphicsPipe::enable_x_error_messages
static int enable_x_error_messages()
Reenables the printing of error messages after a previous call to disable_x_error_messages().
Definition: x11GraphicsPipe.I:113
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
_XRRModeInfo
Definition: x11GraphicsPipe.h:46
x11GraphicsPipe::get_im
XIM get_im() const
Returns the input method opened for the pipe, or NULL if the input method could not be opened for som...
Definition: x11GraphicsPipe.I:44
x11GraphicsPipe::get_root
X11_Window get_root() const
Returns the handle to the root window on the pipe's display.
Definition: x11GraphicsPipe.I:35
lightMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
x11GraphicsPipe::supports_relative_mouse
bool supports_relative_mouse() const
Returns true if relative mouse mode is supported on this display.
Definition: x11GraphicsPipe.I:64
x11GraphicsPipe.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
x11GraphicsPipe::get_preferred_window_thread
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
Definition: x11GraphicsPipe.cxx:401
graphicsPipe.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
x11GraphicsPipe::get_screen_resources
std::unique_ptr< XRRScreenResources, pfn_XRRFreeScreenResources > get_screen_resources() const
Returns an XRRScreenResources object, or null if RandR 1.2 is not supported.
Definition: x11GraphicsPipe.cxx:336
x11GraphicsPipe::disable_x_error_messages
static int disable_x_error_messages()
Globally disables the printing of error messages that are raised by the X11 system,...
Definition: x11GraphicsPipe.I:101
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
_XRRScreenResources
Definition: x11GraphicsPipe.h:63
_XRRCrtcInfo
Definition: x11GraphicsPipe.h:74
config_x11display.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
windowHandle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_x11.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
x11GraphicsPipe::get_crtc_info
std::unique_ptr< XRRCrtcInfo, pfn_XRRFreeCrtcInfo > get_crtc_info(XRRScreenResources *res, RRCrtc crtc) const
Returns an XRRCrtcInfo object, or null if RandR 1.2 is not supported.
Definition: x11GraphicsPipe.cxx:350
XRRScreenSize
Definition: x11GraphicsPipe.h:41
GraphicsPipe
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
graphicsWindow.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
x11GraphicsPipe::get_hidden_cursor
X11_Cursor get_hidden_cursor()
Returns an invisible Cursor suitable for assigning to windows that have the cursor_hidden property se...
Definition: x11GraphicsPipe.I:53
x11GraphicsPipe::disable_relative_mouse
void disable_relative_mouse()
Disables relative mouse mode for this display.
Definition: x11GraphicsPipe.I:85
x11GraphicsPipe::enable_relative_mouse
bool enable_relative_mouse()
Enables relative mouse mode for this display.
Definition: x11GraphicsPipe.I:72
x11GraphicsPipe::get_screen
int get_screen() const
Returns the X screen number associated with the pipe.
Definition: x11GraphicsPipe.I:27
x11GraphicsPipe::find_fullscreen_crtc
RRCrtc find_fullscreen_crtc(const LPoint2i &point, int &x, int &y, int &width, int &height)
Finds a CRTC for going fullscreen to, at the given origin.
Definition: x11GraphicsPipe.cxx:368
x11GraphicsPipe::get_display
X11_Display * get_display() const
Returns a pointer to the X display associated with the pipe: the display on which to create the windo...
Definition: x11GraphicsPipe.I:19
LightReMutex
A lightweight reentrant mutex.
Definition: lightReMutex.h:32
x11GraphicsPipe
This graphics pipe represents the interface for creating graphics windows on an X-based client.
Definition: x11GraphicsPipe.h:96
lightReMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.