server/frame.cpp

00001 
00002 /* Copyright (c) 2006-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "frame.h"
00019 
00020 #include "compound.h"
00021 #include "frameData.h"
00022 
00023 #include <eq/net/dataIStream.h>
00024 #include <eq/net/dataOStream.h>
00025 #include <eq/net/session.h>
00026 
00027 using namespace eq::base;
00028 using namespace std;
00029 
00030 namespace eq
00031 {
00032 namespace server
00033 {
00034 
00035 Frame::Frame()
00036         : _compound( 0 )
00037         , _buffers( eq::Frame::BUFFER_UNDEFINED )
00038         , _type( eq::Frame::TYPE_MEMORY )
00039         , _masterFrameData( 0 )
00040 {
00041     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00042         _frameData[i] = 0;
00043 }
00044 
00045 Frame::Frame( const Frame& from )
00046         : net::Object()
00047         , _compound( 0 )
00048         , _name( from._name )
00049         , _data( from._data )
00050         , _vp( from._vp )
00051         , _buffers( from._buffers )
00052         , _type( from._type )
00053         , _masterFrameData( 0 )
00054 {
00055     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00056         _frameData[i] = 0;
00057 }
00058 
00059 Frame::~Frame()
00060 {
00061     EQASSERT( _datas.empty());
00062 }
00063 
00064 void Frame::getInstanceData( net::DataOStream& os )
00065 {
00066     os << _inherit;
00067 }
00068 
00069 void Frame::applyInstanceData( net::DataIStream& is )
00070 {
00071     EQUNREACHABLE;
00072     is >> _inherit;
00073 }
00074 
00075 void Frame::flush()
00076 {
00077     unsetData();
00078 
00079     net::Session* session = getSession();
00080     EQASSERT( session );
00081     while( !_datas.empty( ))
00082     {
00083         FrameData* data = _datas.front();
00084         session->deregisterObject( data );
00085         _datas.pop_front();
00086     }
00087 
00088 }
00089 
00090 void Frame::unsetData()
00091 {
00092     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00093     {
00094         _frameData[i] = 0;
00095         _inputFrames[i].clear();
00096     }
00097 }
00098 
00099 void Frame::commitData()
00100 {
00101     if( !_masterFrameData ) // not used
00102         return;
00103 
00104     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00105     {
00106         if( _frameData[i] )
00107         {
00108             if( _frameData[i] != _masterFrameData )
00109                 _frameData[i]->_data = _masterFrameData->_data;
00110 
00111             _frameData[i]->commit();
00112         }
00113     }
00114 }
00115 
00116 uint32_t Frame::commit()
00117 {
00118     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00119     {
00120         if( _frameData[i] )
00121         {
00122             _inherit.frameData[i].id      = _frameData[i]->getID();
00123             _inherit.frameData[i].version = _frameData[i]->getVersion();
00124         }
00125         else
00126             _inherit.frameData[i].id = EQ_ID_INVALID;
00127     }
00128 
00129     return net::Object::commit();
00130 }
00131 
00132 void Frame::cycleData( const uint32_t frameNumber, const uint32_t eyes )
00133 {
00134     _masterFrameData = 0;
00135     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00136     {
00137         _inputFrames[i].clear();
00138 
00139         if( !(eyes & (1<<i))) // eye pass not used
00140         {
00141             _frameData[i] = 0;
00142             continue;
00143         }
00144 
00145         // reuse unused frame data
00146         FrameData*     data    = _datas.empty() ? 0 : _datas.back();
00147         const uint32_t latency = getAutoObsoleteCount();
00148         const uint32_t dataAge = data ? data->getFrameNumber() : 0;
00149 
00150         if( data && dataAge < frameNumber-latency && frameNumber > latency )
00151             // not used anymore
00152             _datas.pop_back();
00153         else // still used - allocate new data
00154         {
00155             data = new FrameData;
00156         
00157             net::Session* session = getSession();
00158             EQASSERT( session );
00159 
00160             session->registerObject( data );
00161             data->setAutoObsolete( 1 ); // current + in use by render nodes
00162         }
00163 
00164         data->setFrameNumber( frameNumber );
00165     
00166         _datas.push_front( data );
00167         _frameData[i] = data;
00168         if( !_masterFrameData )
00169             _masterFrameData = data;
00170     }
00171 }
00172 
00173 void Frame::addInputFrame( Frame* frame, const uint32_t eyes )
00174 {
00175     for( unsigned i = 0; i<eq::EYE_ALL; ++i )
00176     {
00177         if( !(eyes & (1<<i)) ||  // eye pass not used
00178             !_frameData[i] )     // no output frame for eye pass
00179         {
00180             frame->_frameData[i] = 0;
00181         }
00182         else
00183         {
00184             frame->_frameData[i] = _frameData[i];
00185             _inputFrames[i].push_back( frame );
00186         }
00187     }
00188 }
00189 
00190 std::ostream& operator << ( std::ostream& os, const Frame* frame )
00191 {
00192     if( !frame )
00193         return os;
00194     
00195     os << disableFlush << "Frame" << endl;
00196     os << "{" << endl << indent;
00197       
00198     const std::string& name = frame->getName();
00199     os << "name     \"" << name << "\"" << endl;
00200 
00201     const uint32_t buffers = frame->getBuffers();
00202     if( buffers != eq::Frame::BUFFER_UNDEFINED )
00203     {
00204         os << "buffers  [";
00205         if( buffers & eq::Frame::BUFFER_COLOR )  os << " COLOR";
00206         if( buffers & eq::Frame::BUFFER_DEPTH )  os << " DEPTH";
00207         os << " ]" << endl;
00208     }
00209 
00210     const eq::Frame::Type frameType = frame->getType();
00211     if( frameType != eq::Frame::TYPE_MEMORY )
00212         os  << frameType;
00213     
00214     const eq::Viewport& vp = frame->getViewport();
00215     if( vp != eq::Viewport::FULL )
00216         os << "viewport " << vp << endl;
00217 
00218     const eq::Zoom& zoom = frame->getZoom();
00219     if( zoom.isValid() && zoom != eq::Zoom::NONE )
00220         os << zoom << endl;
00221 
00222     os << exdent << "}" << endl << enableFlush;
00223     return os;
00224 }
00225 
00226 }
00227 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8