diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3dc49e89d6..45807662ef 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -192,7 +192,7 @@ #include "scripting/WalletScriptingInterface.h" #include "scripting/TTSScriptingInterface.h" #include "scripting/KeyboardScriptingInterface.h" -#include "scripting/RefreshRateScriptingInterface.h" +#include "scripting/PerformanceScriptingInterface.h" @@ -3274,7 +3274,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); @@ -3424,7 +3424,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 @@ -7392,7 +7392,7 @@ 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/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..b1b4e62dca --- /dev/null +++ b/interface/src/scripting/PerformanceScriptingInterface.cpp @@ -0,0 +1,40 @@ +// +// 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(); +} + +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 new file mode 100644 index 0000000000..90b51d173c --- /dev/null +++ b/interface/src/scripting/PerformanceScriptingInterface.h @@ -0,0 +1,48 @@ +// +// 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; + + int getActiveRefreshRate() const; + RefreshRateManager::UXMode getUXMode() const; + RefreshRateManager::RefreshRateRegime getRefreshRateRegime() const; + + +private: + static std::once_flag registry_flag; +}; + +#endif // header guard 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 diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 954c3e4590..eb967dde89 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,31 @@ void WindowScriptingInterface::onMessageBoxSelected(int button) { float WindowScriptingInterface::domainLoadingProgress() { return qApp->getOctreePacketProcessor().domainLoadingProgress(); } + +int WindowScriptingInterface::getDisplayPluginCount() { + return (int)PluginManager::getInstance()->getDisplayPlugins().size(); +} + +QString WindowScriptingInterface::getDisplayPluginName(int index) { + return PluginManager::getInstance()->getDisplayPlugins().at(index)->getName(); +} + +bool WindowScriptingInterface::isDisplayPluginHmd(int index) { + 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 (PluginManager::getInstance()->getDisplayPlugins().at(i) == active) { + return i; + } + } + return -1; +} + +void WindowScriptingInterface::setActiveDisplayPlugin(int index) { + auto name = PluginManager::getInstance()->getDisplayPlugins().at(index)->getName(); + qApp->setActiveDisplayPlugin(name); +} diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 9a314cad6a..dd3f01dd17 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -558,6 +558,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);