From 5a2506e94f6838b42a5394c1c0ea39326c6d8ca1 Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Fri, 3 Aug 2018 17:10:41 +0300 Subject: [PATCH 1/2] FB16831 qml-related warnings in log fix is based on exposing C++ objects to QML before root object is created (as root object might already require C++ objects) --- interface/src/Application.cpp | 9 +++++++++ interface/src/ui/overlays/Web3DOverlay.cpp | 8 +++++--- interface/src/ui/overlays/Web3DOverlay.h | 2 +- libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp | 9 +++++++++ libraries/ui/src/ui/OffscreenQmlSurfaceCache.h | 3 +++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ba7c15ad33..d9a84981a7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2926,6 +2926,15 @@ void Application::initializeUi() { // Pre-create a couple of Web3D overlays to speed up tablet UI auto offscreenSurfaceCache = DependencyManager::get(); + offscreenSurfaceCache->setOnRootContextCreated([&](const QString& rootObject, QQmlContext* surfaceContext) { + if (rootObject == TabletScriptingInterface::QML) { + // in Qt 5.10.0 there is already an "Audio" object in the QML context + // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface" + surfaceContext->setContextProperty("AudioScriptingInterface", DependencyManager::get().data()); + surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED + } + }); + offscreenSurfaceCache->reserve(TabletScriptingInterface::QML, 1); offscreenSurfaceCache->reserve(Web3DOverlay::QML, 2); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 12100e026c..c16b4c016d 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -184,9 +184,11 @@ void Web3DOverlay::buildWebSurface() { _webSurface->getRootItem()->setProperty("scriptURL", _scriptURL); } else { _webSurface = QSharedPointer(new OffscreenQmlSurface(), qmlSurfaceDeleter); + connect(_webSurface.data(), &hifi::qml::OffscreenSurface::rootContextCreated, [this](QQmlContext* surfaceContext) { + setupQmlSurface(_url == TabletScriptingInterface::QML); + }); _webSurface->load(_url); _cachedWebSurface = false; - setupQmlSurface(); } _webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3toVariant(getWorldPosition())); onResizeWebSurface(); @@ -214,7 +216,7 @@ bool Web3DOverlay::isWebContent() const { return false; } -void Web3DOverlay::setupQmlSurface() { +void Web3DOverlay::setupQmlSurface(bool isTablet) { _webSurface->getSurfaceContext()->setContextProperty("Users", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("HMD", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("UserActivityLogger", DependencyManager::get().data()); @@ -225,7 +227,7 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("Entities", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("Snapshot", DependencyManager::get().data()); - if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") { + if (isTablet) { auto tabletScriptingInterface = DependencyManager::get(); auto flags = tabletScriptingInterface->getFlags(); diff --git a/interface/src/ui/overlays/Web3DOverlay.h b/interface/src/ui/overlays/Web3DOverlay.h index 233f4e0d21..4137ed8680 100644 --- a/interface/src/ui/overlays/Web3DOverlay.h +++ b/interface/src/ui/overlays/Web3DOverlay.h @@ -79,7 +79,7 @@ protected: Transform evalRenderTransform() override; private: - void setupQmlSurface(); + void setupQmlSurface(bool isTablet); void rebuildWebSurface(); bool isWebContent() const; diff --git a/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp b/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp index 51fe11fdc7..aad90d0806 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp @@ -46,8 +46,17 @@ void OffscreenQmlSurfaceCache::release(const QString& rootSource, const QSharedP QSharedPointer OffscreenQmlSurfaceCache::buildSurface(const QString& rootSource) { auto surface = QSharedPointer(new OffscreenQmlSurface()); + + QObject::connect(surface.data(), &hifi::qml::OffscreenSurface::rootContextCreated, [this, rootSource](QQmlContext* surfaceContext) { + if (_onRootContextCreated) + _onRootContextCreated(rootSource, surfaceContext); + }); + surface->load(rootSource); surface->resize(QSize(100, 100)); return surface; } +void OffscreenQmlSurfaceCache::setOnRootContextCreated(const std::function& onRootContextCreated) { + _onRootContextCreated = onRootContextCreated; +} \ No newline at end of file diff --git a/libraries/ui/src/ui/OffscreenQmlSurfaceCache.h b/libraries/ui/src/ui/OffscreenQmlSurfaceCache.h index 02382a791b..6dc8b79ca3 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurfaceCache.h +++ b/libraries/ui/src/ui/OffscreenQmlSurfaceCache.h @@ -13,6 +13,7 @@ #include +class QQmlContext; class OffscreenQmlSurface; class OffscreenQmlSurfaceCache : public Dependency { @@ -25,10 +26,12 @@ public: QSharedPointer acquire(const QString& rootSource); void release(const QString& rootSource, const QSharedPointer& surface); void reserve(const QString& rootSource, int count = 1); + void setOnRootContextCreated(const std::function & onRootContextCreated); private: QSharedPointer buildSurface(const QString& rootSource); QHash>> _cache; + std::function _onRootContextCreated; }; #endif From 4478733c27c4810775e6eb8ea9feced8357b450b Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Tue, 14 Aug 2018 21:18:54 +0300 Subject: [PATCH 2/2] fix coding conventions --- libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp b/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp index aad90d0806..6911c34e2a 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurfaceCache.cpp @@ -48,8 +48,9 @@ QSharedPointer OffscreenQmlSurfaceCache::buildSurface(const auto surface = QSharedPointer(new OffscreenQmlSurface()); QObject::connect(surface.data(), &hifi::qml::OffscreenSurface::rootContextCreated, [this, rootSource](QQmlContext* surfaceContext) { - if (_onRootContextCreated) + if (_onRootContextCreated) { _onRootContextCreated(rootSource, surfaceContext); + } }); surface->load(rootSource);