1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui>
|
---|
43 | #include <QtDebug>
|
---|
44 |
|
---|
45 | #include <private/qpaintengineex_p.h>
|
---|
46 | #include <private/qpaintbuffer_p.h>
|
---|
47 |
|
---|
48 | class ReplayWidget : public QWidget
|
---|
49 | {
|
---|
50 | Q_OBJECT
|
---|
51 | public:
|
---|
52 | ReplayWidget(const QString &filename);
|
---|
53 |
|
---|
54 | void paintEvent(QPaintEvent *event);
|
---|
55 |
|
---|
56 | public slots:
|
---|
57 | void updateRect();
|
---|
58 |
|
---|
59 | public:
|
---|
60 | QList<QRegion> updates;
|
---|
61 | QPaintBuffer buffer;
|
---|
62 |
|
---|
63 | int currentFrame;
|
---|
64 | int currentIteration;
|
---|
65 | QTime timer;
|
---|
66 |
|
---|
67 | QList<uint> iterationTimes;
|
---|
68 | QString filename;
|
---|
69 | };
|
---|
70 |
|
---|
71 | void ReplayWidget::updateRect()
|
---|
72 | {
|
---|
73 | if (!updates.isEmpty())
|
---|
74 | update(updates.at(currentFrame));
|
---|
75 | }
|
---|
76 |
|
---|
77 | void ReplayWidget::paintEvent(QPaintEvent *)
|
---|
78 | {
|
---|
79 | QPainter p(this);
|
---|
80 |
|
---|
81 | // p.setClipRegion(frames.at(currentFrame).updateRegion);
|
---|
82 |
|
---|
83 | buffer.draw(&p, currentFrame);
|
---|
84 |
|
---|
85 | ++currentFrame;
|
---|
86 | if (currentFrame >= buffer.numFrames()) {
|
---|
87 | currentFrame = 0;
|
---|
88 | ++currentIteration;
|
---|
89 |
|
---|
90 | if (currentIteration == 3)
|
---|
91 | timer.start();
|
---|
92 | else if (currentIteration > 3) {
|
---|
93 | iterationTimes << timer.elapsed();
|
---|
94 | timer.restart();
|
---|
95 |
|
---|
96 | if (iterationTimes.size() >= 3) {
|
---|
97 | qreal mean = 0;
|
---|
98 | qreal stddev = 0;
|
---|
99 | uint min = INT_MAX;
|
---|
100 |
|
---|
101 | for (int i = 0; i < iterationTimes.size(); ++i) {
|
---|
102 | mean += iterationTimes.at(i);
|
---|
103 | min = qMin(min, iterationTimes.at(i));
|
---|
104 | }
|
---|
105 |
|
---|
106 | mean /= qreal(iterationTimes.size());
|
---|
107 |
|
---|
108 | for (int i = 0; i < iterationTimes.size(); ++i) {
|
---|
109 | qreal delta = iterationTimes.at(i) - mean;
|
---|
110 | stddev += delta * delta;
|
---|
111 | }
|
---|
112 |
|
---|
113 | stddev = qSqrt(stddev / iterationTimes.size());
|
---|
114 |
|
---|
115 | qSort(iterationTimes.begin(), iterationTimes.end());
|
---|
116 | uint median = iterationTimes.at(iterationTimes.size() / 2);
|
---|
117 |
|
---|
118 | stddev = 100 * stddev / mean;
|
---|
119 |
|
---|
120 | if (iterationTimes.size() >= 10 || stddev < 4) {
|
---|
121 | printf("%s, iterations: %d, frames: %d, min(ms): %d, median(ms): %d, stddev: %f %%, max(fps): %f\n", qPrintable(filename),
|
---|
122 | iterationTimes.size(), updates.size(), min, median, stddev, 1000. * updates.size() / min);
|
---|
123 | deleteLater();
|
---|
|
---|