LCOV - code coverage report
Current view: top level - eq/server - segment.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 52 72 72.2 %
Date: 2014-06-18 Functions: 11 13 84.6 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "segment.h"
      19             : 
      20             : #include "canvas.h"
      21             : #include "channel.h"
      22             : #include "compound.h"
      23             : #include "config.h"
      24             : #include "configDestCompoundVisitor.h"
      25             : #include "pipe.h"
      26             : #include "view.h"
      27             : #include "window.h"
      28             : 
      29             : #include <eq/fabric/paths.h>
      30             : #include <co/dataOStream.h>
      31             : 
      32             : #include <boost/foreach.hpp>
      33             : 
      34             : namespace eq
      35             : {
      36             : namespace server
      37             : {
      38             : 
      39             : typedef fabric::Segment< Canvas, Segment, Channel > Super;
      40             : 
      41         375 : Segment::Segment( Canvas* parent )
      42         375 :         : Super( parent )
      43             : {
      44         375 : }
      45             : 
      46        1122 : Segment::~Segment()
      47             : {
      48             :     ConfigDestCompoundVisitor visitor( _destinationChannels,
      49         374 :                                        false /*activeOnly*/ );
      50         374 :     getConfig()->accept( visitor );
      51         374 :     const Compounds& compounds = visitor.getResult();
      52             : 
      53        1122 :     for( Compounds::const_iterator i = compounds.begin();
      54         748 :          i != compounds.end(); ++i )
      55             :     {
      56           0 :         Compound* compound = *i;
      57           0 :         while( compound )
      58             :         {
      59           0 :             Compound* parent = compound->getParent();
      60           0 :             delete compound;
      61           0 :             if( parent && parent->isLeaf( )) // empty parent now
      62           0 :                 compound = parent;
      63             :             else
      64           0 :                 compound = 0;
      65             :         }
      66             :     }
      67             : 
      68             :     // Use copy - Channel::unsetOutput modifies vector
      69         748 :     Channels destinationChannels = _destinationChannels;
      70        3027 :     for( Channels::const_iterator i = destinationChannels.begin();
      71        2018 :          i != destinationChannels.end(); ++i )
      72             :     {
      73         635 :         Channel* channel = *i;
      74         635 :         LBASSERT( channel );
      75         635 :         channel->unsetOutput();
      76             :     }
      77             : 
      78         374 :     LBASSERT( _destinationChannels.empty( ));
      79         748 :     _destinationChannels.clear();
      80         748 : }
      81             : 
      82           0 : void Segment::updateFrustum()
      83             : {
      84           0 :     BOOST_FOREACH( Channel* channel, _destinationChannels )
      85             :     {
      86           0 :         View* view = channel->getView();
      87           0 :         view->updateFrusta();
      88             :     }
      89           0 : }
      90             : 
      91         384 : Config* Segment::getConfig()
      92             : {
      93         384 :     Canvas* canvas = getCanvas();
      94         384 :     LBASSERT( canvas );
      95         384 :     return canvas ? canvas->getConfig() : 0;
      96             : }
      97             : 
      98             : 
      99         200 : const Config* Segment::getConfig() const
     100             : {
     101         200 :     const Canvas* canvas = getCanvas();
     102         200 :     LBASSERT( canvas );
     103         200 :     return canvas ? canvas->getConfig() : 0;
     104             : }
     105             : 
     106          10 : ServerPtr Segment::getServer()
     107             : {
     108          10 :     Canvas* canvas = getCanvas();
     109          10 :     LBASSERT( canvas );
     110          10 :     return ( canvas ? canvas->getServer() : 0 );
     111             : }
     112             : 
     113         636 : void Segment::addDestinationChannel( Channel* channel )
     114             : {
     115         636 :     LBASSERT( channel );
     116         636 :     LBASSERT( std::find( _destinationChannels.begin(),
     117             :                          _destinationChannels.end(), channel ) ==
     118             :               _destinationChannels.end( ));
     119             : 
     120         636 :     _destinationChannels.push_back( channel );
     121         636 : }
     122             : 
     123         635 : bool Segment::removeDestinationChannel( Channel* channel )
     124             : {
     125         635 :     Channels::iterator i = lunchbox::find( _destinationChannels, channel );
     126             : 
     127         635 :     LBASSERT( i !=  _destinationChannels.end( ));
     128         635 :     if( i == _destinationChannels.end( ))
     129           0 :         return false;
     130             : 
     131         635 :     _destinationChannels.erase( i );
     132             : 
     133         635 :     LBASSERT( lunchbox::find( _destinationChannels, channel ) ==
     134             :               _destinationChannels.end( ));
     135         635 :     return true;
     136             : }
     137             : 
     138           0 : void Segment::findDestinationChannels( const Layout* layout,
     139             :                                        Channels& result ) const
     140             : {
     141           0 :     for( Channels::const_iterator i = _destinationChannels.begin();
     142           0 :          i != _destinationChannels.end(); ++i )
     143             :     {
     144           0 :         Channel* channel = *i;
     145           0 :         if( channel->getLayout() == layout )
     146           0 :             result.push_back( channel );
     147             :     }
     148           0 : }
     149             : 
     150         413 : SegmentPath Segment::getPath() const
     151             : {
     152         413 :     const Canvas* canvas = getCanvas();
     153         413 :     LBASSERT( canvas );
     154         413 :     SegmentPath path( canvas->getPath( ));
     155             : 
     156         413 :     const Segments& segments = canvas->getSegments();
     157             :     Segments::const_iterator i = std::find( segments.begin(), segments.end(),
     158         413 :                                             this );
     159         413 :     LBASSERT( i != segments.end( ));
     160         413 :     path.segmentIndex = std::distance( segments.begin(), i );
     161         413 :     return path;
     162             : }
     163             : 
     164             : }
     165             : }
     166             : 
     167             : #include "../fabric/segment.ipp"
     168             : template class eq::fabric::Segment< eq::server::Canvas, eq::server::Segment,
     169             :                                     eq::server::Channel >;
     170             : /** @cond IGNORE */
     171             : template std::ostream& eq::fabric::operator << ( std::ostream&,
     172          27 :                                                  const eq::server::Super& );
     173             : /** @endcond */

Generated by: LCOV version 1.10