Line data Source code
1 :
2 : /* Copyright (c) 2008-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010-2014, Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #include "windowStatistics.h"
20 :
21 : #include "config.h"
22 : #include "global.h"
23 : #include "pipe.h"
24 : #include "window.h"
25 :
26 : #include <cstdio>
27 :
28 : #ifdef _MSC_VER
29 : # define snprintf _snprintf
30 : #endif
31 :
32 : namespace eq
33 : {
34 :
35 0 : WindowStatistics::WindowStatistics( const Statistic::Type type,
36 : Window* window )
37 0 : : StatisticSampler< Window >( type, window )
38 : {
39 0 : const int32_t hint = _owner->getIAttribute( WindowSettings::IATTR_HINT_STATISTICS );
40 0 : if( hint == OFF )
41 0 : return;
42 :
43 0 : const std::string& name = window->getName();
44 0 : if( name.empty( ))
45 : snprintf( event.data.statistic.resourceName, 32, "Window %s",
46 0 : window->getID().getShortString().c_str( ));
47 : else
48 0 : snprintf( event.data.statistic.resourceName, 32, "%s", name.c_str());
49 0 : event.data.statistic.resourceName[31] = 0;
50 :
51 0 : if( type != Statistic::WINDOW_FPS && hint == NICEST )
52 0 : window->finish();
53 :
54 0 : event.data.statistic.startTime = window->getConfig()->getTime();
55 : }
56 :
57 :
58 0 : WindowStatistics::~WindowStatistics()
59 : {
60 0 : const int32_t hint = _owner->getIAttribute( WindowSettings::IATTR_HINT_STATISTICS );
61 0 : if( hint == OFF )
62 0 : return;
63 :
64 0 : if( event.data.statistic.frameNumber == 0 ) // does not belong to a frame
65 0 : return;
66 :
67 0 : if( event.data.statistic.type != Statistic::WINDOW_FPS && hint == NICEST )
68 0 : _owner->finish();
69 :
70 0 : event.data.statistic.endTime = _owner->getConfig()->getTime();
71 0 : if( event.data.statistic.endTime <= event.data.statistic.startTime )
72 0 : event.data.statistic.endTime = event.data.statistic.startTime + 1;
73 0 : _owner->processEvent( event.data );
74 0 : }
75 :
76 42 : }
|