LCOV - code coverage report
Current view: top level - eq/server/equalizers - tileEqualizer.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 13 88 14.8 %
Date: 2014-06-18 Functions: 4 18 22.2 %

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

Generated by: LCOV version 1.10