| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopengltimerquery.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | class QExtTimerQueryHelper | - | ||||||||||||||||||
| 7 | { | - | ||||||||||||||||||
| 8 | public: | - | ||||||||||||||||||
| 9 | QExtTimerQueryHelper(QOpenGLContext *context) | - | ||||||||||||||||||
| 10 | { | - | ||||||||||||||||||
| 11 | ((!(context)) ? qt_assert("context",__FILE__,55) : qt_noop()); | - | ||||||||||||||||||
| 12 | GetQueryObjectui64vEXT = reinterpret_cast<void ( *)(GLuint , GLenum , GLuint64EXT *)>(context->getProcAddress("glGetQueryObjectui64vEXT")); | - | ||||||||||||||||||
| 13 | GetQueryObjecti64vEXT = reinterpret_cast<void ( *)(GLuint , GLenum , GLint64EXT *)>(context->getProcAddress("glGetQueryObjecti64vEXT")); | - | ||||||||||||||||||
| 14 | } never executed: end of block | 0 | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | inline void glGetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params) | - | ||||||||||||||||||
| 17 | { | - | ||||||||||||||||||
| 18 | GetQueryObjectui64vEXT(id, pname, params); | - | ||||||||||||||||||
| 19 | } never executed: end of block | 0 | ||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | inline void glGetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params) | - | ||||||||||||||||||
| 22 | { | - | ||||||||||||||||||
| 23 | GetQueryObjecti64vEXT(id, pname, params); | - | ||||||||||||||||||
| 24 | } never executed: end of block | 0 | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | private: | - | ||||||||||||||||||
| 27 | void ( * GetQueryObjectui64vEXT)(GLuint id, GLenum pname, GLuint64EXT *params); | - | ||||||||||||||||||
| 28 | void ( * GetQueryObjecti64vEXT)(GLuint id, GLenum pname, GLint64EXT *params); | - | ||||||||||||||||||
| 29 | }; | - | ||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | class QOpenGLTimerQueryPrivate : public QObjectPrivate | - | ||||||||||||||||||
| 32 | { | - | ||||||||||||||||||
| 33 | public: | - | ||||||||||||||||||
| 34 | QOpenGLTimerQueryPrivate() | - | ||||||||||||||||||
| 35 | : QObjectPrivate(), | - | ||||||||||||||||||
| 36 | context(0), | - | ||||||||||||||||||
| 37 | ext(0), | - | ||||||||||||||||||
| 38 | timeInterval(0), | - | ||||||||||||||||||
| 39 | timer(0) | - | ||||||||||||||||||
| 40 | { | - | ||||||||||||||||||
| 41 | } never executed: end of block | 0 | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | ~QOpenGLTimerQueryPrivate() | - | ||||||||||||||||||
| 44 | { | - | ||||||||||||||||||
| 45 | delete core; | - | ||||||||||||||||||
| 46 | delete ext; | - | ||||||||||||||||||
| 47 | } never executed: end of block | 0 | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | bool create(); | - | ||||||||||||||||||
| 50 | void destroy(); | - | ||||||||||||||||||
| 51 | void begin(); | - | ||||||||||||||||||
| 52 | void end(); | - | ||||||||||||||||||
| 53 | GLuint64 waitForTimeStamp() const; | - | ||||||||||||||||||
| 54 | void recordTimestamp(); | - | ||||||||||||||||||
| 55 | bool isResultAvailable() const; | - | ||||||||||||||||||
| 56 | GLuint64 result() const; | - | ||||||||||||||||||
| 57 | QOpenGLContext *context; | - | ||||||||||||||||||
| 58 | QOpenGLQueryHelper *core; | - | ||||||||||||||||||
| 59 | QExtTimerQueryHelper *ext; | - | ||||||||||||||||||
| 60 | mutable GLuint64 timeInterval; | - | ||||||||||||||||||
| 61 | GLuint timer; | - | ||||||||||||||||||
| 62 | }; | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | bool QOpenGLTimerQueryPrivate::create() | - | ||||||||||||||||||
| 65 | { | - | ||||||||||||||||||
| 66 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | if (timer
| 0 | ||||||||||||||||||
| 69 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | context = ctx; | - | ||||||||||||||||||
| 72 | if (!context
| 0 | ||||||||||||||||||
| 73 | QMessageLogger(__FILE__, 132, __PRETTY_FUNCTION__).warning("A current OpenGL context is required to create timer query objects"); | - | ||||||||||||||||||
| 74 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 75 | } | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | if (context->isOpenGLES()
| 0 | ||||||||||||||||||
| 78 | QMessageLogger(__FILE__, 137, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery: Not supported on OpenGL ES"); | - | ||||||||||||||||||
| 79 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 80 | } | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | core = new QOpenGLQueryHelper(context); | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | QSurfaceFormat f = context->format(); | - | ||||||||||||||||||
| 87 | if (f.version() <= qMakePair<int, int>(3, 2)
| 0 | ||||||||||||||||||
| 88 | && !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 89 | && context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_EXT_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_EXT_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 90 | ext = new QExtTimerQueryHelper(context); | - | ||||||||||||||||||
| 91 | } never executed: else if (f.version() <= qMakePair<int, int>(3, 2)end of block
| 0 | ||||||||||||||||||
| 92 | && !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 93 | && !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_EXT_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_EXT_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 94 | QMessageLogger(__FILE__, 153, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery requires one of:\n" | - | ||||||||||||||||||
| 95 | " OpenGL 3.3 or newer,\n" | - | ||||||||||||||||||
| 96 | " OpenGL 3.2 and the ARB_timer_query extension\n" | - | ||||||||||||||||||
| 97 | " or the EXT_timer query extension"); | - | ||||||||||||||||||
| 98 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 99 | } | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | core->glGenQueries(1, &timer); | - | ||||||||||||||||||
| 102 | return never executed: (timer != 0);return (timer != 0);never executed: return (timer != 0); | 0 | ||||||||||||||||||
| 103 | } | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | void QOpenGLTimerQueryPrivate::destroy() | - | ||||||||||||||||||
| 106 | { | - | ||||||||||||||||||
| 107 | if (!timer
| 0 | ||||||||||||||||||
| 108 | return; never executed: return; | 0 | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | core->glDeleteQueries(1, &timer); | - | ||||||||||||||||||
| 111 | timer = 0; | - | ||||||||||||||||||
| 112 | context = 0; | - | ||||||||||||||||||
| 113 | } never executed: end of block | 0 | ||||||||||||||||||
| 114 | void QOpenGLTimerQueryPrivate::begin() | - | ||||||||||||||||||
| 115 | { | - | ||||||||||||||||||
| 116 | core->glBeginQuery(0x88BF, timer); | - | ||||||||||||||||||
| 117 | } never executed: end of block | 0 | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | void QOpenGLTimerQueryPrivate::end() | - | ||||||||||||||||||
| 120 | { | - | ||||||||||||||||||
| 121 | core->glEndQuery(0x88BF); | - | ||||||||||||||||||
| 122 | } never executed: end of block | 0 | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | void QOpenGLTimerQueryPrivate::recordTimestamp() | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | if (!ext
| 0 | ||||||||||||||||||
| 129 | core->glQueryCounter(timer, 0x8E28); never executed: core->glQueryCounter(timer, 0x8E28); | 0 | ||||||||||||||||||
| 130 | else | - | ||||||||||||||||||
| 131 | QMessageLogger(__FILE__, 201, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::recordTimestamp() requires OpenGL 3.3 or GL_ARB_timer_query"); never executed: QMessageLogger(__FILE__, 201, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::recordTimestamp() requires OpenGL 3.3 or GL_ARB_timer_query"); | 0 | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | } | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | GLuint64 QOpenGLTimerQueryPrivate::waitForTimeStamp() const | - | ||||||||||||||||||
| 138 | { | - | ||||||||||||||||||
| 139 | GLint64 tmp = 0; | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | if (!ext
| 0 | ||||||||||||||||||
| 142 | core->glGetInteger64v(0x8E28, &tmp); never executed: core->glGetInteger64v(0x8E28, &tmp); | 0 | ||||||||||||||||||
| 143 | else | - | ||||||||||||||||||
| 144 | QMessageLogger(__FILE__, 214, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::waitForTimestamp() requires OpenGL 3.3 or GL_ARB_timer_query"); never executed: QMessageLogger(__FILE__, 214, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::waitForTimestamp() requires OpenGL 3.3 or GL_ARB_timer_query"); | 0 | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | GLuint64 timestamp(tmp); | - | ||||||||||||||||||
| 149 | return never executed: timestamp;return timestamp;never executed: return timestamp; | 0 | ||||||||||||||||||
| 150 | } | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | bool QOpenGLTimerQueryPrivate::isResultAvailable() const | - | ||||||||||||||||||
| 153 | { | - | ||||||||||||||||||
| 154 | GLuint available = 0; | - | ||||||||||||||||||
| 155 | core->glGetQueryObjectuiv(timer, 0x8867, &available); | - | ||||||||||||||||||
| 156 | return never executed: available;return available;never executed: return available; | 0 | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | GLuint64 QOpenGLTimerQueryPrivate::result() const | - | ||||||||||||||||||
| 160 | { | - | ||||||||||||||||||
| 161 | if (!ext
| 0 | ||||||||||||||||||
| 162 | core->glGetQueryObjectui64v(timer, 0x8866, &timeInterval); never executed: core->glGetQueryObjectui64v(timer, 0x8866, &timeInterval); | 0 | ||||||||||||||||||
| 163 | else | - | ||||||||||||||||||
| 164 | ext->glGetQueryObjectui64vEXT(timer, 0x8866, &timeInterval); never executed: ext->glGetQueryObjectui64vEXT(timer, 0x8866, &timeInterval); | 0 | ||||||||||||||||||
| 165 | return never executed: timeInterval;return timeInterval;never executed: return timeInterval; | 0 | ||||||||||||||||||
| 166 | } | - | ||||||||||||||||||
| 167 | QOpenGLTimerQuery::QOpenGLTimerQuery(QObject *parent) | - | ||||||||||||||||||
| 168 | : QObject(*new QOpenGLTimerQueryPrivate, parent) | - | ||||||||||||||||||
| 169 | { | - | ||||||||||||||||||
| 170 | } never executed: end of block | 0 | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | QOpenGLTimerQuery::~QOpenGLTimerQuery() | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | QOpenGLContext* ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 180 | QOpenGLContext *oldContext = 0; | - | ||||||||||||||||||
| 181 | if (d->context != ctx
| 0 | ||||||||||||||||||
| 182 | oldContext = ctx; | - | ||||||||||||||||||
| 183 | if (d->context->makeCurrent(oldContext->surface())
| 0 | ||||||||||||||||||
| 184 | ctx = d->context; | - | ||||||||||||||||||
| 185 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 186 | QMessageLogger(__FILE__, 319, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::~QOpenGLTimerQuery() failed to make query objects's context current"); | - | ||||||||||||||||||
| 187 | ctx = 0; | - | ||||||||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | if (ctx
| 0 | ||||||||||||||||||
| 192 | destroy(); never executed: destroy(); | 0 | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | if (oldContext
| 0 | ||||||||||||||||||
| 195 | if (!oldContext->makeCurrent(oldContext->surface())
| 0 | ||||||||||||||||||
| 196 | QMessageLogger(__FILE__, 329, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::~QOpenGLTimerQuery() failed to restore current context"); never executed: QMessageLogger(__FILE__, 329, __PRETTY_FUNCTION__).warning("QOpenGLTimerQuery::~QOpenGLTimerQuery() failed to restore current context"); | 0 | ||||||||||||||||||
| 197 | } never executed: end of block | 0 | ||||||||||||||||||
| 198 | } never executed: end of block | 0 | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | bool QOpenGLTimerQuery::create() | - | ||||||||||||||||||
| 207 | { | - | ||||||||||||||||||
| 208 | QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 209 | return never executed: d->create();return d->create();never executed: return d->create(); | 0 | ||||||||||||||||||
| 210 | } | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | void QOpenGLTimerQuery::destroy() | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 219 | d->destroy(); | - | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | bool QOpenGLTimerQuery::isCreated() const | - | ||||||||||||||||||
| 228 | { | - | ||||||||||||||||||
| 229 | const QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 230 | return never executed: (d->timer != 0);return (d->timer != 0);never executed: return (d->timer != 0); | 0 | ||||||||||||||||||
| 231 | } | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | GLuint QOpenGLTimerQuery::objectId() const | - | ||||||||||||||||||
| 237 | { | - | ||||||||||||||||||
| 238 | const QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 239 | return never executed: d->timer;return d->timer;never executed: return d->timer; | 0 | ||||||||||||||||||
| 240 | } | - | ||||||||||||||||||
| 241 | void QOpenGLTimerQuery::begin() | - | ||||||||||||||||||
| 242 | { | - | ||||||||||||||||||
| 243 | QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 244 | d->begin(); | - | ||||||||||||||||||
| 245 | } never executed: end of block | 0 | ||||||||||||||||||
| 246 | void QOpenGLTimerQuery::end() | - | ||||||||||||||||||
| 247 | { | - | ||||||||||||||||||
| 248 | QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 249 | d->end(); | - | ||||||||||||||||||
| 250 | } never executed: end of block | 0 | ||||||||||||||||||
| 251 | void QOpenGLTimerQuery::recordTimestamp() | - | ||||||||||||||||||
| 252 | { | - | ||||||||||||||||||
| 253 | QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 254 | return never executed: d->recordTimestamp();return d->recordTimestamp();never executed: return d->recordTimestamp(); | 0 | ||||||||||||||||||
| 255 | } | - | ||||||||||||||||||
| 256 | GLuint64 QOpenGLTimerQuery::waitForTimestamp() const | - | ||||||||||||||||||
| 257 | { | - | ||||||||||||||||||
| 258 | const QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 259 | return never executed: d->waitForTimeStamp();return d->waitForTimeStamp();never executed: return d->waitForTimeStamp(); | 0 | ||||||||||||||||||
| 260 | } | - | ||||||||||||||||||
| 261 | bool QOpenGLTimerQuery::isResultAvailable() const | - | ||||||||||||||||||
| 262 | { | - | ||||||||||||||||||
| 263 | const QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 264 | return never executed: d->isResultAvailable();return d->isResultAvailable();never executed: return d->isResultAvailable(); | 0 | ||||||||||||||||||
| 265 | } | - | ||||||||||||||||||
| 266 | GLuint64 QOpenGLTimerQuery::waitForResult() const | - | ||||||||||||||||||
| 267 | { | - | ||||||||||||||||||
| 268 | const QOpenGLTimerQueryPrivate * const d = d_func(); | - | ||||||||||||||||||
| 269 | return never executed: d->result();return d->result();never executed: return d->result(); | 0 | ||||||||||||||||||
| 270 | } | - | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | class QOpenGLTimeMonitorPrivate : public QObjectPrivate | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | public: | - | ||||||||||||||||||
| 276 | QOpenGLTimeMonitorPrivate() | - | ||||||||||||||||||
| 277 | : QObjectPrivate(), | - | ||||||||||||||||||
| 278 | timers(), | - | ||||||||||||||||||
| 279 | timeSamples(), | - | ||||||||||||||||||
| 280 | context(0), | - | ||||||||||||||||||
| 281 | core(0), | - | ||||||||||||||||||
| 282 | ext(0), | - | ||||||||||||||||||
| 283 | requestedSampleCount(2), | - | ||||||||||||||||||
| 284 | currentSample(-1), | - | ||||||||||||||||||
| 285 | timerQueryActive(false) | - | ||||||||||||||||||
| 286 | { | - | ||||||||||||||||||
| 287 | } never executed: end of block | 0 | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | ~QOpenGLTimeMonitorPrivate() | - | ||||||||||||||||||
| 290 | { | - | ||||||||||||||||||
| 291 | delete core; | - | ||||||||||||||||||
| 292 | delete ext; | - | ||||||||||||||||||
| 293 | } never executed: end of block | 0 | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | bool create(); | - | ||||||||||||||||||
| 296 | void destroy(); | - | ||||||||||||||||||
| 297 | void recordSample(); | - | ||||||||||||||||||
| 298 | bool isResultAvailable() const; | - | ||||||||||||||||||
| 299 | QVector<GLuint64> samples() const; | - | ||||||||||||||||||
| 300 | QVector<GLuint64> intervals() const; | - | ||||||||||||||||||
| 301 | void reset(); | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | QVector<GLuint> timers; | - | ||||||||||||||||||
| 304 | mutable QVector<GLuint64> timeSamples; | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | QOpenGLContext *context; | - | ||||||||||||||||||
| 307 | QOpenGLQueryHelper *core; | - | ||||||||||||||||||
| 308 | QExtTimerQueryHelper *ext; | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | int requestedSampleCount; | - | ||||||||||||||||||
| 311 | int currentSample; | - | ||||||||||||||||||
| 312 | mutable bool timerQueryActive; | - | ||||||||||||||||||
| 313 | }; | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | bool QOpenGLTimeMonitorPrivate::create() | - | ||||||||||||||||||
| 316 | { | - | ||||||||||||||||||
| 317 | if (!timers.isEmpty()
| 0 | ||||||||||||||||||
| 318 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 321 | if (context
| 0 | ||||||||||||||||||
| 322 | QMessageLogger(__FILE__, 513, __PRETTY_FUNCTION__).warning("QTimeMonitor: Attempting to use different OpenGL context to recreate timers.\n" | - | ||||||||||||||||||
| 323 | "Please call destroy() first or use the same context to previously create"); | - | ||||||||||||||||||
| 324 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 325 | } | - | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | context = ctx; | - | ||||||||||||||||||
| 328 | if (!context
| 0 | ||||||||||||||||||
| 329 | QMessageLogger(__FILE__, 520, __PRETTY_FUNCTION__).warning("A current OpenGL context is required to create timer query objects"); | - | ||||||||||||||||||
| 330 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 331 | } | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | timers.resize(requestedSampleCount); | - | ||||||||||||||||||
| 335 | timeSamples.resize(requestedSampleCount); | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | core = new QOpenGLQueryHelper(context); | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | QSurfaceFormat f = context->format(); | - | ||||||||||||||||||
| 342 | if (f.version() <= qMakePair<int, int>(3, 2)
| 0 | ||||||||||||||||||
| 343 | && !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 344 | && context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_EXT_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_EXT_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 345 | ext = new QExtTimerQueryHelper(context); | - | ||||||||||||||||||
| 346 | } never executed: else if (f.version() <= qMakePair<int, int>(3, 2)end of block
| 0 | ||||||||||||||||||
| 347 | && !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 348 | && !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_EXT_timer_query") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_EXT_timer_query" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
| 0 | ||||||||||||||||||
| 349 | QMessageLogger(__FILE__, 540, __PRETTY_FUNCTION__).warning("QOpenGLTimeMonitor requires one of:\n" | - | ||||||||||||||||||
| 350 | " OpenGL 3.3 or newer,\n" | - | ||||||||||||||||||
| 351 | " OpenGL 3.2 and the ARB_timer_query extension\n" | - | ||||||||||||||||||
| 352 | " or the EXT_timer query extension"); | - | ||||||||||||||||||
| 353 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 354 | } | - | ||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | core->glGenQueries(requestedSampleCount, timers.data()); | - | ||||||||||||||||||
| 357 | return never executed: (timers.at(0) != 0);return (timers.at(0) != 0);never executed: return (timers.at(0) != 0); | 0 | ||||||||||||||||||
| 358 | } | - | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | void QOpenGLTimeMonitorPrivate::destroy() | - | ||||||||||||||||||
| 361 | { | - | ||||||||||||||||||
| 362 | if (timers.isEmpty()
| 0 | ||||||||||||||||||
| 363 | return; never executed: return; | 0 | ||||||||||||||||||
| 364 | - | |||||||||||||||||||
| 365 | core->glDeleteQueries(timers.size(), timers.data()); | - | ||||||||||||||||||
| 366 | timers.clear(); | - | ||||||||||||||||||
| 367 | delete core; | - | ||||||||||||||||||
| 368 | core = 0; | - | ||||||||||||||||||
| 369 | delete ext; | - | ||||||||||||||||||
| 370 | ext = 0; | - | ||||||||||||||||||
| 371 | context = 0; | - | ||||||||||||||||||
| 372 | } never executed: end of block | 0 | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | void QOpenGLTimeMonitorPrivate::recordSample() | - | ||||||||||||||||||
| 375 | { | - | ||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | if (!ext
| 0 | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | core->glQueryCounter(timers.at(++currentSample), 0x8E28); | - | ||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 383 | if (currentSample == -1
| 0 | ||||||||||||||||||
| 384 | core->glBeginQuery(0x88BF, timers.at(++currentSample)); | - | ||||||||||||||||||
| 385 | timerQueryActive = true; | - | ||||||||||||||||||
| 386 | } never executed: else if (currentSample < timers.size() - 1end of block
| 0 | ||||||||||||||||||
| 387 | core->glEndQuery(0x88BF); | - | ||||||||||||||||||
| 388 | core->glBeginQuery(0x88BF, timers.at(++currentSample)); | - | ||||||||||||||||||
| 389 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 390 | if (timerQueryActive
| 0 | ||||||||||||||||||
| 391 | core->glEndQuery(0x88BF); | - | ||||||||||||||||||
| 392 | timerQueryActive = false; | - | ||||||||||||||||||
| 393 | } never executed: end of block | 0 | ||||||||||||||||||
| 394 | } never executed: end of block | 0 | ||||||||||||||||||
| 395 | } | - | ||||||||||||||||||
| 396 | } | - | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | bool QOpenGLTimeMonitorPrivate::isResultAvailable() const | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | - | |||||||||||||||||||
| 403 | GLuint available = 0; | - | ||||||||||||||||||
| 404 | core->glGetQueryObjectuiv(timers.at(currentSample), 0x8867, &available); | - | ||||||||||||||||||
| 405 | return never executed: available;return available;never executed: return available; | 0 | ||||||||||||||||||
| 406 | } | - | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | QVector<GLuint64> QOpenGLTimeMonitorPrivate::samples() const | - | ||||||||||||||||||
| 409 | { | - | ||||||||||||||||||
| 410 | - | |||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | if (!ext
| 0 | ||||||||||||||||||
| 414 | for (int i = 0; i <= currentSample
| 0 | ||||||||||||||||||
| 415 | core->glGetQueryObjectui64v(timers.at(i), 0x8866, &timeSamples[i]); never executed: core->glGetQueryObjectui64v(timers.at(i), 0x8866, &timeSamples[i]); | 0 | ||||||||||||||||||
| 416 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 417 | QMessageLogger(__FILE__, 608, __PRETTY_FUNCTION__).warning("QOpenGLTimeMonitor::samples() requires OpenGL >=3.3\n" | - | ||||||||||||||||||
| 418 | "or OpenGL 3.2 and GL_ARB_timer_query"); | - | ||||||||||||||||||
| 419 | } never executed: end of block | 0 | ||||||||||||||||||
| 420 | return never executed: timeSamples;return timeSamples;never executed: return timeSamples; | 0 | ||||||||||||||||||
| 421 | } | - | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | QVector<GLuint64> QOpenGLTimeMonitorPrivate::intervals() const | - | ||||||||||||||||||
| 424 | { | - | ||||||||||||||||||
| 425 | QVector<GLuint64> intervals(timers.size() - 1); | - | ||||||||||||||||||
| 426 | if (!ext
| 0 | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | const QVector<GLuint64> timeStamps = samples(); | - | ||||||||||||||||||
| 429 | for (int i = 0; i < intervals.size()
| 0 | ||||||||||||||||||
| 430 | intervals[i] = timeStamps[i+1] - timeStamps[i]; never executed: intervals[i] = timeStamps[i+1] - timeStamps[i]; | 0 | ||||||||||||||||||
| 431 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | if (timerQueryActive
| 0 | ||||||||||||||||||
| 434 | core->glEndQuery(0x88BF); | - | ||||||||||||||||||
| 435 | timerQueryActive = false; | - | ||||||||||||||||||
| 436 | } never executed: end of block | 0 | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | for (int i = 0; i < currentSample
| 0 | ||||||||||||||||||
| 441 | ext->glGetQueryObjectui64vEXT(timers.at(i), 0x8866, &intervals[i]); never executed: ext->glGetQueryObjectui64vEXT(timers.at(i), 0x8866, &intervals[i]); | 0 | ||||||||||||||||||
| 442 | } never executed: end of block | 0 | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | return never executed: intervals;return intervals;never executed: return intervals; | 0 | ||||||||||||||||||
| 445 | } | - | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | void QOpenGLTimeMonitorPrivate::reset() | - | ||||||||||||||||||
| 448 | { | - | ||||||||||||||||||
| 449 | currentSample = -1; | - | ||||||||||||||||||
| 450 | timeSamples.fill(0); | - | ||||||||||||||||||
| 451 | } never executed: end of block | 0 | ||||||||||||||||||
| 452 | QOpenGLTimeMonitor::QOpenGLTimeMonitor(QObject *parent) | - | ||||||||||||||||||
| 453 | : QObject(*new QOpenGLTimeMonitorPrivate, parent) | - | ||||||||||||||||||
| 454 | { | - | ||||||||||||||||||
| 455 | } never executed: end of block | 0 | ||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | QOpenGLTimeMonitor::~QOpenGLTimeMonitor() | - | ||||||||||||||||||
| 461 | { | - | ||||||||||||||||||
| 462 | QOpenGLContext* ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 465 | QOpenGLContext *oldContext = 0; | - | ||||||||||||||||||
| 466 | if (d->context != ctx
| 0 | ||||||||||||||||||
| 467 | oldContext = ctx; | - | ||||||||||||||||||
| 468 | if (d->context->makeCurrent(oldContext->surface())
| 0 | ||||||||||||||||||
| 469 | ctx = d->context; | - | ||||||||||||||||||
| 470 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 471 | QMessageLogger(__FILE__, 710, __PRETTY_FUNCTION__).warning("QOpenGLTimeMonitor::~QOpenGLTimeMonitor() failed to make time monitor's context current"); | - | ||||||||||||||||||
| 472 | ctx = 0; | - | ||||||||||||||||||
| 473 | } never executed: end of block | 0 | ||||||||||||||||||
| 474 | } | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | if (ctx
| 0 | ||||||||||||||||||
| 477 | destroy(); never executed: destroy(); | 0 | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | if (oldContext
| 0 | ||||||||||||||||||
| 480 | if (!oldContext->makeCurrent(oldContext->surface())
| 0 | ||||||||||||||||||
| 481 | QMessageLogger(__FILE__, 720, __PRETTY_FUNCTION__).warning("QOpenGLTimeMonitor::~QOpenGLTimeMonitor() failed to restore current context"); never executed: QMessageLogger(__FILE__, 720, __PRETTY_FUNCTION__).warning("QOpenGLTimeMonitor::~QOpenGLTimeMonitor() failed to restore current context"); | 0 | ||||||||||||||||||
| 482 | } never executed: end of block | 0 | ||||||||||||||||||
| 483 | } never executed: end of block | 0 | ||||||||||||||||||
| 484 | void QOpenGLTimeMonitor::setSampleCount(int sampleCount) | - | ||||||||||||||||||
| 485 | { | - | ||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | if (sampleCount < 2
| 0 | ||||||||||||||||||
| 488 | return; never executed: return; | 0 | ||||||||||||||||||
| 489 | QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 490 | d->requestedSampleCount = sampleCount; | - | ||||||||||||||||||
| 491 | } never executed: end of block | 0 | ||||||||||||||||||
| 492 | int QOpenGLTimeMonitor::sampleCount() const | - | ||||||||||||||||||
| 493 | { | - | ||||||||||||||||||
| 494 | const QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 495 | return never executed: d->requestedSampleCount;return d->requestedSampleCount;never executed: return d->requestedSampleCount; | 0 | ||||||||||||||||||
| 496 | } | - | ||||||||||||||||||
| 497 | bool QOpenGLTimeMonitor::create() | - | ||||||||||||||||||
| 498 | { | - | ||||||||||||||||||
| 499 | QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 500 | return never executed: d->create();return d->create();never executed: return d->create(); | 0 | ||||||||||||||||||
| 501 | } | - | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | void QOpenGLTimeMonitor::destroy() | - | ||||||||||||||||||
| 509 | { | - | ||||||||||||||||||
| 510 | QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 511 | d->destroy(); | - | ||||||||||||||||||
| 512 | } never executed: end of block | 0 | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | - | |||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | bool QOpenGLTimeMonitor::isCreated() const | - | ||||||||||||||||||
| 520 | { | - | ||||||||||||||||||
| 521 | const QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 522 | return never executed: (!d->timers.isEmpty() && d->timers.at(0) != 0);return (!d->timers.isEmpty() && d->timers.at(0) != 0);never executed: return (!d->timers.isEmpty() && d->timers.at(0) != 0); | 0 | ||||||||||||||||||
| 523 | } | - | ||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | - | |||||||||||||||||||
| 528 | QVector<GLuint> QOpenGLTimeMonitor::objectIds() const | - | ||||||||||||||||||
| 529 | { | - | ||||||||||||||||||
| 530 | const QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 531 | return never executed: d->timers;return d->timers;never executed: return d->timers; | 0 | ||||||||||||||||||
| 532 | } | - | ||||||||||||||||||
| 533 | int QOpenGLTimeMonitor::recordSample() | - | ||||||||||||||||||
| 534 | { | - | ||||||||||||||||||
| 535 | QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 536 | d->recordSample(); | - | ||||||||||||||||||
| 537 | return never executed: d->currentSample;return d->currentSample;never executed: return d->currentSample; | 0 | ||||||||||||||||||
| 538 | } | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | - | |||||||||||||||||||
| 542 | - | |||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | bool QOpenGLTimeMonitor::isResultAvailable() const | - | ||||||||||||||||||
| 546 | { | - | ||||||||||||||||||
| 547 | const QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 548 | return never executed: d->isResultAvailable();return d->isResultAvailable();never executed: return d->isResultAvailable(); | 0 | ||||||||||||||||||
| 549 | } | - | ||||||||||||||||||
| 550 | QVector<GLuint64> QOpenGLTimeMonitor::waitForSamples() const | - | ||||||||||||||||||
| 551 | { | - | ||||||||||||||||||
| 552 | const QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 553 | return never executed: d->samples();return d->samples();never executed: return d->samples(); | 0 | ||||||||||||||||||
| 554 | } | - | ||||||||||||||||||
| 555 | QVector<GLuint64> QOpenGLTimeMonitor::waitForIntervals() const | - | ||||||||||||||||||
| 556 | { | - | ||||||||||||||||||
| 557 | const QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 558 | return never executed: d->intervals();return d->intervals();never executed: return d->intervals(); | 0 | ||||||||||||||||||
| 559 | } | - | ||||||||||||||||||
| 560 | void QOpenGLTimeMonitor::reset() | - | ||||||||||||||||||
| 561 | { | - | ||||||||||||||||||
| 562 | QOpenGLTimeMonitorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 563 | d->reset(); | - | ||||||||||||||||||
| 564 | } never executed: end of block | 0 | ||||||||||||||||||
| 565 | - | |||||||||||||||||||
| 566 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |