~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to src/qml/qml/ftw/qqmltrace_p.h

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/
 
5
**
 
6
** This file is part of the QtQml module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** GNU Lesser General Public License Usage
 
10
** This file may be used under the terms of the GNU Lesser General Public
 
11
** License version 2.1 as published by the Free Software Foundation and
 
12
** appearing in the file LICENSE.LGPL included in the packaging of this
 
13
** file. Please review the following information to ensure the GNU Lesser
 
14
** General Public License version 2.1 requirements will be met:
 
15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
16
**
 
17
** In addition, as a special exception, Nokia gives you certain additional
 
18
** rights. These rights are described in the Nokia Qt LGPL Exception
 
19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
20
**
 
21
** GNU General Public License Usage
 
22
** Alternatively, this file may be used under the terms of the GNU General
 
23
** Public License version 3.0 as published by the Free Software Foundation
 
24
** and appearing in the file LICENSE.GPL included in the packaging of this
 
25
** file. Please review the following information to ensure the GNU General
 
26
** Public License version 3.0 requirements will be met:
 
27
** http://www.gnu.org/copyleft/gpl.html.
 
28
**
 
29
** Other Usage
 
30
** Alternatively, this file may be used in accordance with the terms and
 
31
** conditions contained in a signed written agreement between you and Nokia.
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QQMLTRACE_P_H
 
43
#define QQMLTRACE_P_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
49
// This file is not part of the Qt API.  It exists purely as an
 
50
// implementation detail.  This header file may change from version to
 
51
// version without notice, or even be removed.
 
52
//
 
53
// We mean it.
 
54
//
 
55
 
 
56
#include <QtCore/qglobal.h>
 
57
#include <private/qqmlpool_p.h>
 
58
 
 
59
// #define QML_ENABLE_TRACE
 
60
 
 
61
#if defined(QML_ENABLE_TRACE) && defined(Q_OS_MAC)
 
62
#include <mach/mach_time.h>
 
63
#endif
 
64
 
 
65
QT_BEGIN_NAMESPACE
 
66
 
 
67
class QUrl;
 
68
class QQmlTrace
 
69
{
 
70
public:
 
71
    inline QQmlTrace(const char *desc);
 
72
    inline ~QQmlTrace();
 
73
 
 
74
    inline void addDetail(const char *);
 
75
    inline void addDetail(const char *, int);
 
76
    inline void addDetail(const char *, const QString &);
 
77
    inline void addDetail(const char *, const QUrl &);
 
78
 
 
79
    inline void event(const char *desc);
 
80
 
 
81
#ifdef QML_ENABLE_TRACE
 
82
 
 
83
#ifdef Q_OS_MAC
 
84
    typedef uint64_t TimeType;
 
85
#else
 
86
    typedef timespec TimeType;
 
87
#endif
 
88
 
 
89
    struct Entry : public QQmlPool::POD {
 
90
        enum Type { Null, RangeStart, RangeEnd, Detail, IntDetail, StringDetail, UrlDetail, Event };
 
91
        inline Entry();
 
92
        inline Entry(Type);
 
93
        Type type;
 
94
        Entry *next;
 
95
    };
 
96
    struct RangeEnd : public Entry {
 
97
        inline RangeEnd();
 
98
        TimeType time;
 
99
    };
 
100
    struct RangeStart : public Entry {
 
101
        inline RangeStart();
 
102
        const char *description;
 
103
        TimeType time;
 
104
        QQmlTrace::RangeEnd *end;
 
105
    };
 
106
    struct Detail : public Entry {
 
107
        inline Detail();
 
108
        inline Detail(Type t);
 
109
        const char *description;
 
110
    };
 
111
    struct IntDetail : public Detail {
 
112
        inline IntDetail();
 
113
        int value;
 
114
    };
 
115
    struct StringDetail : public Detail {
 
116
        inline StringDetail();
 
117
        QString *value;
 
118
    };
 
119
    struct UrlDetail : public Detail {
 
120
        inline UrlDetail();
 
121
        QUrl *value;
 
122
    };
 
123
    struct Event : public Entry {
 
124
        inline Event();
 
125
        const char *description;
 
126
        TimeType time;
 
127
        QQmlTrace::RangeStart *start;
 
128
    };
 
129
 
 
130
    struct Pool : public QQmlPool {
 
131
        Pool();
 
132
        ~Pool();
 
133
    };
 
134
 
 
135
    static Pool logPool;
 
136
    static Entry *first;
 
137
    static Entry *last;
 
138
 
 
139
private:
 
140
    RangeStart *start;
 
141
 
 
142
    static TimeType gettime() {
 
143
#ifdef Q_OS_MAC
 
144
        return mach_absolute_time();
 
145
#else
 
146
        TimeType ts;
 
147
        clock_gettime(CLOCK_MONOTONIC, &ts);
 
148
        return ts;
 
149
#endif
 
150
    }
 
151
#endif
 
152
};
 
153
 
 
154
#ifdef QML_ENABLE_TRACE
 
155
QQmlTrace::Entry::Entry()
 
156
: type(Null), next(0)
 
157
{
 
158
}
 
159
 
 
160
QQmlTrace::Entry::Entry(Type type)
 
161
: type(type), next(0)
 
162
{
 
163
    QQmlTrace::last->next = this;
 
164
    QQmlTrace::last = this;
 
165
}
 
166
 
 
167
QQmlTrace::RangeEnd::RangeEnd()
 
168
: QQmlTrace::Entry(QQmlTrace::Entry::RangeEnd),
 
169
  time(gettime())
 
170
{
 
171
}
 
172
 
 
173
QQmlTrace::RangeStart::RangeStart()
 
174
: QQmlTrace::Entry(QQmlTrace::Entry::RangeStart),
 
175
  description(0), time(gettime())
 
176
{
 
177
}
 
178
 
 
179
QQmlTrace::Detail::Detail()
 
180
: QQmlTrace::Entry(QQmlTrace::Entry::Detail),
 
181
  description(0)
 
182
{
 
183
}
 
184
 
 
185
QQmlTrace::Detail::Detail(Type type)
 
186
: QQmlTrace::Entry(type), description(0)
 
187
{
 
188
}
 
189
 
 
190
QQmlTrace::IntDetail::IntDetail()
 
191
: QQmlTrace::Detail(QQmlTrace::Entry::IntDetail),
 
192
  value(0)
 
193
{
 
194
}
 
195
 
 
196
QQmlTrace::StringDetail::StringDetail()
 
197
: QQmlTrace::Detail(QQmlTrace::Entry::StringDetail),
 
198
  value(0)
 
199
{
 
200
}
 
201
 
 
202
QQmlTrace::UrlDetail::UrlDetail()
 
203
: QQmlTrace::Detail(QQmlTrace::Entry::UrlDetail),
 
204
  value(0)
 
205
{
 
206
}
 
207
 
 
208
QQmlTrace::Event::Event()
 
209
: QQmlTrace::Entry(QQmlTrace::Entry::Event),
 
210
  description(0), time(gettime()), start(0)
 
211
{
 
212
}
 
213
#endif
 
214
 
 
215
QQmlTrace::QQmlTrace(const char *desc)
 
216
{
 
217
#ifdef QML_ENABLE_TRACE
 
218
    RangeStart *e = logPool.New<RangeStart>();
 
219
    e->description = desc;
 
220
    e->end = 0;
 
221
    start = e;
 
222
#else
 
223
    Q_UNUSED(desc);
 
224
#endif
 
225
}
 
226
 
 
227
QQmlTrace::~QQmlTrace()
 
228
{
 
229
#ifdef QML_ENABLE_TRACE
 
230
    RangeEnd *e = logPool.New<RangeEnd>();
 
231
    start->end = e;
 
232
#endif
 
233
}
 
234
 
 
235
void QQmlTrace::addDetail(const char *desc)
 
236
{
 
237
#ifdef QML_ENABLE_TRACE
 
238
    Detail *e = logPool.New<Detail>();
 
239
    e->description = desc;
 
240
#else
 
241
    Q_UNUSED(desc);
 
242
#endif
 
243
}
 
244
 
 
245
void QQmlTrace::addDetail(const char *desc, int v)
 
246
{
 
247
#ifdef QML_ENABLE_TRACE
 
248
    IntDetail *e = logPool.New<IntDetail>();
 
249
    e->description = desc;
 
250
    e->value = v;
 
251
#else
 
252
    Q_UNUSED(desc);
 
253
    Q_UNUSED(v);
 
254
#endif
 
255
}
 
256
 
 
257
void QQmlTrace::addDetail(const char *desc, const QString &v)
 
258
{
 
259
#ifdef QML_ENABLE_TRACE
 
260
    StringDetail *e = logPool.New<StringDetail>();
 
261
    e->description = desc;
 
262
    e->value = logPool.NewString(v);
 
263
#else
 
264
    Q_UNUSED(desc);
 
265
    Q_UNUSED(v);
 
266
#endif
 
267
}
 
268
 
 
269
void QQmlTrace::addDetail(const char *desc, const QUrl &v)
 
270
{
 
271
#ifdef QML_ENABLE_TRACE
 
272
    UrlDetail *e = logPool.New<UrlDetail>();
 
273
    e->description = desc;
 
274
    e->value = logPool.NewUrl(v);
 
275
#else
 
276
    Q_UNUSED(desc);
 
277
    Q_UNUSED(v);
 
278
#endif
 
279
}
 
280
 
 
281
void QQmlTrace::event(const char *desc)
 
282
{
 
283
#ifdef QML_ENABLE_TRACE
 
284
    Event *e = logPool.New<Event>();
 
285
    e->start = start;
 
286
    e->description = desc;
 
287
#else
 
288
    Q_UNUSED(desc);
 
289
#endif
 
290
}
 
291
 
 
292
QT_END_NAMESPACE
 
293
 
 
294
#endif // QQMLTRACE_P_H