dfrEqualizer.cpp

00001 
00002 /* Copyright (c) 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 "dfrEqualizer.h"
00019 
00020 #include "../compound.h"
00021 #include "../compoundVisitor.h"
00022 #include "../config.h"
00023 #include "../log.h"
00024 
00025 #include <eq/base/debug.h>
00026 #include <eq/client/zoom.h>
00027 
00028 namespace eq
00029 {
00030 namespace server
00031 {
00032 
00033 DFREqualizer::DFREqualizer()
00034         : _target( 10.f )
00035         , _damping( .5f )
00036         , _current ( _target )
00037         , _lastTime( 0 )
00038 {    
00039     EQINFO << "New DFREqualizer @" << (void*)this << std::endl;
00040 }
00041 
00042 DFREqualizer::~DFREqualizer()
00043 {
00044     attach( 0 );
00045     EQINFO << "Delete DFREqualizer @" << (void*)this << std::endl;
00046 }
00047 
00048 void DFREqualizer::attach( Compound* compound )
00049 {
00050     Compound* oldCompound = getCompound();
00051     if( oldCompound )
00052     {
00053         Channel*  channel   = oldCompound->getChannel();
00054         EQASSERT( channel );
00055 
00056         // Unsubscribe to channel load notification
00057         channel->removeListener( this );
00058     }
00059 
00060     Equalizer::attach( compound );
00061     
00062     if( compound )
00063     {
00064         Channel* channel = compound->getChannel();
00065         EQASSERT( channel );
00066     
00067         // Subscribe to channel load notification
00068         if ( compound->getParent() && channel )
00069             channel->addListener( this );
00070     }
00071 }
00072 
00073 void DFREqualizer::notifyUpdatePre( Compound* compound, 
00074                                     const uint32_t frameNumber )
00075 {
00076     EQASSERT( compound == getCompound( ));
00077 
00078     if( isFrozen( ))
00079     {
00080         compound->setZoom( Zoom::NONE );  
00081         return;    
00082     }
00083    
00084     EQASSERT( _damping >= 0.f );
00085     EQASSERT( _damping <= 1.f );
00086 
00087     const float factor = ( sqrtf( _current / _target ) - 1.f ) * 
00088         _damping + 1.0f;
00089 
00090     Zoom newZoom( compound->getZoom( ));
00091     newZoom *= factor;
00092 
00093     //EQINFO << _current << ": " << factor << " = " << newZoom 
00094     //       << std::endl;
00095 
00096     // clip zoom factor to min( 128px ), max( channel pvp )
00097 
00098     const Compound*          parent = compound->getParent();
00099     const eq::PixelViewport& pvp    = parent->getInheritPixelViewport();
00100    
00101     const Channel*           channel    = compound->getChannel();
00102     const eq::PixelViewport& channelPVP = channel->getPixelViewport();
00103    
00104     const float minZoom = 128.f / EQ_MIN( static_cast< float >( pvp.h ),
00105                                           static_cast< float >( pvp.w ));
00106     const float maxZoom = EQ_MIN( static_cast< float >( channelPVP.w ) /
00107                                   static_cast< float >( pvp.w ),
00108                                   static_cast< float >( channelPVP.h ) /
00109                                   static_cast< float >( pvp.h ));
00110    
00111    newZoom.x() = EQ_MAX( newZoom.x(), minZoom ); 
00112    newZoom.x() = EQ_MIN( newZoom.x(), maxZoom );
00113    newZoom.y() = newZoom.x(); 
00114    
00115     compound->setZoom( newZoom );
00116 }
00117 
00118 void DFREqualizer::notifyLoadData( Channel* channel, const uint32_t frameNumber,
00119                                    const uint32_t nStatistics,
00120                                    const eq::Statistic* statistics  )
00121 {
00122     // gather and notify load data
00123     int64_t endTime = 0;
00124     for( uint32_t i = 0; i < nStatistics; ++i )
00125     {
00126         const eq::Statistic& data = statistics[i];
00127         switch( data.type )
00128         {
00129             case eq::Statistic::CHANNEL_CLEAR:
00130             case eq::Statistic::CHANNEL_DRAW:
00131             case eq::Statistic::CHANNEL_ASSEMBLE:
00132             case eq::Statistic::CHANNEL_READBACK:
00133                 endTime = EQ_MAX( endTime, data.endTime );
00134                 break;
00135                 
00136             default:
00137                 break;
00138         }
00139     }
00140     
00141     if( endTime == 0 )
00142         return;
00143     
00144     const int64_t time = endTime - _lastTime;
00145     _lastTime = endTime;
00146 
00147     if( _lastTime <= 0 || time <= 0 ) 
00148         return;
00149          
00150     _current = 1000.0f / static_cast< float >( time );
00151     EQLOG( LOG_LB1 ) << "Frame " << frameNumber << " channel "
00152                      << channel->getName() << " time " << time << std::endl;
00153 }
00154 
00155 std::ostream& operator << ( std::ostream& os, const DFREqualizer* lb )
00156 {
00157     if( !lb )
00158         return os;
00159 
00160     os << base::disableFlush
00161        << "DFR_equalizer " << std::endl
00162        << '{' << std::endl
00163        << "    framerate " << lb->getFrameRate() << std::endl;
00164 
00165     if( lb->getDamping() != 0.5f )
00166         os << "    damping " << lb->getDamping() << std::endl;
00167     
00168     os << '}' << std::endl << base::enableFlush;
00169     return os;
00170 }
00171 
00172 }
00173 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8