4#include <QtQuick/private/qsgcontext_p.h>
5#include <QtQuick/private/qsgtexture_p.h>
6#include <QtQuick/private/qsgrenderer_p.h>
7#include <QtQuick/private/qquickpixmap_p.h>
8#include <QtQuick/private/qsgadaptationlayer_p.h>
9#include <QtQuick/private/qsginternaltextnode_p.h>
11#include <QGuiApplication>
13#include <QQuickWindow>
15#include <private/qqmlglobal_p.h>
17#include <QtQuick/private/qsgtexture_p.h>
18#include <QtGui/private/qguiapplication_p.h>
19#include <QtCore/private/qabstractanimation_p.h>
21#include <private/qobject_p.h>
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
45Q_LOGGING_CATEGORY(QSG_LOG_INFO,
"qt.scenegraph.general")
49Q_LOGGING_CATEGORY(QSG_LOG_RENDERLOOP,
"qt.scenegraph.renderloop")
53Q_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION,
"qt.scenegraph.time.compilation")
56Q_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP,
"qt.scenegraph.time.renderloop")
59Q_LOGGING_CATEGORY(QSG_LOG_TIME_TEXTURE,
"qt.scenegraph.time.texture")
62Q_LOGGING_CATEGORY(QSG_LOG_TIME_GLYPH,
"qt.scenegraph.time.glyph")
65Q_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERER,
"qt.scenegraph.time.renderer")
68Q_LOGGING_CATEGORY(lcQsgLeak,
"qt.scenegraph.leaks")
72DEFINE_BOOL_CONFIG_OPTION(useElapsedTimerBasedAnimationDriver, QSG_USE_SIMPLE_ANIMATION_DRIVER);
78 use = !qEnvironmentVariableIsEmpty(
"QSG_FIXED_ANIMATION_STEP") && qgetenv(
"QSG_FIXED_ANIMATION_STEP") !=
"no"
80 qCDebug(QSG_LOG_INFO,
"Using %s",
bool(use) ?
"fixed animation steps" :
"sg animation driver");
91 QScreen *screen = QGuiApplication::primaryScreen();
93 qreal refreshRate = screen->refreshRate();
98 m_vsync = 1000.0f /
float(refreshRate);
130 QScreen *screen = QGuiApplication::primaryScreen();
136 if (qsg_useConsistentTiming())
137 QUnifiedTimer::instance(
true)->setConsistentTiming(
true);
139 if (m_mode == VSyncMode)
140 qCDebug(QSG_LOG_INFO,
"Animation Driver: using vsync: %.2f ms", m_vsync);
142 qCDebug(QSG_LOG_INFO,
"Animation Driver: using walltime");
150 QAnimationDriver::start();
155 return m_mode == VSyncMode
157 : qint64(m_time) + m_wallTime.elapsed();
162 qint64 delta = m_timer.restart();
164 if (m_mode == VSyncMode) {
190 qCDebug(QSG_LOG_INFO,
"animation driver switched to timer mode");
213 qCDebug(QSG_LOG_INFO,
"animation driver switched to vsync mode");
265 qCDebug(QSG_LOG_INFO,
"Animation Driver: using QElapsedTimer, thread %p %s",
266 QThread::currentThread(),
267 QThread::currentThread() == qGuiApp->thread() ?
"(gui/main thread)" :
"(render thread)");
273 QAnimationDriver::start();
278 return m_wallTime.elapsed();
292 QElapsedTimer m_wallTime;
295QSGRenderContext::FontKey::FontKey(
const QRawFont &font,
int quality)
297 QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine;
299 faceId = fe->faceId();
300 style = font.style();
301 weight = font.weight();
302 renderTypeQuality = quality;
303 if (faceId.filename.isEmpty()) {
304 familyName = font.familyName();
305 styleName = font.styleName();
310
311
312
313
314
315
316
317
318
320QSGContext::QSGContext(QObject *parent) :
325QSGContext::~QSGContext()
329void QSGContext::renderContextInitialized(QSGRenderContext *)
333void QSGContext::renderContextInvalidated(QSGRenderContext *)
339
340
341QSGInternalRectangleNode *QSGContext::createInternalRectangleNode(
const QRectF &rect,
const QColor &c)
343 QSGInternalRectangleNode *node = createInternalRectangleNode();
350QSGInternalTextNode *QSGContext::createInternalTextNode(QSGRenderContext *renderContext)
352 return new QSGInternalTextNode(renderContext);
355QSGTextNode *QSGContext::createTextNode(QSGRenderContext *renderContext)
357 return createInternalTextNode(renderContext);
361
362
363
364
365QSGGuiThreadShaderEffectManager *QSGContext::createGuiThreadShaderEffectManager()
371
372
373
374
375QSGShaderEffectNode *QSGContext::createShaderEffectNode(QSGRenderContext *)
381
382
383QAnimationDriver *QSGContext::createAnimationDriver(QObject *parent)
385 if (useElapsedTimerBasedAnimationDriver())
386 return new QSGElapsedTimerAnimationDriver(parent);
388 return new QSGDefaultAnimationDriver(parent);
392
393
394
395float QSGContext::vsyncIntervalForAnimationDriver(QAnimationDriver *driver)
397 return static_cast<QSGAnimationDriver *>(driver)->vsyncInterval();
401
402
403bool QSGContext::isVSyncDependent(QAnimationDriver *driver)
405 return static_cast<QSGAnimationDriver *>(driver)->isVSyncDependent();
408QSize QSGContext::minimumFBOSize()
const
414
415
416
417
418
419
420
421
422
423
424
425
426
427QSGRendererInterface *QSGContext::rendererInterface(QSGRenderContext *renderContext)
429 Q_UNUSED(renderContext);
430 qWarning(
"QSGRendererInterface not implemented");
435
436
437
438
439QSGRenderContext::QSGRenderContext(QSGContext *context)
444QSGRenderContext::~QSGRenderContext()
448void QSGRenderContext::initialize(
const InitParams *params)
453void QSGRenderContext::invalidate()
457void QSGRenderContext::prepareSync(qreal devicePixelRatio,
458 QRhiCommandBuffer *cb,
459 const QQuickGraphicsConfiguration &config)
461 Q_UNUSED(devicePixelRatio);
466void QSGRenderContext::beginNextFrame(QSGRenderer *renderer,
const QSGRenderTarget &renderTarget,
467 RenderPassCallback mainPassRecordingStart,
468 RenderPassCallback mainPassRecordingEnd,
469 void *callbackUserData)
471 renderer->setRenderTarget(renderTarget);
472 Q_UNUSED(mainPassRecordingStart);
473 Q_UNUSED(mainPassRecordingEnd);
474 Q_UNUSED(callbackUserData);
477void QSGRenderContext::endNextFrame(QSGRenderer *renderer)
482void QSGRenderContext::endSync()
484 qDeleteAll(m_texturesToDelete);
485 m_texturesToDelete.clear();
489
490
491void QSGRenderContext::preprocess()
496
497
498
499QSGCurveGlyphAtlas *QSGRenderContext::curveGlyphAtlas(
const QRawFont &font)
506
507
508QSGDistanceFieldGlyphCache *QSGRenderContext::distanceFieldGlyphCache(
const QRawFont &,
int)
513void QSGRenderContext::invalidateGlyphCaches()
518void QSGRenderContext::flushGlyphCaches()
523void QSGRenderContext::registerFontengineForCleanup(QFontEngine *engine)
526 m_fontEnginesToClean[engine]++;
529void QSGRenderContext::unregisterFontengineForCleanup(QFontEngine *engine)
531 m_fontEnginesToClean[engine]--;
532 Q_ASSERT(m_fontEnginesToClean.value(engine) >= 0);
535QRhi *QSGRenderContext::rhi()
const
541
542
543
544
545
547QSGTexture *QSGRenderContext::textureForFactory(QQuickTextureFactory *factory, QQuickWindow *window)
553 QSGTexture *texture = m_textures.value(factory);
557 texture = factory->createTexture(window);
560 m_textures.insert(factory, texture);
563 connect(factory, SIGNAL(destroyed(QObject*)),
this, SLOT(textureFactoryDestroyed(QObject*)), Qt::DirectConnection);
568void QSGRenderContext::textureFactoryDestroyed(QObject *o)
571 m_texturesToDelete << m_textures.take(o);
576
577
578
579
580
581
582
583
584QSGTexture *QSGRenderContext::compressedTextureForFactory(
const QSGCompressedTextureFactory *)
const
591#include "qsgcontext.moc"
592#include "moc_qsgcontext_p.cpp"
QSGAnimationDriver(QObject *parent)
float vsyncInterval() const
virtual bool isVSyncDependent() const =0
qint64 elapsed() const override
Returns the number of milliseconds since the animations was started.
void advance() override
Advances the animation.
QSGDefaultAnimationDriver(QObject *parent)
bool isVSyncDependent() const override
QSGElapsedTimerAnimationDriver(QObject *parent)
bool isVSyncDependent() const override
qint64 elapsed() const override
Returns the number of milliseconds since the animations was started.
void advance() override
Advances the animation.
Combined button and popup list for selecting options.
bool qsg_useConsistentTiming()