CmGLXWindow.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #include "CmGLXWindow.h"
  25. #include "CmGLRenderSystem.h"
  26. #include "CmException.h"
  27. #include "CmStringConverter.h"
  28. #include "CmGLXUtils.h"
  29. #include "CmGLXGLSupport.h"
  30. #include "CmGLPixelFormat.h"
  31. #include "CmWindowEventUtilities.h"
  32. #include <iostream>
  33. #include <algorithm>
  34. #include <sys/time.h>
  35. #include <climits>
  36. #include <X11/Xlib.h>
  37. #include <X11/keysym.h>
  38. #include <X11/extensions/Xrandr.h>
  39. extern "C"
  40. {
  41. int
  42. safeXErrorHandler (Display *display, XErrorEvent *event)
  43. {
  44. // Ignore all XErrorEvents
  45. return 0;
  46. }
  47. int (*oldXErrorHandler)(Display *, XErrorEvent*);
  48. }
  49. namespace CamelotEngine
  50. {
  51. //-------------------------------------------------------------------------------------------------//
  52. GLXWindow::GLXWindow(GLXGLSupport *glsupport) :
  53. mGLSupport(glsupport), mContext(0)
  54. {
  55. mWindow = 0;
  56. mIsTopLevel = false;
  57. mIsFullScreen = false;
  58. mIsExternal = false;
  59. mIsExternalGLControl = false;
  60. mClosed = false;
  61. mActive = false;
  62. }
  63. //-------------------------------------------------------------------------------------------------//
  64. GLXWindow::~GLXWindow()
  65. {
  66. Display* xDisplay = mGLSupport->getXDisplay();
  67. destroy();
  68. // Ignore fatal XErrorEvents from stale handles.
  69. oldXErrorHandler = XSetErrorHandler(safeXErrorHandler);
  70. if (mWindow)
  71. {
  72. XDestroyWindow(xDisplay, mWindow);
  73. }
  74. if (mContext)
  75. {
  76. delete mContext;
  77. }
  78. XSetErrorHandler(oldXErrorHandler);
  79. mContext = 0;
  80. mWindow = 0;
  81. }
  82. //-------------------------------------------------------------------------------------------------//
  83. void GLXWindow::create(const String& name, uint width, uint height,
  84. bool fullScreen, const NameValuePairList *miscParams)
  85. {
  86. Display *xDisplay = mGLSupport->getXDisplay();
  87. String title = name;
  88. uint samples = 0;
  89. short frequency = 0;
  90. bool vsync = false;
  91. unsigned int vsyncInterval = 1;
  92. int gamma = 0;
  93. ::GLXContext glxContext = 0;
  94. ::GLXDrawable glxDrawable = 0;
  95. Window externalWindow = 0;
  96. Window parentWindow = DefaultRootWindow(xDisplay);
  97. int left = DisplayWidth(xDisplay, DefaultScreen(xDisplay))/2 - width/2;
  98. int top = DisplayHeight(xDisplay, DefaultScreen(xDisplay))/2 - height/2;
  99. mIsFullScreen = fullScreen;
  100. if(miscParams)
  101. {
  102. NameValuePairList::const_iterator opt;
  103. NameValuePairList::const_iterator end = miscParams->end();
  104. // NB: Do not try to implement the externalGLContext option.
  105. //
  106. // Accepting a non-current context would expose us to the
  107. // risk of segfaults when we made it current. Since the
  108. // application programmers would be responsible for these
  109. // segfaults, they are better discovering them in their code.
  110. if ((opt = miscParams->find("currentGLContext")) != end &&
  111. StringConverter::parseBool(opt->second))
  112. {
  113. if (! glXGetCurrentContext())
  114. {
  115. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "currentGLContext was specified with no current GL context", "GLXWindow::create");
  116. }
  117. glxContext = glXGetCurrentContext();
  118. glxDrawable = glXGetCurrentDrawable();
  119. }
  120. // Note: Some platforms support AA inside ordinary windows
  121. if((opt = miscParams->find("FSAA")) != end)
  122. samples = StringConverter::parseUnsignedInt(opt->second);
  123. if((opt = miscParams->find("displayFrequency")) != end)
  124. frequency = (short)StringConverter::parseInt(opt->second);
  125. if((opt = miscParams->find("vsync")) != end)
  126. vsync = StringConverter::parseBool(opt->second);
  127. if((opt = miscParams->find("vsyncInterval")) != end)
  128. vsyncInterval = StringConverter::parseUnsignedInt(opt->second);
  129. if ((opt = miscParams->find("gamma")) != end)
  130. gamma = StringConverter::parseBool(opt->second);
  131. if((opt = miscParams->find("left")) != end)
  132. left = StringConverter::parseInt(opt->second);
  133. if((opt = miscParams->find("top")) != end)
  134. top = StringConverter::parseInt(opt->second);
  135. if((opt = miscParams->find("title")) != end)
  136. title = opt->second;
  137. if ((opt = miscParams->find("externalGLControl")) != end)
  138. mIsExternalGLControl = StringConverter::parseBool(opt->second);
  139. if((opt = miscParams->find("parentWindowHandle")) != end)
  140. {
  141. vector<String>::type tokens = StringUtil::split(opt->second, " :");
  142. if (tokens.size() == 3)
  143. {
  144. // deprecated display:screen:xid format
  145. parentWindow = StringConverter::parseUnsignedLong(tokens[2]);
  146. }
  147. else
  148. {
  149. // xid format
  150. parentWindow = StringConverter::parseUnsignedLong(tokens[0]);
  151. }
  152. }
  153. else if((opt = miscParams->find("externalWindowHandle")) != end)
  154. {
  155. vector<String>::type tokens = StringUtil::split(opt->second, " :");
  156. LogManager::getSingleton().logMessage(
  157. "GLXWindow::create: The externalWindowHandle parameter is deprecated.\n"
  158. "Use the parentWindowHandle or currentGLContext parameter instead.");
  159. if (tokens.size() == 3)
  160. {
  161. // Old display:screen:xid format
  162. // The old GLX code always created a "parent" window in this case:
  163. parentWindow = StringConverter::parseUnsignedLong(tokens[2]);
  164. }
  165. else if (tokens.size() == 4)
  166. {
  167. // Old display:screen:xid:visualinfo format
  168. externalWindow = StringConverter::parseUnsignedLong(tokens[2]);
  169. }
  170. else
  171. {
  172. // xid format
  173. externalWindow = StringConverter::parseUnsignedLong(tokens[0]);
  174. }
  175. }
  176. }
  177. // Ignore fatal XErrorEvents during parameter validation:
  178. oldXErrorHandler = XSetErrorHandler(safeXErrorHandler);
  179. // Validate parentWindowHandle
  180. if (parentWindow != DefaultRootWindow(xDisplay))
  181. {
  182. XWindowAttributes windowAttrib;
  183. if (! XGetWindowAttributes(xDisplay, parentWindow, &windowAttrib) ||
  184. windowAttrib.root != DefaultRootWindow(xDisplay))
  185. {
  186. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid parentWindowHandle (wrong server or screen)", "GLXWindow::create");
  187. }
  188. }
  189. // Validate externalWindowHandle
  190. if (externalWindow != 0)
  191. {
  192. XWindowAttributes windowAttrib;
  193. if (! XGetWindowAttributes(xDisplay, externalWindow, &windowAttrib) ||
  194. windowAttrib.root != DefaultRootWindow(xDisplay))
  195. {
  196. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid externalWindowHandle (wrong server or screen)", "GLXWindow::create");
  197. }
  198. glxDrawable = externalWindow;
  199. }
  200. // Derive fbConfig
  201. ::GLXFBConfig fbConfig = 0;
  202. if (glxDrawable)
  203. {
  204. fbConfig = mGLSupport->getFBConfigFromDrawable (glxDrawable, &width, &height);
  205. }
  206. if (! fbConfig && glxContext)
  207. {
  208. fbConfig = mGLSupport->getFBConfigFromContext (glxContext);
  209. }
  210. mIsExternal = (glxDrawable != 0);
  211. XSetErrorHandler(oldXErrorHandler);
  212. if (! fbConfig)
  213. {
  214. int minAttribs[] = {
  215. GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
  216. GLX_RENDER_TYPE, GLX_RGBA_BIT,
  217. GLX_RED_SIZE, 1,
  218. GLX_BLUE_SIZE, 1,
  219. GLX_GREEN_SIZE, 1,
  220. None
  221. };
  222. int maxAttribs[] = {
  223. GLX_SAMPLES, samples,
  224. GLX_DOUBLEBUFFER, 1,
  225. GLX_STENCIL_SIZE, INT_MAX,
  226. GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, 1,
  227. None
  228. };
  229. fbConfig = mGLSupport->selectFBConfig(minAttribs, maxAttribs);
  230. if (gamma != 0)
  231. {
  232. mGLSupport->getFBConfigAttrib(fbConfig, GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &gamma);
  233. }
  234. mHwGamma = (gamma != 0);
  235. }
  236. if (! fbConfig)
  237. {
  238. // This should never happen.
  239. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unexpected failure to determine a GLXFBConfig","GLXWindow::create");
  240. }
  241. mIsTopLevel = (! mIsExternal && parentWindow == DefaultRootWindow(xDisplay));
  242. if (! mIsTopLevel)
  243. {
  244. mIsFullScreen = false;
  245. left = top = 0;
  246. }
  247. if (mIsFullScreen)
  248. {
  249. mGLSupport->switchMode (width, height, frequency);
  250. }
  251. if (! mIsExternal)
  252. {
  253. XSetWindowAttributes attr;
  254. ulong mask;
  255. XVisualInfo *visualInfo = mGLSupport->getVisualFromFBConfig (fbConfig);
  256. attr.background_pixel = 0;
  257. attr.border_pixel = 0;
  258. attr.colormap = XCreateColormap(xDisplay, DefaultRootWindow(xDisplay), visualInfo->visual, AllocNone);
  259. attr.event_mask = StructureNotifyMask | VisibilityChangeMask | FocusChangeMask;
  260. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  261. if(mIsFullScreen && mGLSupport->mAtomFullScreen == None)
  262. {
  263. LogManager::getSingleton().logMessage("GLXWindow::switchFullScreen: Your WM has no fullscreen support");
  264. // A second best approach for outdated window managers
  265. attr.backing_store = NotUseful;
  266. attr.save_under = False;
  267. attr.override_redirect = True;
  268. mask |= CWSaveUnder | CWBackingStore | CWOverrideRedirect;
  269. left = top = 0;
  270. }
  271. // Create window on server
  272. mWindow = XCreateWindow(xDisplay, parentWindow, left, top, width, height, 0, visualInfo->depth, InputOutput, visualInfo->visual, mask, &attr);
  273. XFree(visualInfo);
  274. if(!mWindow)
  275. {
  276. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to create an X Window", "GLXWindow::create");
  277. }
  278. if (mIsTopLevel)
  279. {
  280. XWMHints *wmHints;
  281. XSizeHints *sizeHints;
  282. if ((wmHints = XAllocWMHints()) != NULL)
  283. {
  284. wmHints->initial_state = NormalState;
  285. wmHints->input = True;
  286. wmHints->flags = StateHint | InputHint;
  287. int depth = DisplayPlanes(xDisplay, DefaultScreen(xDisplay));
  288. // Check if we can give it an icon
  289. if(depth == 24 || depth == 32)
  290. {
  291. if(mGLSupport->loadIcon("GLX_icon.png", &wmHints->icon_pixmap, &wmHints->icon_mask))
  292. {
  293. wmHints->flags |= IconPixmapHint | IconMaskHint;
  294. }
  295. }
  296. }
  297. // Is this really necessary ? Which broken WM might need it?
  298. if ((sizeHints = XAllocSizeHints()) != NULL)
  299. {
  300. sizeHints->flags = USPosition;
  301. }
  302. XTextProperty titleprop;
  303. char *lst = (char*)title.c_str();
  304. XStringListToTextProperty((char **)&lst, 1, &titleprop);
  305. XSetWMProperties(xDisplay, mWindow, &titleprop, NULL, NULL, 0, sizeHints, wmHints, NULL);
  306. XFree(titleprop.value);
  307. XFree(wmHints);
  308. XFree(sizeHints);
  309. XSetWMProtocols(xDisplay, mWindow, &mGLSupport->mAtomDeleteWindow, 1);
  310. XWindowAttributes windowAttrib;
  311. XGetWindowAttributes(xDisplay, mWindow, &windowAttrib);
  312. left = windowAttrib.x;
  313. top = windowAttrib.y;
  314. width = windowAttrib.width;
  315. height = windowAttrib.height;
  316. }
  317. glxDrawable = mWindow;
  318. XMapWindow(xDisplay, mWindow);
  319. if (mIsFullScreen)
  320. {
  321. switchFullScreen (true);
  322. }
  323. XFlush(xDisplay);
  324. WindowEventUtilities::_addRenderWindow(this);
  325. }
  326. mContext = new GLXContext(mGLSupport, fbConfig, glxDrawable, glxContext);
  327. ::GLXDrawable oldDrawable = glXGetCurrentDrawable();
  328. ::GLXContext oldContext = glXGetCurrentContext();
  329. mContext->setCurrent();
  330. if (! mIsExternalGLControl && GLXEW_SGI_swap_control)
  331. {
  332. glXSwapIntervalSGI (vsync ? vsyncInterval : 0);
  333. }
  334. mContext->endCurrent();
  335. glXMakeCurrent (mGLSupport->getGLDisplay(), oldDrawable, oldContext);
  336. int fbConfigID;
  337. mGLSupport->getFBConfigAttrib(fbConfig, GLX_FBCONFIG_ID, &fbConfigID);
  338. LogManager::getSingleton().logMessage("GLXWindow::create used FBConfigID = " + StringConverter::toString(fbConfigID));
  339. mName = name;
  340. mWidth = width;
  341. mHeight = height;
  342. mLeft = left;
  343. mTop = top;
  344. mActive = true;
  345. mClosed = false;
  346. }
  347. //-------------------------------------------------------------------------------------------------//
  348. void GLXWindow::destroy(void)
  349. {
  350. if (mClosed)
  351. return;
  352. mClosed = true;
  353. mActive = false;
  354. if (! mIsExternal)
  355. WindowEventUtilities::_removeRenderWindow(this);
  356. if (mIsFullScreen)
  357. {
  358. mGLSupport->switchMode();
  359. switchFullScreen(false);
  360. }
  361. }
  362. //-------------------------------------------------------------------------------------------------//
  363. void GLXWindow::setFullscreen(bool fullscreen, uint width, uint height)
  364. {
  365. short frequency = 0;
  366. if (mClosed || ! mIsTopLevel)
  367. return;
  368. if (fullscreen == mIsFullScreen && width == mWidth && height == mHeight)
  369. return;
  370. if (mIsFullScreen != fullscreen && &mGLSupport->mAtomFullScreen == None)
  371. {
  372. // Without WM support it is best to give up.
  373. LogManager::getSingleton().logMessage("GLXWindow::switchFullScreen: Your WM has no fullscreen support");
  374. return;
  375. }
  376. else if (fullscreen)
  377. {
  378. mGLSupport->switchMode(width, height, frequency);
  379. }
  380. else
  381. {
  382. mGLSupport->switchMode();
  383. }
  384. if (mIsFullScreen != fullscreen)
  385. {
  386. switchFullScreen(fullscreen);
  387. }
  388. if (! mIsFullScreen)
  389. {
  390. resize(width, height);
  391. reposition(mLeft, mTop);
  392. }
  393. }
  394. //-------------------------------------------------------------------------------------------------//
  395. bool GLXWindow::isClosed() const
  396. {
  397. return mClosed;
  398. }
  399. //-------------------------------------------------------------------------------------------------//
  400. bool GLXWindow::isVisible() const
  401. {
  402. return mVisible;
  403. }
  404. //-------------------------------------------------------------------------------------------------//
  405. void GLXWindow::setVisible(bool visible)
  406. {
  407. mVisible = visible;
  408. }
  409. //-------------------------------------------------------------------------------------------------//
  410. void GLXWindow::reposition(int left, int top)
  411. {
  412. if (mClosed || ! mIsTopLevel)
  413. return;
  414. XMoveWindow(mGLSupport->getXDisplay(), mWindow, left, top);
  415. }
  416. //-------------------------------------------------------------------------------------------------//
  417. void GLXWindow::resize(uint width, uint height)
  418. {
  419. if (mClosed)
  420. return;
  421. if(mWidth == width && mHeight == height)
  422. return;
  423. if(width != 0 && height != 0)
  424. {
  425. if (!mIsExternal)
  426. {
  427. XResizeWindow(mGLSupport->getXDisplay(), mWindow, width, height);
  428. }
  429. else
  430. {
  431. mWidth = width;
  432. mHeight = height;
  433. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  434. (*it).second->_updateDimensions();
  435. }
  436. }
  437. }
  438. //-------------------------------------------------------------------------------------------------//
  439. void GLXWindow::windowMovedOrResized()
  440. {
  441. if (mClosed || !mWindow)
  442. return;
  443. Display* xDisplay = mGLSupport->getXDisplay();
  444. XWindowAttributes windowAttrib;
  445. if (mIsTopLevel && !mIsFullScreen)
  446. {
  447. Window parent, root, *children;
  448. uint nChildren;
  449. XQueryTree(xDisplay, mWindow, &root, &parent, &children, &nChildren);
  450. if (children)
  451. XFree(children);
  452. XGetWindowAttributes(xDisplay, parent, &windowAttrib);
  453. mLeft = windowAttrib.x;
  454. mTop = windowAttrib.y;
  455. }
  456. XGetWindowAttributes(xDisplay, mWindow, &windowAttrib);
  457. if (mWidth == windowAttrib.width && mHeight == windowAttrib.height)
  458. return;
  459. mWidth = windowAttrib.width;
  460. mHeight = windowAttrib.height;
  461. for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
  462. (*it).second->_updateDimensions();
  463. }
  464. //-------------------------------------------------------------------------------------------------//
  465. void GLXWindow::swapBuffers(bool waitForVSync)
  466. {
  467. if (mClosed || mIsExternalGLControl)
  468. return;
  469. glXSwapBuffers(mGLSupport->getGLDisplay(), mContext->mDrawable);
  470. }
  471. //-------------------------------------------------------------------------------------------------//
  472. void GLXWindow::getCustomAttribute( const String& name, void* pData )
  473. {
  474. if( name == "DISPLAY NAME" )
  475. {
  476. *static_cast<String*>(pData) = mGLSupport->getDisplayName();
  477. return;
  478. }
  479. else if( name == "DISPLAY" )
  480. {
  481. *static_cast<Display**>(pData) = mGLSupport->getGLDisplay();
  482. return;
  483. }
  484. else if( name == "GLCONTEXT" )
  485. {
  486. *static_cast<GLXContext**>(pData) = mContext;
  487. return;
  488. }
  489. else if( name == "XDISPLAY" )
  490. {
  491. *static_cast<Display**>(pData) = mGLSupport->getXDisplay();
  492. return;
  493. }
  494. else if( name == "ATOM" )
  495. {
  496. *static_cast< ::Atom* >(pData) = mGLSupport->mAtomDeleteWindow;
  497. return;
  498. }
  499. else if( name == "WINDOW" )
  500. {
  501. *static_cast<Window*>(pData) = mWindow;
  502. return;
  503. }
  504. }
  505. //-------------------------------------------------------------------------------------------------//
  506. void GLXWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer)
  507. {
  508. if (mClosed)
  509. return;
  510. if ((dst.left < 0) || (dst.right > mWidth) ||
  511. (dst.top < 0) || (dst.bottom > mHeight) ||
  512. (dst.front != 0) || (dst.back != 1))
  513. {
  514. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "GLXWindow::copyContentsToMemory" );
  515. }
  516. if (buffer == FB_AUTO)
  517. {
  518. buffer = mIsFullScreen? FB_FRONT : FB_BACK;
  519. }
  520. GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format);
  521. GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format);
  522. if ((format == GL_NONE) || (type == 0))
  523. {
  524. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Unsupported format.", "GLXWindow::copyContentsToMemory" );
  525. }
  526. glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK);
  527. glReadPixels((GLint)dst.left, (GLint)dst.top,
  528. (GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(),
  529. format, type, dst.data);
  530. //vertical flip
  531. {
  532. size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format);
  533. size_t height = dst.getHeight();
  534. uchar *tmpData = new uchar[rowSpan * height];
  535. uchar *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan;
  536. while (tmpRow >= tmpData)
  537. {
  538. memcpy(tmpRow, srcRow, rowSpan);
  539. srcRow += rowSpan;
  540. tmpRow -= rowSpan;
  541. }
  542. memcpy(dst.data, tmpData, rowSpan * height);
  543. delete [] tmpData;
  544. }
  545. }
  546. //-------------------------------------------------------------------------------------------------//
  547. void GLXWindow::switchFullScreen(bool fullscreen)
  548. {
  549. if (&mGLSupport->mAtomFullScreen != None)
  550. {
  551. Display* xDisplay = mGLSupport->getXDisplay();
  552. XClientMessageEvent xMessage;
  553. xMessage.type = ClientMessage;
  554. xMessage.serial = 0;
  555. xMessage.send_event = True;
  556. xMessage.window = mWindow;
  557. xMessage.message_type = mGLSupport->mAtomState;
  558. xMessage.format = 32;
  559. xMessage.data.l[0] = (fullscreen ? 1 : 0);
  560. xMessage.data.l[1] = mGLSupport->mAtomFullScreen;
  561. xMessage.data.l[2] = 0;
  562. XSendEvent(xDisplay, DefaultRootWindow(xDisplay), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*)&xMessage);
  563. mIsFullScreen = fullscreen;
  564. }
  565. }
  566. }