nux-0.9.46
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef GRAPHICSDISPLAYX11_H 00024 #define GRAPHICSDISPLAYX11_H 00025 00026 #include "Gfx_Interface.h" 00027 #include "GLTimer.h" 00028 #include "GLDeviceObjects.h" 00029 #include "GLRenderStates.h" 00030 00031 /* Xlib.h is the default header that is included and has the core functionallity */ 00032 #include <X11/Xlib.h> 00033 /* Xatom.h includes functionallity for creating new protocol messages */ 00034 #include <X11/Xatom.h> 00035 /* keysym.h contains keysymbols which we use to resolv what keys that are being pressed */ 00036 #include <X11/keysym.h> 00037 00038 #include <X11/extensions/xf86vmode.h> 00039 00040 namespace nux 00041 { 00042 00043 class Event; 00044 class MainFBO; 00045 class GpuDevice; 00046 class GraphicsEngine; 00047 class IOpenGLFrameBufferObject; 00048 00049 enum WindowStyle 00050 { 00051 WINDOWSTYLE_NORMAL, 00052 WINDOWSTYLE_PANEL, 00053 WINDOWSTYLE_DIALOG, 00054 WINDOWSTYLE_TOOL, 00055 WINDOWSTYLE_NOBORDER, 00056 }; 00057 00058 enum DndAction 00059 { 00060 DNDACTION_COPY, 00061 DNDACTION_MOVE, 00062 DNDACTION_LINK, 00063 DNDACTION_ASK, 00064 DNDACTION_PRIVATE, 00065 00066 DNDACTION_NONE, 00067 }; 00068 00069 #define NUX_THREADMSG (WM_APP+0) 00070 #define NUX_THREADMSG_START_RENDERING (WM_APP+1) // Connection established // start at WM_APP 00071 #define NUX_THREADMSG_CHILD_WINDOW_TERMINATED (WM_APP+2) // General failure - Wait Connection failed 00072 #define NUX_THREADMSG_THREAD_TERMINATED (WM_APP+3) // Set wParam = Thread ID, lParam = 0 00073 00074 #define _xdnd_max_type 100 00075 #define xdnd_version 5 00076 00077 // This will become GLWindow 00078 class GraphicsDisplay : public GraphicSystem 00079 { 00080 friend class GraphicsEngine; 00081 00082 private: 00083 Display *m_X11Display; 00084 int m_X11Screen; 00085 Window m_X11Window; 00086 XVisualInfo *m_X11VisualInfo; 00087 00088 int m_ParentWindow; 00089 GLXContext m_GLCtx; 00090 GLXFBConfig _fb_config; 00091 XSetWindowAttributes m_X11Attr; 00092 00093 int m_NumVideoModes; 00094 XF86VidModeModeInfo **m_X11VideoModes; 00095 /* original desktop mode which we save so we can restore it later */ 00096 XF86VidModeModeInfo m_X11OriginalVideoMode; 00097 00098 Atom m_WMDeleteWindow; 00099 Colormap m_X11Colormap; 00100 int m_BorderPixel; 00101 00102 int _x11_major; 00103 int _x11_minor; 00104 int _glx_major; 00105 int _glx_minor; 00106 bool _has_glx_13; 00107 00108 XEvent m_X11LastEvent; 00109 Bool m_X11RepeatKey; 00110 00111 TCHAR m_WindowClassName[256]; 00112 GLuint m_PixelFormat; // Holds The Results After Searching For A Match 00113 NString m_WindowTitle; 00114 00115 // size, position 00116 Size m_ViewportSize; 00117 Size m_WindowSize; 00118 Point m_WindowPosition; 00119 00120 // surface attibute; 00121 bool m_Fullscreen; 00122 unsigned int m_ScreenBitDepth; 00123 00124 // verifiy that the interface is properly created 00125 bool m_GfxInterfaceCreated; 00126 00127 // Device information 00128 void GetDisplayInfo(); 00129 int m_BestMode; 00130 00131 bool m_CreatedFromForeignWindow; 00132 00133 public: 00134 typedef void (*GrabReleaseCallback) (bool replaced, void *user_data); 00135 00136 typedef struct _DndSourceFuncs 00137 { 00138 nux::NBitmapData * (*get_drag_image) (void * data); 00139 std::list<const char *> (*get_drag_types) (void * data); 00140 const char * (*get_data_for_type) (const char * type, int *size, int *format, void * data); 00141 void (*drag_finished) (DndAction result, void * data); 00142 } DndSourceFuncs; 00143 00144 bool HasXPendingEvent() const; 00145 Display *GetX11Display() 00146 { 00147 return m_X11Display; 00148 } 00149 // Device 00150 int m_num_device_modes; 00151 00152 // Event object 00153 IEvent *m_pEvent; 00154 00155 bool IsGfxInterfaceCreated(); 00156 00158 00166 bool CreateOpenGLWindow ( 00167 const TCHAR *WindowTitle, 00168 unsigned int WindowWidth, 00169 unsigned int WindowHeight, 00170 WindowStyle Style, 00171 const GraphicsDisplay *Parent, 00172 bool FullscreenFlag = false, 00173 bool create_rendering_data = true); 00174 00176 00180 bool CreateFromOpenGLWindow (Display *X11Display, Window X11Window, GLXContext OpenGLContext); 00181 00182 void DestroyOpenGLWindow(); 00183 00184 void SetWindowTitle (const TCHAR *Title); 00185 00187 00191 void SetWindowSize (int width, int height); 00192 00194 void SetWindowPosition (int width, int height); 00195 00197 void SetViewPort (int x, int y, int width, int height); 00198 00199 Point GetMouseScreenCoord(); 00200 Point GetMouseWindowCoord(); 00201 Point GetWindowCoord(); 00202 Rect GetWindowGeometry(); 00203 Rect GetNCWindowGeometry(); 00204 void MakeGLContextCurrent(); 00205 void SwapBuffer (bool glswap = true); 00206 00207 // Event methods 00208 void GetSystemEvent (IEvent *evt); 00209 00210 // Os specific 00211 int GetGlXMajor () const; 00212 int GetGlXMinor () const; 00213 00214 #if defined (NUX_OS_LINUX) 00215 void InjectXEvent (IEvent *evt, XEvent xevent); 00216 #endif 00217 00218 IEvent &GetCurrentEvent(); 00219 00220 // That method is deprecated, it always returns false and still here in 00221 // order to maintain API compatibility. 00222 bool isWindowMinimized() const 00223 { 00224 return false; 00225 } 00226 00227 void ShowWindow(); 00228 void HideWindow(); 00229 bool IsWindowVisible (); 00230 00231 void EnterMaximizeWindow(); 00232 void ExitMaximizeWindow(); 00233 00234 Window GetWindowHandle() const 00235 { 00236 return m_X11Window; 00237 } 00238 bool IsChildWindow() const 00239 { 00240 return m_ParentWindow != 0; 00241 } 00242 00243 // Return true if VSync swap control is available 00244 bool HasVSyncSwapControl() const; 00245 void EnableVSyncSwapControl(); 00246 void DisableVSyncSwapControl(); 00247 00248 // m_FrameRate 00249 float GetFrameTime() const; 00250 void ResetFrameTime(); 00251 00252 GraphicsEngine *GetGraphicsEngine() const 00253 { 00254 return m_GraphicsContext; 00255 } 00256 GpuDevice *GetGpuDevice () const 00257 { 00258 return m_DeviceFactory; 00259 } 00260 // Dialog 00261 /*bool StartOpenFileDialog(FileDialogOption& fdo); 00262 bool StartSaveFileDialog(FileDialogOption& fdo); 00263 bool StartColorDialog(ColorDialogOption& cdo);*/ 00264 00265 00266 void GetDesktopSize (int &w, int &h); 00267 void GetWindowSize (int &w, int &h); 00268 int GetWindowWidth (); 00269 int GetWindowHeight (); 00270 00272 00277 void ResetWindowSize (); 00278 00279 bool HasFrameBufferSupport(); 00280 /*void SetWindowCursor(HCURSOR cursor); 00281 HCURSOR GetWindowCursor() const;*/ 00282 00283 00285 00294 void PauseThreadGraphicsRendering(); 00295 bool IsPauseThreadGraphicsRendering() const; 00296 00297 void ProcessForeignX11Event (XEvent *xevent, IEvent *nux_event); 00298 void ProcessXEvent (XEvent xevent, bool foreign); 00299 void RecalcXYPosition (Window TheMainWindow, XEvent xevent, int &x, int &y); 00300 void RecalcXYPosition (int x_root, int y_root, int &x_recalc, int &y_recalc); 00301 00302 void SendDndStatus (bool accept, DndAction action, Rect region); 00303 void SendDndFinished (bool accepted, DndAction performed_action); 00304 std::list<char *> GetDndMimeTypes (); 00305 char * GetDndData (char *property); 00306 00307 void StartDndDrag (const DndSourceFuncs &funcs, void *user_data); 00308 00309 bool GrabPointer (GrabReleaseCallback callback, void *data, bool replace_existing); 00310 bool UngrabPointer (void *data); 00311 bool PointerIsGrabbed (); 00312 00313 bool GrabKeyboard (GrabReleaseCallback callback, void *data, bool replace_existing); 00314 bool UngrabKeyboard (void *data); 00315 bool KeyboardIsGrabbed (); 00316 00317 void * KeyboardGrabData () { return _global_keyboard_grab_data; } 00318 void * PointerGrabData () { return _global_pointer_grab_data; } 00319 private: 00320 void InitGlobalGrabWindow (); 00321 00322 void HandleXDndPosition (XEvent event, Event* nux_event); 00323 void HandleXDndEnter (XEvent event); 00324 void HandleXDndStatus (XEvent event); 00325 void HandleXDndLeave (XEvent event); 00326 void HandleXDndDrop (XEvent event, Event* nux_event); 00327 void HandleXDndFinished (XEvent event); 00328 00329 void SendXDndStatus (Display *display, Window source, Window target, bool accept, Atom action, Rect box); 00330 bool GetXDndSelectionEvent (Display *display, Window target, Atom property, long time, XEvent *result, int attempts); 00331 void SendXDndFinished (Display *display, Window source, Window target, bool result, Atom action); 00332 char * GetXDndData (Display *display, Window requestor, Atom property, long time); 00333 00334 void EndDndDrag (DndAction action); 00335 bool GrabDndSelection (Display *display, Window window, Time time); 00336 void HandleDndDragSourceEvent (XEvent event); 00337 void HandleDndSelectionRequest (XEvent event); 00338 Window GetDndTargetWindowForPos (int x, int y); 00339 00340 void DrawDndSourceWindow (); 00341 00342 void SendDndSourcePosition (Window target, int x, int y, Time time); 00343 void SendDndSourceEnter (Window target); 00344 void SendDndSourceLeave (Window target); 00345 void SendDndSourceDrop (Window target, Time time); 00346 void SetDndSourceTargetWindow (Window target); 00347 00348 static gboolean OnDragEndTimeout (gpointer data); 00349 00350 Point _last_dnd_position; 00351 00352 bool m_PauseGraphicsRendering; 00353 GLTimer m_Timer; 00354 float m_FrameTime; 00355 GpuDevice *m_DeviceFactory; 00356 GraphicsEngine *m_GraphicsContext; 00357 WindowStyle m_Style; 00358 00359 Atom _xdnd_types[_xdnd_max_type + 1]; 00360 Display *_drag_display; 00361 Window _drag_window; 00362 Window _drag_source; 00363 long _drag_drop_timestamp; 00364 00365 void * _dnd_source_data; 00366 DndSourceFuncs _dnd_source_funcs; 00367 00368 Window _dnd_source_window; 00369 Window _dnd_source_target_window; 00370 00371 Window _global_grab_window; 00372 00373 void *_global_pointer_grab_data; 00374 bool _global_pointer_grab_active; 00375 GrabReleaseCallback _global_pointer_grab_callback; 00376 00377 void *_global_keyboard_grab_data; 00378 bool _global_keyboard_grab_active; 00379 GrabReleaseCallback _global_keyboard_grab_callback; 00380 00381 bool _dnd_is_drag_source; 00382 bool _dnd_source_target_accepts_drop; 00383 bool _dnd_source_grab_active; 00384 bool _dnd_source_drop_sent; 00385 public: 00386 ~GraphicsDisplay(); 00387 GLEWContext *GetGLEWContext() 00388 { 00389 return &m_GLEWContext; 00390 } 00391 GLXEWContext *GetGLXEWContext() 00392 { 00393 return &m_GLXEWContext; 00394 } 00395 00396 NString FindResourceLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false); 00397 NString FindUITextureLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false); 00398 NString FindShaderLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false); 00399 NString FindFontLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false); 00400 00401 const std::vector<NString>& GetFontSearchPath() const 00402 { 00403 return m_FontSearchPath; 00404 } 00405 const std::vector<NString>& GetShaderSearchPath() const 00406 { 00407 return m_ShaderSearchPath; 00408 } 00409 const std::vector<NString>& GetUITextureSearchPath() const 00410 { 00411 return m_UITextureSearchPath; 00412 } 00413 00414 private: 00415 std::vector<NString> m_FontSearchPath; 00416 std::vector<NString> m_ShaderSearchPath; 00417 std::vector<NString> m_UITextureSearchPath; 00418 FilePath m_ResourcePathLocation; 00419 00420 GraphicsDisplay(); 00421 GraphicsDisplay (const GraphicsDisplay &); 00422 // Does not make sense for a singleton. This is a self assignment. 00423 GraphicsDisplay &operator= (const GraphicsDisplay &); 00424 00425 GLEWContext m_GLEWContext; 00426 GLXEWContext m_GLXEWContext; 00427 friend class DisplayAccessController; 00428 }; 00429 00430 } 00431 00432 #endif //GRAPHICSDISPLAYX11_H