LCOV - code coverage report
Current view: top level - eq/qt - window.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 1 75 1.3 %
Date: 2017-12-16 05:07:20 Functions: 2 19 10.5 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2014-2016, Daniel Nachbaur <danielnachbaur@gmail.com>
       3             :  *                          Juan Hernando <jhernando@fi.upm.es>
       4             :  *                          Stefan.Eilemann@epfl.ch
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #include "window.h"
      21             : #include "detail/window.h"
      22             : 
      23             : #include "shareContextWindow.h"
      24             : #include <eq/fabric/sizeEvent.h>
      25             : 
      26             : namespace eq
      27             : {
      28             : namespace qt
      29             : {
      30             : namespace
      31             : {
      32           0 : QOpenGLContext* _getShareContext(const WindowSettings& settings)
      33             : {
      34           0 :     const SystemWindow* shareWindow = settings.getSharedContextWindow();
      35           0 :     const Window* window = dynamic_cast<const Window*>(shareWindow);
      36           0 :     if (window)
      37             :         // This only works if configInit has already been called in the window
      38           0 :         return window->getContext();
      39             : 
      40             :     const ShareContextWindow* dummyWindow =
      41           0 :         dynamic_cast<const ShareContextWindow*>(shareWindow);
      42           0 :     return dummyWindow ? dummyWindow->getContext() : 0;
      43             : }
      44             : 
      45           0 : detail::Window* _createImpl(WindowIF& windowIF, const WindowSettings& settings,
      46             :                             QScreen* screen, QThread* thread)
      47             : {
      48           0 :     QOpenGLContext* shareContext = _getShareContext(settings);
      49             :     const int32_t drawable =
      50           0 :         windowIF.getIAttribute(WindowSettings::IATTR_HINT_DRAWABLE);
      51           0 :     detail::Window* window = nullptr;
      52           0 :     if (drawable == eq::WINDOW)
      53           0 :         window = new detail::QWindowWrapper(windowIF, thread, settings, screen,
      54           0 :                                             shareContext);
      55             :     else
      56           0 :         window =
      57             :             new detail::QOffscreenSurfaceWrapper(windowIF, thread, settings,
      58           0 :                                                  screen, shareContext);
      59           0 :     LBASSERT(window);
      60           0 :     if (thread)
      61           0 :         window->getContext()->moveToThread(thread);
      62           0 :     return window;
      63             : }
      64             : }
      65             : 
      66           0 : Window::Window(NotifierInterface& parent_, const WindowSettings& settings,
      67           0 :                QScreen* screen, QThread* thr)
      68             :     : WindowIF(parent_, settings)
      69           0 :     , _impl(_createImpl(*this, settings, screen, thr))
      70             : {
      71           0 :     LBASSERT(_impl);
      72           0 : }
      73             : 
      74           0 : Window::~Window()
      75             : {
      76           0 :     destroyImpl(_impl);
      77           0 : }
      78             : 
      79           0 : bool Window::configInit()
      80             : {
      81           0 :     if (!_impl->configInit())
      82           0 :         return false;
      83             : 
      84           0 :     makeCurrent();
      85           0 :     initGLEW();
      86             : 
      87           0 :     const int32_t drawable = getIAttribute(WindowSettings::IATTR_HINT_DRAWABLE);
      88           0 :     if (drawable == FBO)
      89           0 :         return configInitFBO();
      90           0 :     return true;
      91             : }
      92             : 
      93           0 : void Window::configExit()
      94             : {
      95           0 :     configExitFBO();
      96           0 :     makeCurrent();
      97           0 :     exitGLEW();
      98           0 :     _impl->doneCurrent();
      99           0 : }
     100             : 
     101           0 : QOpenGLContext* Window::getContext() const
     102             : {
     103           0 :     return _impl->getContext();
     104             : }
     105             : 
     106           0 : void Window::makeCurrent(const bool cache LB_UNUSED) const
     107             : {
     108             : // Qt (at least on Windows) complains about call to non-current context
     109             : // while swapBuffers()
     110             : #ifndef _MSC_VER
     111           0 :     if (cache && isCurrent())
     112           0 :         return;
     113             : #endif
     114             : 
     115           0 :     _impl->makeCurrent();    // Make real GL context current first
     116           0 :     WindowIF::makeCurrent(); // Validate FBO binding and caching state
     117             : }
     118             : 
     119           0 : void Window::doneCurrent() const
     120             : {
     121           0 :     if (!isCurrent())
     122           0 :         return;
     123             : 
     124           0 :     _impl->doneCurrent();
     125           0 :     WindowIF::doneCurrent();
     126             : }
     127             : 
     128           0 : void Window::_resize(const PixelViewport& pvp)
     129             : {
     130           0 :     _impl->resize(pvp);
     131           0 : }
     132             : 
     133           0 : void Window::swapBuffers()
     134             : {
     135           0 :     _impl->swapBuffers();
     136           0 : }
     137             : 
     138           0 : void Window::joinNVSwapBarrier(const uint32_t /*group*/,
     139             :                                const uint32_t /*barrier*/)
     140             : {
     141           0 : }
     142             : 
     143           0 : void Window::leaveNVSwapBarrier()
     144             : {
     145           0 : }
     146             : 
     147           0 : bool Window::processEvent(const EventType type, QEvent* qEvent,
     148             :                           SizeEvent& sizeEvent)
     149             : {
     150             :     // Resize the FBO if needed
     151           0 :     if (type == EVENT_WINDOW_RESIZE && getFrameBufferObject())
     152           0 :         getFrameBufferObject()->resize(sizeEvent.w, sizeEvent.h);
     153             : 
     154           0 :     return WindowIF::processEvent(type, qEvent, sizeEvent);
     155             : }
     156             : 
     157           0 : QObject* Window::getEventProcessor()
     158             : {
     159           0 :     return _impl->getEventProcessor();
     160             : }
     161             : 
     162           0 : void Window::moveContextToThread(QThread* thread_)
     163             : {
     164           0 :     _impl->getContext()->moveToThread(thread_);
     165           0 : }
     166             : }
     167          30 : }

Generated by: LCOV version 1.11