From 5db78ef2e15ea1ee05c817074517c55e6fc396ac Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 15 May 2019 12:55:25 -0700 Subject: [PATCH 1/4] Add scripting to set the refresh rate --- interface/src/Application.cpp | 6 ++- interface/src/RefreshRateManager.cpp | 5 --- interface/src/RefreshRateManager.h | 1 + .../PerformanceScriptingInterface.cpp | 28 ++++++++++++ .../scripting/PerformanceScriptingInterface.h | 43 +++++++++++++++++++ 5 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 interface/src/scripting/PerformanceScriptingInterface.cpp create mode 100644 interface/src/scripting/PerformanceScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d8df9ea62d..7f429d9765 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -193,6 +193,7 @@ #include "scripting/TTSScriptingInterface.h" #include "scripting/KeyboardScriptingInterface.h" #include "scripting/RefreshRateScriptingInterface.h" +#include "scripting/PerformanceScriptingInterface.h" @@ -3280,6 +3281,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("Controller", DependencyManager::get().data()); surfaceContext->setContextProperty("Entities", DependencyManager::get().data()); surfaceContext->setContextProperty("RefreshRate", new RefreshRateScriptingInterface()); + surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface()); _fileDownload = new FileScriptingInterface(engine); surfaceContext->setContextProperty("File", _fileDownload); connect(_fileDownload, &FileScriptingInterface::unzipResult, this, &Application::handleUnzip); @@ -3430,6 +3432,7 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona surfaceContext->setContextProperty("Settings", SettingsScriptingInterface::getInstance()); surfaceContext->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance()); surfaceContext->setContextProperty("RefreshRate", new RefreshRateScriptingInterface()); + surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface()); surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED surfaceContext->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED @@ -7413,7 +7416,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("LODManager", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Keyboard", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("RefreshRate", new RefreshRateScriptingInterface); + scriptEngine->registerGlobalObject("RefreshRate", new RefreshRateScriptingInterface()); + scriptEngine->registerGlobalObject("Performance", new PerformanceScriptingInterface()); scriptEngine->registerGlobalObject("Paths", DependencyManager::get().data()); diff --git a/interface/src/RefreshRateManager.cpp b/interface/src/RefreshRateManager.cpp index 0c5bcd405e..f2033b9491 100644 --- a/interface/src/RefreshRateManager.cpp +++ b/interface/src/RefreshRateManager.cpp @@ -13,13 +13,8 @@ #include "RefreshRateManager.h" #include -#include -#include - -#include - static const int VR_TARGET_RATE = 90; static const std::array REFRESH_RATE_PROFILE_TO_STRING = diff --git a/interface/src/RefreshRateManager.h b/interface/src/RefreshRateManager.h index 6ded8c8869..6316de3bfb 100644 --- a/interface/src/RefreshRateManager.h +++ b/interface/src/RefreshRateManager.h @@ -14,6 +14,7 @@ #include #include +#include #include diff --git a/interface/src/scripting/PerformanceScriptingInterface.cpp b/interface/src/scripting/PerformanceScriptingInterface.cpp new file mode 100644 index 0000000000..53529beeef --- /dev/null +++ b/interface/src/scripting/PerformanceScriptingInterface.cpp @@ -0,0 +1,28 @@ +// +// Created by Bradley Austin Davis on 2019/05/14 +// Copyright 2013-2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include "PerformanceScriptingInterface.h" + +#include "../Application.h" + +std::once_flag PerformanceScriptingInterface::registry_flag; + +PerformanceScriptingInterface::PerformanceScriptingInterface() { + std::call_once(registry_flag, [] { + qmlRegisterType("PerformanceEnums", 1, 0, "RefreshRate"); + }); +} + +void PerformanceScriptingInterface::setRefreshRateProfile(RefreshRateProfile refreshRateProfile) { + qApp->getRefreshRateManager().setRefreshRateProfile((RefreshRateManager::RefreshRateProfile)refreshRateProfile); +} + +PerformanceScriptingInterface::RefreshRateProfile PerformanceScriptingInterface::getRefreshRateProfile() const { + return (PerformanceScriptingInterface::RefreshRateProfile)qApp->getRefreshRateManager().getRefreshRateProfile(); +} diff --git a/interface/src/scripting/PerformanceScriptingInterface.h b/interface/src/scripting/PerformanceScriptingInterface.h new file mode 100644 index 0000000000..266fa7229f --- /dev/null +++ b/interface/src/scripting/PerformanceScriptingInterface.h @@ -0,0 +1,43 @@ +// +// Created by Bradley Austin Davis on 2019/05/14 +// Copyright 2013-2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_PerformanceScriptingInterface_h +#define hifi_PerformanceScriptingInterface_h + +#include + +#include + +#include "../RefreshRateManager.h" + + +class PerformanceScriptingInterface : public QObject { + Q_OBJECT +public: + // Must match RefreshRateManager enums + enum RefreshRateProfile { + ECO = RefreshRateManager::RefreshRateProfile::ECO, + INTERACTIVE = RefreshRateManager::RefreshRateProfile::INTERACTIVE, + REALTIME = RefreshRateManager::RefreshRateProfile::REALTIME, + }; + Q_ENUM(RefreshRateProfile) + + + PerformanceScriptingInterface(); + ~PerformanceScriptingInterface() = default; + +public slots: + void setRefreshRateProfile(RefreshRateProfile refreshRateProfile); + RefreshRateProfile getRefreshRateProfile() const; + +private: + static std::once_flag registry_flag; +}; + +#endif // header guard From 8c375db90f3185263c4180db78cc495d4968f199 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 15 May 2019 12:55:47 -0700 Subject: [PATCH 2/4] Add display plugin introspection to the window scripting interface --- .../scripting/WindowScriptingInterface.cpp | 33 ++++++++++++++++ .../src/scripting/WindowScriptingInterface.h | 38 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 2c1311924f..e1272d68a7 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include "AndroidHelper.h" @@ -609,3 +610,35 @@ void WindowScriptingInterface::onMessageBoxSelected(int button) { float WindowScriptingInterface::domainLoadingProgress() { return qApp->getOctreePacketProcessor().domainLoadingProgress(); } + +const DisplayPluginList& getDisplayPlugins() { + static const auto& list = PluginManager::getInstance()->getDisplayPlugins(); + return list; +} + +int WindowScriptingInterface::getDisplayPluginCount() { + return getDisplayPlugins().size(); +} + +QString WindowScriptingInterface::getDisplayPluginName(int index) { + return getDisplayPlugins().at(index)->getName(); +} + +bool WindowScriptingInterface::isDisplayPluginHmd(int index) { + return getDisplayPlugins().at(index)->isHmd(); +} + +int WindowScriptingInterface::getActiveDisplayPlugin() { + auto active = qApp->getActiveDisplayPlugin(); + auto size = getDisplayPluginCount(); + for (int i = 0; i < size; ++i) { + if (getDisplayPlugins().at(i) == active) { + return i; + } + } + return -1; +} + +void WindowScriptingInterface::setActiveDisplayPlugin(int index) { + qApp->setActiveDisplayPlugin(getDisplayPlugins().at(index)->getName()); +} diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 77b586ec70..c165e5474e 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -575,6 +575,44 @@ public slots: float domainLoadingProgress(); + /**jsdoc + * Return the number of display plugins currently available + * @function Window.getDisplayPluginCount + * @returns {int} The number of currently available display plugins + */ + int getDisplayPluginCount(); + + /**jsdoc + * Return the human readable name of a display plugin + * @function Window.getDisplayPluginName + * @param {int} index - The index of the display plugin. Must be less than the value returned by {@link Window.getDisplayPluginCount|getDisplayPluginCount}. + * @returns {string} The name of the specified display plugin + */ + QString getDisplayPluginName(int index); + + /**jsdoc + * Return whether a given display plugin is an HMD + * @function Window.isDisplayPluginHmd + * @param {int} index - The index of the display plugin. Must be less than the value returned by {@link Window.getDisplayPluginCount|getDisplayPluginCount}. + * @returns {bool} True if the specified display plugin is a HMD + */ + bool isDisplayPluginHmd(int index); + + /**jsdoc + * Return the currently active display plugin + * @function Window.getActiveDisplayPlugin + * @returns {int} The index of the currently active display plugin + */ + int getActiveDisplayPlugin(); + + /**jsdoc + * Return the currently active display plugin + * @function Window.setActiveDisplayPlugin + * @param {int} index - The index of the display plugin. Must be less than the value returned by {@link Window.getDisplayPluginCount|getDisplayPluginCount}. + */ + void setActiveDisplayPlugin(int index); + + private slots: void onWindowGeometryChanged(const QRect& geometry); void onMessageBoxSelected(int button); From 9bcc23f0c48445b9dfa0da1c9cb716308ee0b381 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 16 May 2019 09:40:22 -0700 Subject: [PATCH 3/4] PR comments --- interface/src/Application.cpp | 4 -- .../PerformanceScriptingInterface.cpp | 12 +++++ .../scripting/PerformanceScriptingInterface.h | 5 ++ .../scripting/RefreshRateScriptingInterface.h | 46 ------------------- 4 files changed, 17 insertions(+), 50 deletions(-) delete mode 100644 interface/src/scripting/RefreshRateScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7f429d9765..3d6c2218ce 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -192,7 +192,6 @@ #include "scripting/WalletScriptingInterface.h" #include "scripting/TTSScriptingInterface.h" #include "scripting/KeyboardScriptingInterface.h" -#include "scripting/RefreshRateScriptingInterface.h" #include "scripting/PerformanceScriptingInterface.h" @@ -3280,7 +3279,6 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("Controller", DependencyManager::get().data()); surfaceContext->setContextProperty("Entities", DependencyManager::get().data()); - surfaceContext->setContextProperty("RefreshRate", new RefreshRateScriptingInterface()); surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface()); _fileDownload = new FileScriptingInterface(engine); surfaceContext->setContextProperty("File", _fileDownload); @@ -3431,7 +3429,6 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona surfaceContext->setContextProperty("Settings", SettingsScriptingInterface::getInstance()); surfaceContext->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance()); - surfaceContext->setContextProperty("RefreshRate", new RefreshRateScriptingInterface()); surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface()); surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED @@ -7416,7 +7413,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("LODManager", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Keyboard", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("RefreshRate", new RefreshRateScriptingInterface()); scriptEngine->registerGlobalObject("Performance", new PerformanceScriptingInterface()); scriptEngine->registerGlobalObject("Paths", DependencyManager::get().data()); diff --git a/interface/src/scripting/PerformanceScriptingInterface.cpp b/interface/src/scripting/PerformanceScriptingInterface.cpp index 53529beeef..b1b4e62dca 100644 --- a/interface/src/scripting/PerformanceScriptingInterface.cpp +++ b/interface/src/scripting/PerformanceScriptingInterface.cpp @@ -26,3 +26,15 @@ void PerformanceScriptingInterface::setRefreshRateProfile(RefreshRateProfile ref PerformanceScriptingInterface::RefreshRateProfile PerformanceScriptingInterface::getRefreshRateProfile() const { return (PerformanceScriptingInterface::RefreshRateProfile)qApp->getRefreshRateManager().getRefreshRateProfile(); } + +int PerformanceScriptingInterface::getActiveRefreshRate() const { + return qApp->getRefreshRateManager().getActiveRefreshRate(); +} + +RefreshRateManager::UXMode PerformanceScriptingInterface::getUXMode() const { + return qApp->getRefreshRateManager().getUXMode(); +} + +RefreshRateManager::RefreshRateRegime PerformanceScriptingInterface::getRefreshRateRegime() const { + return qApp->getRefreshRateManager().getRefreshRateRegime(); +} diff --git a/interface/src/scripting/PerformanceScriptingInterface.h b/interface/src/scripting/PerformanceScriptingInterface.h index 266fa7229f..90b51d173c 100644 --- a/interface/src/scripting/PerformanceScriptingInterface.h +++ b/interface/src/scripting/PerformanceScriptingInterface.h @@ -36,6 +36,11 @@ public slots: void setRefreshRateProfile(RefreshRateProfile refreshRateProfile); RefreshRateProfile getRefreshRateProfile() const; + int getActiveRefreshRate() const; + RefreshRateManager::UXMode getUXMode() const; + RefreshRateManager::RefreshRateRegime getRefreshRateRegime() const; + + private: static std::once_flag registry_flag; }; diff --git a/interface/src/scripting/RefreshRateScriptingInterface.h b/interface/src/scripting/RefreshRateScriptingInterface.h deleted file mode 100644 index 697141583f..0000000000 --- a/interface/src/scripting/RefreshRateScriptingInterface.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// RefreshRateScriptingInterface.h -// interface/src/scrfipting -// -// Created by Dante Ruiz on 2019-04-15. -// Copyright 2019 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_RefreshRateScriptingInterface_h -#define hifi_RefreshRateScriptingInterface_h - -#include - -#include - -class RefreshRateScriptingInterface : public QObject { - Q_OBJECT -public: - RefreshRateScriptingInterface() = default; - ~RefreshRateScriptingInterface() = default; - -public: - Q_INVOKABLE QString getRefreshRateProfile() { - RefreshRateManager& refreshRateManager = qApp->getRefreshRateManager(); - return QString::fromStdString(RefreshRateManager::refreshRateProfileToString(refreshRateManager.getRefreshRateProfile())); - } - - Q_INVOKABLE QString getRefreshRateRegime() { - RefreshRateManager& refreshRateManager = qApp->getRefreshRateManager(); - return QString::fromStdString(RefreshRateManager::refreshRateRegimeToString(refreshRateManager.getRefreshRateRegime())); - } - - Q_INVOKABLE QString getUXMode() { - RefreshRateManager& refreshRateManager = qApp->getRefreshRateManager(); - return QString::fromStdString(RefreshRateManager::uxModeToString(refreshRateManager.getUXMode())); - } - - Q_INVOKABLE int getActiveRefreshRate() { - return qApp->getRefreshRateManager().getActiveRefreshRate(); - } -}; - -#endif From 6a0b479041f1f96356f1a7ab260b47211627ca0d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 16 May 2019 10:48:18 -0700 Subject: [PATCH 4/4] Fix warning and build failures --- .../src/scripting/WindowScriptingInterface.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index e1272d68a7..3194fa24eb 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -611,28 +611,23 @@ float WindowScriptingInterface::domainLoadingProgress() { return qApp->getOctreePacketProcessor().domainLoadingProgress(); } -const DisplayPluginList& getDisplayPlugins() { - static const auto& list = PluginManager::getInstance()->getDisplayPlugins(); - return list; -} - int WindowScriptingInterface::getDisplayPluginCount() { - return getDisplayPlugins().size(); + return (int)PluginManager::getInstance()->getDisplayPlugins().size(); } QString WindowScriptingInterface::getDisplayPluginName(int index) { - return getDisplayPlugins().at(index)->getName(); + return PluginManager::getInstance()->getDisplayPlugins().at(index)->getName(); } bool WindowScriptingInterface::isDisplayPluginHmd(int index) { - return getDisplayPlugins().at(index)->isHmd(); + return PluginManager::getInstance()->getDisplayPlugins().at(index)->isHmd(); } int WindowScriptingInterface::getActiveDisplayPlugin() { auto active = qApp->getActiveDisplayPlugin(); auto size = getDisplayPluginCount(); for (int i = 0; i < size; ++i) { - if (getDisplayPlugins().at(i) == active) { + if (PluginManager::getInstance()->getDisplayPlugins().at(i) == active) { return i; } } @@ -640,5 +635,6 @@ int WindowScriptingInterface::getActiveDisplayPlugin() { } void WindowScriptingInterface::setActiveDisplayPlugin(int index) { - qApp->setActiveDisplayPlugin(getDisplayPlugins().at(index)->getName()); + auto name = PluginManager::getInstance()->getDisplayPlugins().at(index)->getName(); + qApp->setActiveDisplayPlugin(name); }