llwindowsdl.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**
  2. * @file llwindowsdl.h
  3. * @brief SDL implementation of LLWindow class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLWINDOWSDL_H
  33. #define LL_LLWINDOWSDL_H
  34. // Simple Directmedia Layer (http://libsdl.org/) implementation of LLWindow
  35. // class
  36. #include "lltimer.h"
  37. #include "llwindow.h"
  38. #include "SDL2/SDL.h"
  39. #include "SDL2/SDL_endian.h"
  40. #include "SDL2/SDL_syswm.h"
  41. #include <X11/Xutil.h>
  42. // For Xlib selection routines
  43. #include <X11/Xlib.h>
  44. #include <X11/Xatom.h>
  45. class LLWindowSDL final : public LLWindow
  46. {
  47. friend class LLWindow;
  48. protected:
  49. LOG_CLASS(LLWindowSDL);
  50. public:
  51. void setWindowTitle(const std::string& title) override;
  52. LL_INLINE void show() override {}
  53. LL_INLINE void hide() override {}
  54. void close() override;
  55. void minimize() override;
  56. void restore() override;
  57. bool getVisible() override;
  58. bool getMinimized() override;
  59. // *TODO
  60. LL_INLINE bool getMaximized() override { return false; }
  61. LL_INLINE bool maximize() override { return false; }
  62. LL_INLINE bool getFullscreen() override { return mFullscreen; }
  63. bool getPosition(LLCoordScreen* pos) override;
  64. bool getSize(LLCoordScreen* size) override;
  65. bool getSize(LLCoordWindow* size) override;
  66. // SDL-specific method needed to force-redraw the screen after a graphics
  67. // benchmark or a GL shared context creation. HB.
  68. void refresh() override;
  69. // *TODO
  70. LL_INLINE bool setPosition(LLCoordScreen pos) override
  71. {
  72. return true;
  73. }
  74. bool setSize(LLCoordScreen size) override;
  75. bool switchContext(bool fullscreen, const LLCoordScreen& size,
  76. bool disable_vsync,
  77. const LLCoordScreen* const posp = NULL) override;
  78. void* createSharedContext() override;
  79. void makeContextCurrent(void* context) override;
  80. void destroySharedContext(void* context) override;
  81. bool setCursorPosition(const LLCoordWindow& position) override;
  82. bool getCursorPosition(LLCoordWindow* position) override;
  83. void showCursor() override;
  84. void hideCursor() override;
  85. void showCursorFromMouseMove() override;
  86. void hideCursorUntilMouseMove() override;
  87. LL_INLINE bool isCursorHidden() override { return mCursorHidden; }
  88. void setCursor(ECursorType cursor) override;
  89. void captureMouse() override;
  90. void releaseMouse() override;
  91. void setMouseClipping(bool b) override;
  92. bool isClipboardTextAvailable() override;
  93. bool pasteTextFromClipboard(LLWString& text) override;
  94. bool copyTextToClipboard(const LLWString& text) override;
  95. bool isPrimaryTextAvailable() override;
  96. bool pasteTextFromPrimary(LLWString& text) override;
  97. bool copyTextToPrimary(const LLWString& text) override;
  98. void flashIcon(F32 seconds) override;
  99. // Sets the gamma
  100. bool setGamma(F32 gamma) override;
  101. LL_INLINE U32 getFSAASamples() override { return mFSAASamples; }
  102. LL_INLINE void setFSAASamples(U32 n) override { mFSAASamples = n; }
  103. // Restore original gamma table (before updating gamma):
  104. bool restoreGamma() override;
  105. ESwapMethod getSwapMethod() override { return mSwapMethod; }
  106. void gatherInput() override;
  107. void swapBuffers() override;
  108. LL_INLINE void delayInputProcessing() override {}
  109. // Handy coordinate space conversion routines
  110. bool convertCoords(LLCoordScreen from, LLCoordWindow* to) override;
  111. bool convertCoords(LLCoordWindow from, LLCoordScreen* to) override;
  112. bool convertCoords(LLCoordWindow from, LLCoordGL* to) override;
  113. bool convertCoords(LLCoordGL from, LLCoordWindow* to) override;
  114. bool convertCoords(LLCoordScreen from, LLCoordGL* to) override;
  115. bool convertCoords(LLCoordGL from, LLCoordScreen* to) override;
  116. LLWindowResolution* getSupportedResolutions(S32& num_res) override;
  117. F32 getNativeAspectRatio() override;
  118. F32 getPixelAspectRatio() override;
  119. void beforeDialog() override;
  120. void afterDialog() override;
  121. void* getPlatformWindow() override;
  122. void bringToFront() override;
  123. void spawnWebBrowser(const std::string& escaped_url, bool async) override;
  124. // *HACK: to compute window borders offsets
  125. void calculateBordersOffsets() override;
  126. bool getSelectionText(Atom selection, LLWString& text);
  127. bool setSelectionText(Atom selection, const LLWString& text);
  128. LL_INLINE LLWString& getPrimaryText() { return mPrimaryClipboard; }
  129. LL_INLINE LLWString& getSecondaryText() { return mSecondaryClipboard; }
  130. LL_INLINE void clearPrimaryText() { mPrimaryClipboard.clear(); }
  131. LL_INLINE void clearSecondaryText() { mSecondaryClipboard.clear(); }
  132. static void initXlibThreads();
  133. static Window getSDLXWindowID();
  134. static Display* getSDLDisplay();
  135. static std::vector<std::string> getDynamicFallbackFontList();
  136. protected:
  137. LLWindowSDL(const std::string& title, S32 x, S32 y, U32 width, U32 height,
  138. U32 flags, bool fullscreen, bool disable_vsync,
  139. U32 fsaa_samples);
  140. ~LLWindowSDL() override;
  141. LL_INLINE bool isValid() override { return mWindow != NULL; }
  142. LLSD getNativeKeyData() override;
  143. void initCursors();
  144. void quitCursors();
  145. void moveWindow(const LLCoordScreen& position, const LLCoordScreen& size);
  146. //
  147. // Platform specific methods
  148. //
  149. // Creates or re-creates the GL context/window. Called from the constructor
  150. // and switchContext():
  151. bool createContext(S32 x, S32 y, S32 width, S32 height, S32 bits,
  152. bool fullscreen, bool disable_vsync);
  153. void destroyContext();
  154. void setupFailure(const std::string& text);
  155. void fixWindowSize();
  156. U32 SDLCheckGrabbyKeys(U32 keysym, bool gain);
  157. bool SDLReallyCaptureInput(bool capture);
  158. void x11_set_urgent(bool urgent);
  159. void initialiseX11Clipboard();
  160. private:
  161. void setWindowIcon();
  162. // Returns true when successful, false otherwise.
  163. bool getFullScreenSize(S32& width, S32& height);
  164. public:
  165. // Not great that these are public, but they have to be accessible
  166. // by non-class code and it is better than making them global.
  167. Window mSDL_XWindowID;
  168. Display* mSDL_Display;
  169. SDL_Window* mWindow;
  170. protected:
  171. //
  172. // Platform specific variables
  173. //
  174. SDL_GLContext mContext;
  175. S32 mInitialPosX;
  176. S32 mInitialPosY;
  177. S32 mPosOffsetX;
  178. S32 mPosOffsetY;
  179. std::string mWindowTitle;
  180. F32 mOriginalAspectRatio;
  181. U32 mFSAASamples;
  182. S32 mSDLFlags;
  183. SDL_Cursor* mSDLCursors[UI_CURSOR_COUNT];
  184. U16 mPrevGammaRamp[3][256];
  185. U16 mCurrentGammaRamp[256];
  186. U32 mKeyModifiers;
  187. U32 mKeyVirtualKey;
  188. LLWString mSecondaryClipboard;
  189. U32 mGrabbyKeyFlags;
  190. bool mCaptured;
  191. LLTimer mFlashTimer;
  192. bool mFlashing;
  193. bool mCustomGammaSet;
  194. };
  195. class HBSplashScreenSDLImpl;
  196. class LLSplashScreenSDL final : public LLSplashScreen
  197. {
  198. public:
  199. LLSplashScreenSDL();
  200. ~LLSplashScreenSDL() override;
  201. void showImpl() override;
  202. void updateImpl(const std::string& mesg) override;
  203. void hideImpl() override;
  204. private:
  205. HBSplashScreenSDLImpl* mImpl;
  206. };
  207. S32 OSMessageBoxSDL(const std::string& text, const std::string& caption,
  208. U32 type);
  209. extern bool gXlibThreadSafe;
  210. extern bool gXWayland;
  211. extern bool gUseFullDesktop;
  212. #endif // LL_LLWINDOWSDL_H