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

Generated by: LCOV version 1.11