From 4a662c21e669e964f9c3b835a91a38c9decf4ad4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 4 Oct 2013 02:37:53 +0200 Subject: [new compiler] Preliminary support for QQmlIncubator Just enough to run some unit tests that use QQuickLoader, components are created instantly. Change-Id: I1c827aa946d3e2a60ccc220bb79572aca2ed8c96 Reviewed-by: Lars Knoll --- src/qml/qml/qqmlcomponent.cpp | 6 +++++- src/qml/qml/qqmlincubator.cpp | 17 +++++++++++++++-- src/qml/qml/qqmlincubator_p.h | 5 +++++ src/qml/qml/qqmlobjectcreator.cpp | 8 +++++++- src/qml/qml/qqmlobjectcreator_p.h | 3 ++- src/qml/types/qqmldelegatemodel.cpp | 15 ++++++++++----- 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 21bcd3569c..5813415347 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1056,7 +1056,11 @@ void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, p->compiledData = d->cc; p->compiledData->addref(); - p->vme.init(contextData, d->cc, d->start, d->creationContext); + if (enginePriv->useNewCompiler) { + p->creator.reset(new QmlObjectCreator(contextData, d->cc)); + p->subComponentToCreate = d->start; + } else + p->vme.init(contextData, d->cc, d->start, d->creationContext); enginePriv->incubate(incubator, forContextData); } diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp index ade4634c2d..52bf1d8b3e 100644 --- a/src/qml/qml/qqmlincubator.cpp +++ b/src/qml/qml/qqmlincubator.cpp @@ -46,6 +46,7 @@ #include "qqmlcompiler_p.h" #include "qqmlexpression_p.h" #include "qqmlmemoryprofiler_p.h" +#include "qqmlobjectcreator_p.h" // XXX TODO // - check that the Component.onCompleted behavior is the same as 4.8 in the synchronous and @@ -292,7 +293,14 @@ void QQmlIncubatorPrivate::incubate(QQmlVME::Interrupt &i) if (progress == QQmlIncubatorPrivate::Execute) { enginePriv->referenceScarceResources(); - QObject *tresult = vme.execute(&errors, i); + QObject *tresult = 0; + if (enginePriv->useNewCompiler) { + tresult = creator->create(subComponentToCreate); + if (!tresult) + errors = creator->errors; + } else { + tresult = vme.execute(&errors, i); + } enginePriv->dereferenceScarceResources(); if (watcher.hasRecursed()) @@ -335,7 +343,11 @@ void QQmlIncubatorPrivate::incubate(QQmlVME::Interrupt &i) if (watcher.hasRecursed()) return; - QQmlContextData *ctxt = vme.complete(i); + QQmlContextData *ctxt = 0; + if (enginePriv->useNewCompiler) + ctxt = creator->finalize(); + else + ctxt = vme.complete(i); if (ctxt) { rootContext = ctxt; progress = QQmlIncubatorPrivate::Completed; @@ -566,6 +578,7 @@ void QQmlIncubator::clear() d->vme.reset(); d->vmeGuard.clear(); + d->creator.reset(0); Q_ASSERT(d->compiledData == 0); Q_ASSERT(d->waitingOnMe.data() == 0); diff --git a/src/qml/qml/qqmlincubator_p.h b/src/qml/qml/qqmlincubator_p.h index e7246ce3b2..a8b549bd28 100644 --- a/src/qml/qml/qqmlincubator_p.h +++ b/src/qml/qml/qqmlincubator_p.h @@ -88,7 +88,12 @@ public: QPointer result; QQmlGuardedContextData rootContext; QQmlCompiledData *compiledData; + // --- old compiler QQmlVME vme; + // --- new compiler + QScopedPointer creator; + int subComponentToCreate; + // --- QQmlVMEGuard vmeGuard; QExplicitlySharedDataPointer waitingOnMe; diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 7455a486db..822708a73e 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -478,6 +478,7 @@ QmlObjectCreator::QmlObjectCreator(QQmlContextData *parentContext, QQmlCompiledD , propertyCaches(compiledData->propertyCaches) , vmeMetaObjectData(compiledData->datas) , compiledData(compiledData) + , rootContext(0) , _qobject(0) , _qobjectForBindings(0) , _valueTypeProperty(0) @@ -512,6 +513,9 @@ QObject *QmlObjectCreator::create(int subComponentIndex, QObject *parent) context->imports->addref(); context->setParent(parentContext); + if (!rootContext) + rootContext = context; + QVector mapping(objectIndexToId.count()); for (QHash::ConstIterator it = objectIndexToId.constBegin(), end = objectIndexToId.constEnd(); it != end; ++it) { @@ -1312,7 +1316,7 @@ QObject *QmlObjectCreator::createInstance(int index, QObject *parent) return instance; } -void QmlObjectCreator::finalize() +QQmlContextData *QmlObjectCreator::finalize() { { QQmlTrace trace("VME Binding Enable"); @@ -1377,6 +1381,8 @@ void QmlObjectCreator::finalize() #endif } } + + return rootContext; } bool QmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPointer cache, diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index 799329d8de..229a7de198 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -143,7 +143,7 @@ public: QmlObjectCreator(QQmlContextData *contextData, QQmlCompiledData *compiledData); QObject *create(int subComponentIndex = -1, QObject *parent = 0); - void finalize(); + QQmlContextData *finalize(); QQmlComponentAttached *componentAttached; QList finalizeCallbacks; @@ -170,6 +170,7 @@ private: QLinkedList > allCreatedBindings; QLinkedList > allParserStatusCallbacks; QQmlCompiledData *compiledData; + QQmlContextData *rootContext; QObject *_qobject; QObject *_qobjectForBindings; diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 7276c0e5c6..32ebb93279 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1863,11 +1863,16 @@ void QQmlDelegateModelItem::incubateObject( incubatorPriv->compiledData = componentPriv->cc; incubatorPriv->compiledData->addref(); - incubatorPriv->vme.init( - context, - componentPriv->cc, - componentPriv->start, - componentPriv->creationContext); + if (enginePriv->useNewCompiler) { + incubatorPriv->creator.reset(new QmlObjectCreator(context, componentPriv->cc)); + incubatorPriv->subComponentToCreate = componentPriv->start; + } else { + incubatorPriv->vme.init( + context, + componentPriv->cc, + componentPriv->start, + componentPriv->creationContext); + } enginePriv->incubate(*incubationTask, forContext); } -- cgit v1.2.3