int lastFrame = frameTimer.restart();
#endif
- if (d->animationDriver->isRunning())
+ if (d->animationDriver && d->animationDriver->isRunning())
d->animationDriver->advance();
#ifdef FRAME_TIMING
QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Painting);
- if (d->animationDriver->isRunning())
+ if (d->animationDriver && d->animationDriver->isRunning())
update();
} else {
if (isUpdatesEnabled()) {
if (!d->contextFailed) {
if (d->threadedRendering) {
- if (!d->animationDriver) {
- d->animationDriver = d->context->createAnimationDriver(this);
- connect(d->animationDriver, SIGNAL(started()), d->thread, SLOT(animationStarted()), Qt::DirectConnection);
- connect(d->animationDriver, SIGNAL(stopped()), d->thread, SLOT(animationStopped()), Qt::DirectConnection);
+ if (d->vsyncAnimations) {
+ if (!d->animationDriver) {
+ d->animationDriver = d->context->createAnimationDriver(this);
+ connect(d->animationDriver, SIGNAL(started()), d->thread, SLOT(animationStarted()), Qt::DirectConnection);
+ connect(d->animationDriver, SIGNAL(stopped()), d->thread, SLOT(animationStopped()), Qt::DirectConnection);
+ }
+ d->animationDriver->install();
}
- d->animationDriver->install();
d->thread->startRenderThread();
setUpdatesEnabled(true);
} else {
if (!d->context || !d->context->isReady()) {
d->initializeSceneGraph();
- d->animationDriver = d->context->createAnimationDriver(this);
- connect(d->animationDriver, SIGNAL(started()), this, SLOT(update()));
+ if (d->vsyncAnimations) {
+ d->animationDriver = d->context->createAnimationDriver(this);
+ connect(d->animationDriver, SIGNAL(started()), this, SLOT(update()));
+ }
}
- d->animationDriver->install();
+ if (d->animationDriver)
+ d->animationDriver->install();
}
}
}
d->thread->stopRenderThread();
}
- d->animationDriver->uninstall();
+ if (d->animationDriver)
+ d->animationDriver->uninstall();
}
QGLWidget::hideEvent(e);
}
+
+
+/*!
+ Sets weither this canvas should use vsync driven animations.
+
+ This option can only be set on one single QSGCanvas, and that it's
+ vsync signal will then be used to drive all animations in the
+ process.
+
+ This feature is primarily useful for single QSGCanvas, QML-only
+ applications.
+
+ \warning Enabling vsync on multiple QSGCanvas instances has
+ undefined behavior.
+ */
+void QSGCanvas::setVSyncAnimations(bool enabled)
+{
+ Q_D(QSGCanvas);
+ if (isVisible()) {
+ qWarning("QSGCanvas::setVSyncAnimations: Cannot be changed when widget is shown");
+ return;
+ }
+ d->vsyncAnimations = enabled;
+}
+
+
+
+/*!
+ Returns true if this canvas should use vsync driven animations;
+ otherwise returns false.
+ */
+bool QSGCanvas::vsyncAnimations() const
+{
+ Q_D(const QSGCanvas);
+ return d->vsyncAnimations;
+}
+
+
+
void QSGCanvas::focusOutEvent(QFocusEvent *event)
{
Q_D(QSGCanvas);
, threadedRendering(false)
, animationRunning(false)
, renderThreadAwakened(false)
+ , vsyncAnimations(false)
, thread(0)
, animationDriver(0)
{
d->thread->syncAlreadyHappened = false;
- if (d->animationRunning) {
+ if (d->animationRunning && d->animationDriver) {
#ifdef THREAD_DEBUG
qDebug("GUI: Advancing animations...\n");
#endif
// but we don't want to lock an extra time.
wake();
- if (!d->animationRunning && !isExternalUpdatePending) {
+ if (!d->animationRunning && !isExternalUpdatePending && !shouldExit) {
#ifdef THREAD_DEBUG
printf(" RenderThread: nothing to do, going to sleep...\n");
#endif
, scenegraphOnGraphicsview(false)
, clip(false)
, versionDetection(true)
+ , vsync(true)
{
}
bool scenegraphOnGraphicsview;
bool clip;
bool versionDetection;
+ bool vsync;
};
#if defined(QMLSCENE_BUNDLE)
qWarning(" --sg-on-gv [--clip] ....................... Scenegraph on graphicsview (and clip to item)");
#endif
qWarning(" --no-version-detection .................... Do not try to detect the version of the .qml file");
+ qWarning(" --no-vsync-animations ..................... Do not use vsync based animations");
qWarning(" ");
exit(1);
options.versionDetection = false;
else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("-i") && i + 1 < argc)
imports.append(QString::fromLatin1(argv[++i]));
+ else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--no-vsync-animations"))
+ options.vsync = false;
else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--help")
|| QString::fromLatin1(argv[i]).toLower() == QLatin1String("-help")
|| QString::fromLatin1(argv[i]).toLower() == QLatin1String("--h")
if (options.versionDetection)
checkAndAdaptVersion(options.file);
QSGView *qxView = new MyQSGView();
+ qxView->setVSyncAnimations(options.vsync);
engine = qxView->engine();
for (int i = 0; i < imports.size(); ++i)
engine->addImportPath(imports.at(i));