LCOV - code coverage report
Current view: top level - eq/client - view.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 27 66 40.9 %
Date: 2014-06-18 Functions: 11 14 78.6 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2008-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *               2011-2012, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "view.h"
      20             : 
      21             : #include "config.h"
      22             : #include "event.h"
      23             : #include "pipe.h"
      24             : #include "layout.h"
      25             : #include "observer.h"
      26             : #include "server.h"
      27             : 
      28             : #include <eq/fabric/commands.h>
      29             : 
      30             : #include <co/dataIStream.h>
      31             : #include <co/dataOStream.h>
      32             : #include <lunchbox/scopedMutex.h>
      33             : #include <lunchbox/spinLock.h>
      34             : 
      35             : namespace eq
      36             : {
      37             : namespace detail
      38             : {
      39         128 : class View
      40             : {
      41             : public:
      42             :     lunchbox::SpinLock eventLock; //!< event-handling resize synchronizer
      43             : 
      44             :     /** Unmodified, baseline view frustum data, used for resizing. */
      45             :     Frustum baseFrustum;
      46             : };
      47             : }
      48             : 
      49             : typedef fabric::View< Layout, View, Observer > Super;
      50             : 
      51          64 : View::View( Layout* parent )
      52             :         : Super( parent )
      53          64 :         , _impl( new detail::View )
      54         128 :         , _pipe( 0 )
      55             : {
      56          64 : }
      57             : 
      58         184 : View::~View()
      59             : {
      60          64 :     delete _impl;
      61         120 : }
      62             : 
      63         141 : void View::deserialize( co::DataIStream& is, const uint64_t dirtyBits )
      64             : {
      65         141 :     Super::deserialize( is, dirtyBits );
      66         206 :     if( _impl->baseFrustum.getCurrentType() == TYPE_NONE &&
      67          65 :         ( dirtyBits & DIRTY_FRUSTUM ))
      68             :     {
      69          64 :         _impl->baseFrustum = *this; // save baseline data for resizing
      70             :     }
      71         141 : }
      72             : 
      73          64 : void View::detach()
      74             : {
      75             :     // if pipe is not running, detach comes from _flushViews in state stopping
      76             :     //  Don't send command to stopping pipe (see issue #11)
      77          64 :     if( _pipe && _pipe->isRunning( ))
      78             :     {
      79             :         // local command dispatching
      80             :         co::ObjectOCommand( _pipe, getLocalNode(), fabric::CMD_PIPE_DETACH_VIEW,
      81           0 :                             co::COMMANDTYPE_OBJECT, _pipe->getID(),
      82           0 :                             CO_INSTANCE_ALL ) << getID();
      83             :     }
      84          64 :     Super::detach();
      85          64 : }
      86             : 
      87          14 : Config* View::getConfig()
      88             : {
      89          14 :     Layout* layout = getLayout();
      90          14 :     if( layout )
      91          14 :         return layout->getConfig();
      92             : 
      93           0 :     if( _pipe )
      94           0 :         return _pipe->getConfig();
      95             : 
      96           0 :     LBUNREACHABLE;
      97           0 :     return 0;
      98             : }
      99             : 
     100           7 : const Config* View::getConfig() const
     101             : {
     102           7 :     const Layout* layout = getLayout();
     103           7 :     if( layout )
     104           7 :         return layout->getConfig();
     105             : 
     106           0 :     if( _pipe )
     107           0 :         return _pipe->getConfig();
     108             : 
     109           0 :     LBUNREACHABLE;
     110           0 :     return 0;
     111             : }
     112             : 
     113           0 : ServerPtr View::getServer()
     114             : {
     115           0 :     Config* config = getConfig();
     116           0 :     LBASSERT( config );
     117           0 :     return ( config ? config->getServer() : 0 );
     118             : }
     119             : 
     120           0 : const Frustum& View::getBaseFrustum() const
     121             : {
     122           0 :     return _impl->baseFrustum;
     123             : }
     124             : 
     125           0 : bool View::handleEvent( const Event& event )
     126             : {
     127           0 :     switch( event.type )
     128             :     {
     129             :     case Event::VIEW_RESIZE:
     130             :     {
     131           0 :         const ResizeEvent& resize = event.resize;
     132           0 :         if( resize.dw == 0.f || resize.dh == 0.f )
     133           0 :             return true;
     134             : 
     135           0 :         switch( getCurrentType( ))
     136             :         {
     137             :         case TYPE_WALL:
     138             :         {
     139           0 :             const float ratio( resize.dw / resize.dh );
     140           0 :             Wall wall( _impl->baseFrustum.getWall( ));
     141           0 :             wall.resizeHorizontal( ratio );
     142             : 
     143           0 :             lunchbox::ScopedFastWrite mutex( _impl->eventLock );
     144           0 :             setWall( wall );
     145           0 :             break;
     146             :         }
     147             : 
     148             :         case View::TYPE_PROJECTION:
     149             :         {
     150           0 :             const float ratio( resize.dw / resize.dh );
     151           0 :             eq::Projection projection( _impl->baseFrustum.getProjection( ));
     152           0 :             projection.resizeHorizontal( ratio );
     153             : 
     154           0 :             lunchbox::ScopedFastWrite mutex( _impl->eventLock );
     155           0 :             setProjection( projection );
     156           0 :             break;
     157             :         }
     158             : 
     159             :         case eq::View::TYPE_NONE:
     160           0 :             break;
     161             :         default:
     162           0 :             LBUNIMPLEMENTED;
     163           0 :             break;
     164             :         }
     165           0 :         return true;
     166             :     }
     167             :     }
     168             : 
     169           0 :     return false;
     170             : }
     171             : 
     172             : }
     173             : 
     174             : #include "../fabric/view.ipp"
     175             : template class eq::fabric::View< eq::Layout, eq::View, eq::Observer >;
     176             : 
     177             : /** @cond IGNORE */
     178             : template EQFABRIC_API std::ostream& eq::fabric::operator << ( std::ostream&,
     179          36 :                                                              const eq::Super& );
     180             : /** @endcond */

Generated by: LCOV version 1.10