more safeguards

This commit is contained in:
HifiExperiments 2021-01-20 21:25:30 -08:00
parent 3335c040e5
commit 2667af3682
17 changed files with 94 additions and 73 deletions

View file

@ -57,15 +57,15 @@ void AboutUtil::openUrl(const QString& url) const {
auto tablet = DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system"); auto tablet = DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system");
auto hmd = DependencyManager::get<HMDScriptingInterface>(); auto hmd = DependencyManager::get<HMDScriptingInterface>();
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUI = DependencyManager::get<OffscreenUi>();
if (tablet->getToolbarMode()) { if (tablet->getToolbarMode() && offscreenUI) {
offscreenUi->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) { offscreenUI->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) {
newObject->setProperty("url", url); newObject->setProperty("url", url);
}); });
} else { } else {
if (!hmd->getShouldShowTablet() && !qApp->isHMDMode()) { if (!hmd->getShouldShowTablet() && !qApp->isHMDMode() && offscreenUI) {
offscreenUi->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) { offscreenUI->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) {
newObject->setProperty("url", url); newObject->setProperty("url", url);
}); });
} else { } else {

View file

@ -61,7 +61,6 @@ void Bookmarks::deleteBookmark(const QString& bookmarkName) {
void Bookmarks::addBookmarkToFile(const QString& bookmarkName, const QVariant& bookmark) { void Bookmarks::addBookmarkToFile(const QString& bookmarkName, const QVariant& bookmark) {
Menu* menubar = Menu::getInstance(); Menu* menubar = Menu::getInstance();
if (contains(bookmarkName)) { if (contains(bookmarkName)) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
ModalDialogListener* dlg = OffscreenUi::asyncWarning("Duplicate Bookmark", ModalDialogListener* dlg = OffscreenUi::asyncWarning("Duplicate Bookmark",
"The bookmark name you entered already exists in your list.", "The bookmark name you entered already exists in your list.",
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

View file

@ -58,7 +58,9 @@ bool AvatarPackager::open() {
if (tablet->getToolbarMode()) { if (tablet->getToolbarMode()) {
static const QUrl url{ "hifi/AvatarPackagerWindow.qml" }; static const QUrl url{ "hifi/AvatarPackagerWindow.qml" };
DependencyManager::get<OffscreenUi>()->show(url, "AvatarPackager", packageModelDialogCreated); if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {
offscreenUI->show(url, "AvatarPackager", packageModelDialogCreated);
}
return true; return true;
} }

View file

@ -77,6 +77,11 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping,
"Specifying a new folder name will automatically create that folder for you."; "Specifying a new folder name will automatically create that folder for you.";
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUi = DependencyManager::get<OffscreenUi>();
if (!offscreenUi) {
completedCallback.call({ -1 });
return;
}
auto result = offscreenUi->inputDialog(OffscreenUi::ICON_INFORMATION, "Specify Asset Path", auto result = offscreenUi->inputDialog(OffscreenUi::ICON_INFORMATION, "Specify Asset Path",
dropEvent ? dropHelpText : helpText, mapping); dropEvent ? dropHelpText : helpText, mapping);

View file

@ -99,11 +99,16 @@ void DesktopScriptingInterface::setHUDAlpha(float alpha) {
} }
void DesktopScriptingInterface::show(const QString& path, const QString& title) { void DesktopScriptingInterface::show(const QString& path, const QString& title) {
auto offscreenUI = DependencyManager::get<OffscreenUi>();
if (!offscreenUI) {
return;
}
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection, Q_ARG(QString, path), Q_ARG(QString, title)); QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection, Q_ARG(QString, path), Q_ARG(QString, title));
return; return;
} }
DependencyManager::get<OffscreenUi>()->show(path, title); offscreenUI->show(path, title);
} }
InteractiveWindowPointer DesktopScriptingInterface::createWindow(const QString& sourceUrl, const QVariantMap& properties) { InteractiveWindowPointer DesktopScriptingInterface::createWindow(const QString& sourceUrl, const QVariantMap& properties) {

View file

@ -96,8 +96,9 @@ bool HMDScriptingInterface::shouldShowHandControllers() const {
void HMDScriptingInterface::activateHMDHandMouse() { void HMDScriptingInterface::activateHMDHandMouse() {
QWriteLocker lock(&_hmdHandMouseLock); QWriteLocker lock(&_hmdHandMouseLock);
auto offscreenUi = DependencyManager::get<OffscreenUi>(); if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {
offscreenUi->getDesktop()->setProperty("hmdHandMouseActive", true); offscreenUI->getDesktop()->setProperty("hmdHandMouseActive", true);
}
_hmdHandMouseCount++; _hmdHandMouseCount++;
} }
@ -105,8 +106,9 @@ void HMDScriptingInterface::deactivateHMDHandMouse() {
QWriteLocker lock(&_hmdHandMouseLock); QWriteLocker lock(&_hmdHandMouseLock);
_hmdHandMouseCount = std::max(_hmdHandMouseCount - 1, 0); _hmdHandMouseCount = std::max(_hmdHandMouseCount - 1, 0);
if (_hmdHandMouseCount == 0) { if (_hmdHandMouseCount == 0) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {
offscreenUi->getDesktop()->setProperty("hmdHandMouseActive", false); offscreenUI->getDesktop()->setProperty("hmdHandMouseActive", false);
}
} }
} }

View file

@ -100,10 +100,10 @@ void ApplicationOverlay::renderQmlUi(RenderArgs* renderArgs) {
// threads, we need to use a sync object to deteremine when // threads, we need to use a sync object to deteremine when
// the current UI texture is no longer being read from, and only // the current UI texture is no longer being read from, and only
// then release it back to the UI for re-use // then release it back to the UI for re-use
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUI = DependencyManager::get<OffscreenUi>();
OffscreenQmlSurface::TextureAndFence newTextureAndFence; OffscreenQmlSurface::TextureAndFence newTextureAndFence;
bool newTextureAvailable = offscreenUi->fetchTexture(newTextureAndFence); bool newTextureAvailable = offscreenUI ? offscreenUI->fetchTexture(newTextureAndFence) : false;
if (newTextureAvailable) { if (newTextureAvailable) {
_uiTexture->setExternalTexture(newTextureAndFence.first, newTextureAndFence.second); _uiTexture->setExternalTexture(newTextureAndFence.first, newTextureAndFence.second);
} }

View file

@ -362,10 +362,11 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
object->setObjectName("InteractiveWindow"); object->setObjectName("InteractiveWindow");
object->setProperty(SOURCE_PROPERTY, sourceURL); object->setProperty(SOURCE_PROPERTY, sourceURL);
}; };
auto offscreenUi = DependencyManager::get<OffscreenUi>();
// Build the event bridge and wrapper on the main thread if (auto offscreenUi = DependencyManager::get<OffscreenUi>()) {
offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, objectInitLambda, contextInitLambda); // Build the event bridge and wrapper on the main thread
offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, objectInitLambda, contextInitLambda);
}
} }
} }

View file

@ -1212,8 +1212,8 @@ float Overlays::width() {
return result; return result;
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUI = DependencyManager::get<OffscreenUi>();
return offscreenUi->getWindow()->size().width(); return offscreenUI ? offscreenUI->getWindow()->size().width() : -1.0f;
} }
float Overlays::height() { float Overlays::height() {
@ -1224,8 +1224,8 @@ float Overlays::height() {
return result; return result;
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUI = DependencyManager::get<OffscreenUi>();
return offscreenUi->getWindow()->size().height(); return offscreenUI ? offscreenUI->getWindow()->size().height() : -1.0f;
} }
void Overlays::mousePressOnPointerEvent(const QUuid& id, const PointerEvent& event) { void Overlays::mousePressOnPointerEvent(const QUuid& id, const PointerEvent& event) {

View file

@ -24,13 +24,17 @@ QmlOverlay::QmlOverlay(const QUrl& url, const QmlOverlay* overlay)
} }
void QmlOverlay::buildQmlElement(const QUrl& url) { void QmlOverlay::buildQmlElement(const QUrl& url) {
auto offscreenUI = DependencyManager::get<OffscreenUi>();
if (!offscreenUI) {
return;
}
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "buildQmlElement", Q_ARG(QUrl, url)); QMetaObject::invokeMethod(this, "buildQmlElement", Q_ARG(QUrl, url));
return; return;
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); offscreenUI->load(url, [=](QQmlContext* context, QObject* object) {
offscreenUi->load(url, [=](QQmlContext* context, QObject* object) {
_qmlElement = dynamic_cast<QQuickItem*>(object); _qmlElement = dynamic_cast<QQuickItem*>(object);
connect(_qmlElement, &QObject::destroyed, this, &QmlOverlay::qmlElementDestroyed); connect(_qmlElement, &QObject::destroyed, this, &QmlOverlay::qmlElementDestroyed);
}); });

View file

@ -26,14 +26,15 @@ static void quickViewDeleter(QQuickView* quickView) {
} }
DockWidget::DockWidget(const QString& title, QWidget* parent) : QDockWidget(title, parent) { DockWidget::DockWidget(const QString& title, QWidget* parent) : QDockWidget(title, parent) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {
auto qmlEngine = offscreenUi->getSurfaceContext()->engine(); auto qmlEngine = offscreenUI->getSurfaceContext()->engine();
_quickView = std::shared_ptr<QQuickView>(new QQuickView(qmlEngine, nullptr), quickViewDeleter); _quickView = std::shared_ptr<QQuickView>(new QQuickView(qmlEngine, nullptr), quickViewDeleter);
_quickView->setFormat(getDefaultOpenGLSurfaceFormat()); _quickView->setFormat(getDefaultOpenGLSurfaceFormat());
QWidget* widget = QWidget::createWindowContainer(_quickView.get()); QWidget* widget = QWidget::createWindowContainer(_quickView.get());
setWidget(widget); setWidget(widget);
QWidget* headerWidget = new QWidget(); QWidget* headerWidget = new QWidget();
setTitleBarWidget(headerWidget); setTitleBarWidget(headerWidget);
}
} }
void DockWidget::setSource(const QUrl& url) { void DockWidget::setSource(const QUrl& url) {

View file

@ -65,17 +65,18 @@ void InfoView::show(const QString& path, bool firstOrChangedOnly, QString urlQue
} }
infoVersion.set(version); infoVersion.set(version);
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>(); if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {
QString infoViewName(NAME + "_" + path); QString infoViewName(NAME + "_" + path);
offscreenUi->show(QML, NAME + "_" + path, [=](QQmlContext* context, QObject* newObject){ offscreenUI->show(QML, NAME + "_" + path, [=](QQmlContext* context, QObject* newObject){
QQuickItem* item = dynamic_cast<QQuickItem*>(newObject); QQuickItem* item = dynamic_cast<QQuickItem*>(newObject);
item->setWidth(1024); item->setWidth(1024);
item->setHeight(720); item->setHeight(720);
InfoView* newInfoView = newObject->findChild<InfoView*>(); InfoView* newInfoView = newObject->findChild<InfoView*>();
Q_ASSERT(newInfoView); Q_ASSERT(newInfoView);
newInfoView->parent()->setObjectName(infoViewName); newInfoView->parent()->setObjectName(infoViewName);
newInfoView->setUrl(url); newInfoView->setUrl(url);
}); });
}
} }
QUrl InfoView::url() { QUrl InfoView::url() {

View file

@ -53,25 +53,30 @@ private:
} \ } \
\ \
void x::show(std::function<void(QQmlContext*, QObject*)> f) { \ void x::show(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ auto offscreenUI = DependencyManager::get<OffscreenUi>(); \
if (!registered) { \ if (!registered) { \
x::registerType(); \ x::registerType(); \
} \ } \
offscreenUi->show(QML, NAME, f); \ if (offscreenUI) { \
offscreenUI->show(QML, NAME, f); \
} \
} \ } \
\ \
void x::hide() { \ void x::hide() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->hide(NAME); \ offscreenUI->hide(NAME); \
} \
} \ } \
\ \
void x::toggle(std::function<void(QQmlContext*, QObject*)> f) { \ void x::toggle(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->toggle(QML, NAME, f); \ offscreenUI->toggle(QML, NAME, f); \
} \
} \ } \
void x::load(std::function<void(QQmlContext*, QObject*)> f) { \ void x::load(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->load(QML, f); \ offscreenUI->load(QML, f); \
} \
} }
#define HIFI_QML_DEF_LAMBDA(x, f) \ #define HIFI_QML_DEF_LAMBDA(x, f) \
@ -82,21 +87,25 @@ private:
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \ } \
void x::show() { \ void x::show() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->show(QML, NAME, f); \ offscreenUI->show(QML, NAME, f); \
} \
} \ } \
void x::hide() { \ void x::hide() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->hide(NAME); \ offscreenUI->hide(NAME); \
} \
} \ } \
\ \
void x::toggle() { \ void x::toggle() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->toggle(QML, NAME, f); \ offscreenUI->toggle(QML, NAME, f); \
} \
} \ } \
void x::load() { \ void x::load() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \ if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) { \
offscreenUi->load(QML, f); \ offscreenUI->load(QML, f); \
} \
} }
#endif #endif

View file

@ -14,9 +14,6 @@
#include <shared/QtHelpers.h> #include <shared/QtHelpers.h>
#include "OffscreenUi.h"
std::mutex QmlFragmentClass::_mutex; std::mutex QmlFragmentClass::_mutex;
std::map<QString, QScriptValue> QmlFragmentClass::_fragments; std::map<QString, QScriptValue> QmlFragmentClass::_fragments;
@ -40,7 +37,6 @@ QScriptValue QmlFragmentClass::internal_constructor(QScriptContext* context, QSc
} }
auto properties = parseArguments(context); auto properties = parseArguments(context);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QmlFragmentClass* retVal = new QmlFragmentClass(restricted, qml.toString()); QmlFragmentClass* retVal = new QmlFragmentClass(restricted, qml.toString());
Q_ASSERT(retVal); Q_ASSERT(retVal);
if (QThread::currentThread() != qApp->thread()) { if (QThread::currentThread() != qApp->thread()) {

View file

@ -14,7 +14,6 @@
#include <QtScript/QScriptEngine> #include <QtScript/QScriptEngine>
#include <shared/QtHelpers.h> #include <shared/QtHelpers.h>
#include "OffscreenUi.h"
static const char* const URL_PROPERTY = "source"; static const char* const URL_PROPERTY = "source";
static const char* const SCRIPT_PROPERTY = "scriptUrl"; static const char* const SCRIPT_PROPERTY = "scriptUrl";
@ -22,7 +21,6 @@ static const char* const SCRIPT_PROPERTY = "scriptUrl";
// Method called by Qt scripts to create a new web window in the overlay // Method called by Qt scripts to create a new web window in the overlay
QScriptValue QmlWebWindowClass::internal_constructor(QScriptContext* context, QScriptEngine* engine, bool restricted) { QScriptValue QmlWebWindowClass::internal_constructor(QScriptContext* context, QScriptEngine* engine, bool restricted) {
auto properties = parseArguments(context); auto properties = parseArguments(context);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QmlWebWindowClass* retVal = new QmlWebWindowClass(restricted); QmlWebWindowClass* retVal = new QmlWebWindowClass(restricted);
Q_ASSERT(retVal); Q_ASSERT(retVal);
if (QThread::currentThread() != qApp->thread()) { if (QThread::currentThread() != qApp->thread()) {

View file

@ -72,7 +72,6 @@ QVariantMap QmlWindowClass::parseArguments(QScriptContext* context) {
// Method called by Qt scripts to create a new web window in the overlay // Method called by Qt scripts to create a new web window in the overlay
QScriptValue QmlWindowClass::internal_constructor(QScriptContext* context, QScriptEngine* engine, bool restricted) { QScriptValue QmlWindowClass::internal_constructor(QScriptContext* context, QScriptEngine* engine, bool restricted) {
auto properties = parseArguments(context); auto properties = parseArguments(context);
auto offscreenUi = DependencyManager::get<OffscreenUi>();
QmlWindowClass* retVal = new QmlWindowClass(restricted); QmlWindowClass* retVal = new QmlWindowClass(restricted);
Q_ASSERT(retVal); Q_ASSERT(retVal);
if (QThread::currentThread() != qApp->thread()) { if (QThread::currentThread() != qApp->thread()) {
@ -349,7 +348,6 @@ void QmlWindowClass::raise() {
return; return;
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>();
if (_qmlWindow) { if (_qmlWindow) {
QMetaObject::invokeMethod(asQuickItem(), "raise", Qt::DirectConnection); QMetaObject::invokeMethod(asQuickItem(), "raise", Qt::DirectConnection);
} }

View file

@ -203,14 +203,14 @@ void updateFromOpenVrKeyboardInput() {
} }
void finishOpenVrKeyboardInput() { void finishOpenVrKeyboardInput() {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); auto offscreenUI = DependencyManager::get<OffscreenUi>();
updateFromOpenVrKeyboardInput(); updateFromOpenVrKeyboardInput();
// Simulate an enter press on the top level window to trigger the action // Simulate an enter press on the top level window to trigger the action
if (0 == (_currentHints & Qt::ImhMultiLine)) { if (0 == (_currentHints & Qt::ImhMultiLine) && offscreenUI) {
auto keyPress = QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::KeyboardModifiers(), QString("\n")); auto keyPress = QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::KeyboardModifiers(), QString("\n"));
auto keyRelease = QKeyEvent(QEvent::KeyRelease, Qt::Key_Return, Qt::KeyboardModifiers()); auto keyRelease = QKeyEvent(QEvent::KeyRelease, Qt::Key_Return, Qt::KeyboardModifiers());
qApp->sendEvent(offscreenUi->getWindow(), &keyPress); qApp->sendEvent(offscreenUI->getWindow(), &keyPress);
qApp->sendEvent(offscreenUi->getWindow(), &keyRelease); qApp->sendEvent(offscreenUI->getWindow(), &keyRelease);
} }
} }
@ -221,10 +221,8 @@ void enableOpenVrKeyboard(PluginContainer* container) {
if (disableSteamVrKeyboard) { if (disableSteamVrKeyboard) {
return; return;
} }
auto offscreenUi = DependencyManager::get<OffscreenUi>();
_overlay = vr::VROverlay(); _overlay = vr::VROverlay();
auto menu = container->getPrimaryMenu(); auto menu = container->getPrimaryMenu();
auto action = menu->getActionForOption(MenuOption::Overlays); auto action = menu->getActionForOption(MenuOption::Overlays);
@ -282,7 +280,9 @@ void handleOpenVrEvents() {
case vr::VREvent_KeyboardClosed: case vr::VREvent_KeyboardClosed:
_keyboardFocusObject = nullptr; _keyboardFocusObject = nullptr;
_keyboardShown = false; _keyboardShown = false;
DependencyManager::get<OffscreenUi>()->unfocusWindows(); if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {
offscreenUI->unfocusWindows();
}
break; break;
default: default: