5#include <QtQuick/private/qsgcontext_p.h>
6#include <QtQuick/private/qsgtexture_p.h>
7#include <QtQuick/private/qsgrenderer_p.h>
8#include <QtQuick/private/qquickpixmap_p.h>
9#include <QtQuick/private/qsgadaptationlayer_p.h>
10#include <QtQuick/private/qsginternaltextnode_p.h>
12#include <QGuiApplication>
14#include <QQuickWindow>
16#include <private/qqmlglobal_p.h>
18#include <QtQuick/private/qsgtexture_p.h>
19#include <QtGui/private/qguiapplication_p.h>
20#include <QtCore/private/qabstractanimation_p.h>
22#include <private/qobject_p.h>
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
46Q_LOGGING_CATEGORY(QSG_LOG_INFO,
"qt.scenegraph.general")
50Q_LOGGING_CATEGORY(QSG_LOG_RENDERLOOP,
"qt.scenegraph.renderloop")
54Q_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION,
"qt.scenegraph.time.compilation")
57Q_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP,
"qt.scenegraph.time.renderloop")
60Q_LOGGING_CATEGORY(QSG_LOG_TIME_TEXTURE,
"qt.scenegraph.time.texture")
63Q_LOGGING_CATEGORY(QSG_LOG_TIME_GLYPH,
"qt.scenegraph.time.glyph")
66Q_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERER,
"qt.scenegraph.time.renderer")
69Q_LOGGING_CATEGORY(lcQsgLeak,
"qt.scenegraph.leaks")
73DEFINE_BOOL_CONFIG_OPTION(useElapsedTimerBasedAnimationDriver, QSG_USE_SIMPLE_ANIMATION_DRIVER);
79 use = !qEnvironmentVariableIsEmpty(
"QSG_FIXED_ANIMATION_STEP") && qgetenv(
"QSG_FIXED_ANIMATION_STEP") !=
"no"
81 qCDebug(QSG_LOG_INFO,
"Using %s",
bool(use) ?
"fixed animation steps" :
"sg animation driver");
92 QScreen *screen = QGuiApplication::primaryScreen();
94 qreal refreshRate = screen->refreshRate();
99 m_vsync = 1000.0f /
float(refreshRate);
131 QScreen *screen = QGuiApplication::primaryScreen();
137 if (qsg_useConsistentTiming())
138 QUnifiedTimer::instance(
true)->setConsistentTiming(
true);
140 if (m_mode == VSyncMode)
141 qCDebug(QSG_LOG_INFO,
"Animation Driver: using vsync: %.2f ms", m_vsync);
143 qCDebug(QSG_LOG_INFO,
"Animation Driver: using walltime");
151 QAnimationDriver::start();
156 return m_mode == VSyncMode
158 : qint64(m_time) + m_wallTime.elapsed();
163 qint64 delta = m_timer.restart();
165 if (m_mode == VSyncMode) {
183 if (delta > m_vsync * 1.25f) {
184 m_lag += (delta / m_vsync);
191 qCDebug(QSG_LOG_INFO,
"animation driver switched to timer mode");
200 if (delta < 1.25f * m_vsync) {
214 qCDebug(QSG_LOG_INFO,
"animation driver switched to vsync mode");
266 qCDebug(QSG_LOG_INFO,
"Animation Driver: using QElapsedTimer, thread %p %s",
267 QThread::currentThread(),
268 QThread::currentThread() == qGuiApp->thread() ?
"(gui/main thread)" :
"(render thread)");
274 QAnimationDriver::start();
279 return m_wallTime.elapsed();
293 QElapsedTimer m_wallTime;
296QSGRenderContext::FontKey::FontKey(
const QRawFont &font,
int quality)
298 QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine;
300 faceId = fe->faceId();
301 style = font.style();
302 weight = font.weight();
303 renderTypeQuality = quality;
304 if (faceId.filename.isEmpty()) {
305 familyName = font.familyName();
306 styleName = font.styleName();
311
312
313
314
315
316
317
318
319
321QSGContext::QSGContext(QObject *parent) :
326QSGContext::~QSGContext()
330void QSGContext::renderContextInitialized(QSGRenderContext *)
334void QSGContext::renderContextInvalidated(QSGRenderContext *)
340
341
342QSGInternalRectangleNode *QSGContext::createInternalRectangleNode(
const QRectF &rect,
const QColor &c)
344 QSGInternalRectangleNode *node = createInternalRectangleNode();
351QSGInternalTextNode *QSGContext::createInternalTextNode(QSGRenderContext *renderContext)
353 return new QSGInternalTextNode(renderContext);
356QSGTextNode *QSGContext::createTextNode(QSGRenderContext *renderContext)
358 return createInternalTextNode(renderContext);
362
363
364
365
366QSGGuiThreadShaderEffectManager *QSGContext::createGuiThreadShaderEffectManager()
372
373
374
375
376QSGShaderEffectNode *QSGContext::createShaderEffectNode(QSGRenderContext *)
382
383
384QAnimationDriver *QSGContext::createAnimationDriver(QObject *parent)
386 if (useElapsedTimerBasedAnimationDriver())
387 return new QSGElapsedTimerAnimationDriver(parent);
389 return new QSGDefaultAnimationDriver(parent);
393
394
395
396float QSGContext::vsyncIntervalForAnimationDriver(QAnimationDriver *driver)
398 return static_cast<QSGAnimationDriver *>(driver)->vsyncInterval();
402
403
404bool QSGContext::isVSyncDependent(QAnimationDriver *driver)
406 return static_cast<QSGAnimationDriver *>(driver)->isVSyncDependent();
409QSize QSGContext::minimumFBOSize()
const
415
416
417
418
419
420
421
422
423
424
425
426
427
428QSGRendererInterface *QSGContext::rendererInterface(QSGRenderContext *renderContext)
430 Q_UNUSED(renderContext);
431 qWarning(
"QSGRendererInterface not implemented");
436
437
438
439
440QSGRenderContext::QSGRenderContext(QSGContext *context)
445QSGRenderContext::~QSGRenderContext()
449void QSGRenderContext::initialize(
const InitParams *params)
454void QSGRenderContext::invalidate()
458void QSGRenderContext::prepareSync(qreal devicePixelRatio,
459 QRhiCommandBuffer *cb,
460 const QQuickGraphicsConfiguration &config)
462 Q_UNUSED(devicePixelRatio);
467void QSGRenderContext::beginNextFrame(QSGRenderer *renderer,
const QSGRenderTarget &renderTarget,
468 RenderPassCallback mainPassRecordingStart,
469 RenderPassCallback mainPassRecordingEnd,
470 void *callbackUserData)
472 renderer->setRenderTarget(renderTarget);
473 Q_UNUSED(mainPassRecordingStart);
474 Q_UNUSED(mainPassRecordingEnd);
475 Q_UNUSED(callbackUserData);
478void QSGRenderContext::endNextFrame(QSGRenderer *renderer)
483void QSGRenderContext::endSync()
485 qDeleteAll(m_texturesToDelete);
486 m_texturesToDelete.clear();
490
491
492void QSGRenderContext::preprocess()
497
498
499
500QSGCurveGlyphAtlas *QSGRenderContext::curveGlyphAtlas(
const QRawFont &font)
507
508
509QSGDistanceFieldGlyphCache *QSGRenderContext::distanceFieldGlyphCache(
const QRawFont &,
int)
514void QSGRenderContext::invalidateGlyphCaches()
519void QSGRenderContext::flushGlyphCaches()
524void QSGRenderContext::registerFontengineForCleanup(QFontEngine *engine)
527 m_fontEnginesToClean[engine]++;
530void QSGRenderContext::unregisterFontengineForCleanup(QFontEngine *engine)
532 m_fontEnginesToClean[engine]--;
533 Q_ASSERT(m_fontEnginesToClean.value(engine) >= 0);
536QRhi *QSGRenderContext::rhi()
const
542
543
544
545
546
548QSGTexture *QSGRenderContext::textureForFactory(QQuickTextureFactory *factory, QQuickWindow *window)
554 QSGTexture *texture = m_textures.value(factory);
558 texture = factory->createTexture(window);
561 m_textures.insert(factory, texture);
564 connect(factory, SIGNAL(destroyed(QObject*)),
this, SLOT(textureFactoryDestroyed(QObject*)), Qt::DirectConnection);
569void QSGRenderContext::textureFactoryDestroyed(QObject *o)
572 m_texturesToDelete << m_textures.take(o);
577
578
579
580
581
582
583
584
585QSGTexture *QSGRenderContext::compressedTextureForFactory(
const QSGCompressedTextureFactory *)
const
592#include "qsgcontext.moc"
593#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()