1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 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, int from, int to, bool single, int frame);
|
---|
53 |
|
---|
54 | void paintEvent(QPaintEvent *event);
|
---|
55 | void resizeEvent(QResizeEvent *event);
|
---|
56 |
|
---|
57 | public slots:
|
---|
58 | void updateRect();
|
---|
59 |
|
---|
60 | public:
|
---|
61 | QList<QRegion> updates;
|
---|
62 | QPaintBuffer buffer;
|
---|
63 |
|
---|
64 | int currentFrame;
|
---|
65 | int currentIteration;
|
---|
66 | QTime timer;
|
---|
67 |
|
---|
68 | QList<uint> visibleUpdates;
|
---|
69 |
|
---|
70 | QVector<uint> iterationTimes;
|
---|
71 | QString filename;
|
---|
72 |
|
---|
73 | int from;
|
---|
74 | int to;
|
---|
75 |
|
---|
76 | bool single;
|
---|
77 |
|
---|
78 | int frame;
|
---|
79 | int currentCommand;
|
---|
80 | };
|
---|
81 |
|
---|
82 | void ReplayWidget::updateRect()
|
---|
83 | {
|
---|
84 | if (frame >= 0 && !updates.isEmpty())
|
---|
85 | update(updates.at(frame));
|
---|
86 | else if (!visibleUpdates.isEmpty())
|
---|
87 | update(updates.at(visibleUpdates.at(currentFrame)));
|
---|
88 | }
|
---|
89 |
|
---|
90 | const int singleFrameRepeatsPerCommand = 100;
|
---|
91 | const int singleFrameIterations = 4;
|
---|
92 |
|
---|
93 | void ReplayWidget::paintEvent(QPaintEvent *)
|
---|
94 | {
|
---|
95 | QPainter p(this);
|
---|
96 |
|
---|
97 | QTimer::singleShot(0, this, SLOT(updateRect()));
|
---|
98 |
|
---|
99 | // p.setClipRegion(frames.at(currentFrame).updateRegion);
|
---|
100 |
|
---|
101 | if (frame >= 0) {
|
---|
102 | int start = buffer.frameStartIndex(frame);
|
---|
103 | int end = buffer.frameEndIndex(frame);
|
---|
104 |
|
---|
105 | iterationTimes.resize(end - start);
|
---|
106 |
|
---|
107 | int saveRestoreStackDepth = buffer.processCommands(&p, start, start + currentCommand);
|
---|
108 |
|
---|
109 | for (int i = 0; i < saveRestoreStackDepth; ++i)
|
---|
110 | p.restore();
|
---|
111 |
|
---|
112 | const int repeats = currentIteration >= 3 ? singleFrameRepeatsPerCommand : 1;
|
---|
113 |
|
---|
114 | ++currentFrame;
|
---|
115 | if (currentFrame == repeats) {
|
---|
116 | currentFrame = 0;
|
---|
117 | if (currentIteration >= 3) {
|
---|
118 | iterationTimes[currentCommand - 1] = qMin(iterationTimes[currentCommand - 1], uint(timer.elapsed()));
|
---|
119 | timer.restart();
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (currentIteration >= singleFrameIterations + 3) {
|
---|
123 | printf(" # | ms | description\n");
|
---|
124 | printf("------+---------+------------------------------------------------------------\n");
|
---|
125 |
|
---|
126 | qSort(iterationTimes);
|
---|
127 |
|
---|
128 | int sum = 0;
|
---|
129 | for (int i = 0; i < iterationTimes.size(); ++i) {
|
---|
130 | int delta = iterationTimes.at(i);
|
---|
131 | if (i > 0)
|
---|
132 | delta -= iterationTimes.at(i-1);
|
---|
133 | sum += delta;
|
---|
134 | qreal deltaF = delta / qreal(repeats);
|
---|
135 | printf("%.5d | %.5f | %s\n", i, deltaF, qPrintable(buffer.commandDescription(start + i)));
|
---|
136 | }
|
---|
137 | printf("Total | %.5f | Total frame time\n", sum / qreal(repeats));
|
---|
138 | deleteLater();
|
---|
139 | return;
|
---|
140 | }
|
---|
141 |
|
---|
142 | if (start + currentCommand >= end) {
|
---|
143 | currentCommand = 1;
|
---|
144 | ++currentIteration;
|
---|
145 | if (currentIteration == 3) {
|
---|
146 | timer.start();
|
---|
147 | iterationTimes.fill(uint(-1));
|
---|
148 | }
|
---|
149 | if (currentIteration >= 3 && currentIteration < singleFrameIterations + 3)
|
---|
150 | printf("Profiling iteration %d of %d\n", currentIteration - 2, singleFrameIterations);
|
---|
151 | } else {
|
---|
152 | ++currentCommand;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | return;
|
---|
157 | }
|
---|
158 |
|
---|
159 | buffer.draw(&p, visibleUpdates.at(currentFrame));
|
---|
160 |
|
---|
161 | ++currentFrame;
|
---|
|
---|