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");
434QSGRenderContext::QSGRenderContext(QSGContext *context)
439QSGRenderContext::~QSGRenderContext()
443void QSGRenderContext::initialize(
const InitParams *params)
448void QSGRenderContext::invalidate()
452void QSGRenderContext::prepareSync(qreal devicePixelRatio,
453 QRhiCommandBuffer *cb,
454 const QQuickGraphicsConfiguration &config)
456 Q_UNUSED(devicePixelRatio);
461void QSGRenderContext::beginNextFrame(QSGRenderer *renderer,
const QSGRenderTarget &renderTarget,
462 RenderPassCallback mainPassRecordingStart,
463 RenderPassCallback mainPassRecordingEnd,
464 void *callbackUserData)
466 renderer->setRenderTarget(renderTarget);
467 Q_UNUSED(mainPassRecordingStart);
468 Q_UNUSED(mainPassRecordingEnd);
469 Q_UNUSED(callbackUserData);
472void QSGRenderContext::endNextFrame(QSGRenderer *renderer)
477void QSGRenderContext::endSync()
479 qDeleteAll(m_texturesToDelete);
480 m_texturesToDelete.clear();
484
485
486void QSGRenderContext::preprocess()
491
492
493
494QSGCurveGlyphAtlas *QSGRenderContext::curveGlyphAtlas(
const QRawFont &font)
501
502
503QSGDistanceFieldGlyphCache *QSGRenderContext::distanceFieldGlyphCache(
const QRawFont &,
int)
508void QSGRenderContext::invalidateGlyphCaches()
513void QSGRenderContext::flushGlyphCaches()
518void QSGRenderContext::registerFontengineForCleanup(QFontEngine *engine)
521 m_fontEnginesToClean[engine]++;
524void QSGRenderContext::unregisterFontengineForCleanup(QFontEngine *engine)
526 m_fontEnginesToClean[engine]--;
527 Q_ASSERT(m_fontEnginesToClean.value(engine) >= 0);
530QRhi *QSGRenderContext::rhi()
const
536
537
538
539
540
542QSGTexture *QSGRenderContext::textureForFactory(QQuickTextureFactory *factory, QQuickWindow *window)
548 QSGTexture *texture = m_textures.value(factory);
552 texture = factory->createTexture(window);
555 m_textures.insert(factory, texture);
558 connect(factory, SIGNAL(destroyed(QObject*)),
this, SLOT(textureFactoryDestroyed(QObject*)), Qt::DirectConnection);
563void QSGRenderContext::textureFactoryDestroyed(QObject *o)
566 m_texturesToDelete << m_textures.take(o);
571
572
573
574
575
576
577
578
579QSGTexture *QSGRenderContext::compressedTextureForFactory(
const QSGCompressedTextureFactory *)
const
586#include "qsgcontext.moc"
587#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.
bool qsg_useConsistentTiming()