dfrEqualizer.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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
00094
00095
00096
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
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 }