LCOV - code coverage report
Current view: top level - eq/server/equalizers - tileEqualizer.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 13 88 14.8 %
Date: 2016-09-29 05:02:09 Functions: 4 18 22.2 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2011-2015, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *               2011, Carsten Rohn <carsten.rohn@rtt.ag>
       4             :  *               2011, Daniel Nachbaur <danielnachbaur@gmail.com>
       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 "tileEqualizer.h"
      21             : 
      22             : #include "../compound.h"
      23             : #include "../compoundVisitor.h"
      24             : #include "../config.h"
      25             : #include "../server.h"
      26             : #include "../tileQueue.h"
      27             : #include "../view.h"
      28             : 
      29             : namespace eq
      30             : {
      31             : namespace server
      32             : {
      33             : namespace
      34             : {
      35             : 
      36           0 : TileQueue* _findQueue( const std::string& name, const TileQueues& queues )
      37             : {
      38           0 :     for( TileQueuesCIter i = queues.begin(); i != queues.end(); ++i )
      39             :     {
      40           0 :         if ((*i)->getName() == name)
      41           0 :             return *i;
      42             :     }
      43           0 :     return 0;
      44             : }
      45             : 
      46           0 : class InputQueueCreator : public CompoundVisitor
      47             : {
      48             : public:
      49           0 :     InputQueueCreator( const eq::fabric::Vector2i& size,
      50             :                        const std::string& name )
      51             :         : CompoundVisitor()
      52             :         , _tileSize( size )
      53           0 :         , _name( name )
      54           0 :     {}
      55             : 
      56             :     /** Visit a leaf compound. */
      57           0 :     virtual VisitorResult visitLeaf( Compound* compound )
      58             :     {
      59           0 :         if( _findQueue( _name, compound->getInputTileQueues( )))
      60           0 :             return TRAVERSE_CONTINUE;
      61             : 
      62             :         // reset compound viewport to (0, 0, 1, 1) (#108)
      63           0 :         if( !compound->getViewport().hasArea() )
      64           0 :             compound->setViewport( Viewport( ));
      65             : 
      66           0 :         TileQueue* input = new TileQueue;
      67           0 :         ServerPtr server = compound->getServer();
      68           0 :         server->registerObject( input );
      69           0 :         input->setTileSize( _tileSize );
      70           0 :         input->setName( _name );
      71           0 :         input->setAutoObsolete( compound->getConfig()->getLatency( ));
      72             : 
      73           0 :         compound->addInputTileQueue( input );
      74           0 :         return TRAVERSE_CONTINUE;
      75             :     }
      76             : 
      77             : private:
      78             :     const eq::fabric::Vector2i& _tileSize;
      79             :     const std::string& _name;
      80             : };
      81             : 
      82           0 : class InputQueueDestroyer : public CompoundVisitor
      83             : {
      84             : public:
      85           0 :     explicit InputQueueDestroyer( const std::string& name )
      86             :         : CompoundVisitor()
      87           0 :         , _name( name )
      88             :     {
      89           0 :     }
      90             : 
      91             :     /** Visit a leaf compound. */
      92           0 :     virtual VisitorResult visitLeaf( Compound* compound )
      93             :     {
      94           0 :         TileQueue* q = _findQueue( _name, compound->getInputTileQueues( ));
      95           0 :         if( q )
      96             :         {
      97           0 :             compound->removeInputTileQueue( q );
      98           0 :             ServerPtr server = compound->getServer();
      99           0 :             q->flush();
     100           0 :             server->deregisterObject( q );
     101           0 :             delete q;
     102             :         }
     103             : 
     104           0 :         return TRAVERSE_CONTINUE;
     105             :     }
     106             : private:
     107             :     const std::string& _name;
     108             : };
     109             : 
     110             : }
     111             : 
     112           8 : TileEqualizer::TileEqualizer()
     113             :     : Equalizer()
     114             :     , _created( false )
     115           8 :     , _name( "TileEqualizer" )
     116             : {
     117           8 : }
     118             : 
     119           0 : TileEqualizer::TileEqualizer( const TileEqualizer& from )
     120             :     : Equalizer( from )
     121             :     , _created( from._created )
     122           0 :     , _name( from._name )
     123             : {
     124           0 : }
     125             : 
     126           0 : std::string TileEqualizer::_getQueueName() const
     127             : {
     128           0 :     std::ostringstream name;
     129           0 :     name << "queue." << _name << (void*)this;
     130           0 :     return name.str();
     131             : }
     132             : 
     133           0 : void TileEqualizer::_createQueues( Compound* compound )
     134             : {
     135           0 :     _created = true;
     136           0 :     const std::string& name = _getQueueName();
     137           0 :     if( !_findQueue( name, compound->getOutputTileQueues( )))
     138             :     {
     139           0 :         TileQueue* output = new TileQueue;
     140           0 :         ServerPtr server = compound->getServer();
     141           0 :         server->registerObject( output );
     142           0 :         output->setTileSize( getTileSize( ));
     143           0 :         output->setName( name );
     144           0 :         output->setAutoObsolete( compound->getConfig()->getLatency( ));
     145             : 
     146           0 :         compound->addOutputTileQueue( output );
     147             :     }
     148             : 
     149           0 :     InputQueueCreator creator( getTileSize(), name );
     150           0 :     compound->accept( creator );
     151           0 : }
     152             : 
     153           0 : void TileEqualizer::_destroyQueues( Compound* compound )
     154             : {
     155           0 :     const std::string& name = _getQueueName();
     156           0 :     TileQueue* q = _findQueue( name, compound->getOutputTileQueues() );
     157           0 :     if ( q )
     158             :     {
     159           0 :         compound->removeOutputTileQueue( q );
     160           0 :         ServerPtr server = compound->getServer();
     161           0 :         q->flush();
     162           0 :         server->deregisterObject( q );
     163           0 :         delete q;
     164             :     }
     165             : 
     166           0 :     InputQueueDestroyer destroyer( name );
     167           0 :     compound->accept( destroyer );
     168           0 :     _created = false;
     169           0 : }
     170             : 
     171           0 : void TileEqualizer::notifyUpdatePre( Compound* compound,
     172             :                                      const uint32_t /*frame*/ )
     173             : {
     174           0 :     if( isActive() && !_created )
     175           0 :         _createQueues( compound );
     176             : 
     177           0 :     if( !isActive() && _created )
     178           0 :         _destroyQueues( compound );
     179           0 : }
     180             : 
     181           4 : std::ostream& operator << ( std::ostream& os, const TileEqualizer* lb )
     182             : {
     183           4 :     if( lb )
     184             :     {
     185           4 :         os << lunchbox::disableFlush
     186           4 :            << "tile_equalizer" << std::endl
     187           4 :            << "{" << std::endl
     188           8 :            << "    name \"" << lb->getName() << "\"" << std::endl
     189           8 :            << "    size " << lb->getTileSize() << std::endl
     190           4 :            << "}" << std::endl << lunchbox::enableFlush;
     191             :     }
     192           4 :     return os;
     193             : }
     194             : 
     195             : 
     196             : } //server
     197          84 : } //eq

Generated by: LCOV version 1.11