History

Merge pull request #10548 from NeetBhagat/21255

On Oculus Rift on/off, switch automatically to/from desktop mode

Brad Hefta-Gaub committed 9 years ago

Commit e5ac3ee2 parents 06527ac c3621d78 files · +112 −5Browse files

Showing the changes to interface/src/Application.cpp (1 of 8 files). Show all

Unified · Split

interface/src/Application.cpp+60−1
@@ -247,6 +247,8 @@ static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStanda · 246 unmodified lines
247247 Setting::Handle<int> maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS);
248248
249249 static const QString MARKETPLACE_CDN_HOSTNAME = "mpassets.highfidelity.com";
250+static const int INTERVAL_TO_CHECK_HMD_WORN_STATUS = 500; // milliseconds
251+static const QString DESKTOP_DISPLAY_PLUGIN_NAME = "Desktop";
250252
251253 const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions {
252254 { SVO_EXTENSION, &Application::importSVOFromURL },
@@ -1413,6 +1415,31 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 1160 unmodified lines
14131415 properties["active_display_plugin"] = getActiveDisplayPlugin()->getName();
14141416 properties["using_hmd"] = isHMDMode();
14151417
1418+ _autoSwitchDisplayModeSupportedHMDPlugin = nullptr;
1419+ foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) {
1420+ if (displayPlugin->isHmd() &&
1421+ displayPlugin->getSupportsAutoSwitch()) {
1422+ _autoSwitchDisplayModeSupportedHMDPlugin = displayPlugin;
1423+ _autoSwitchDisplayModeSupportedHMDPluginName =
1424+ _autoSwitchDisplayModeSupportedHMDPlugin->getName();
1425+ _previousHMDWornStatus =
1426+ _autoSwitchDisplayModeSupportedHMDPlugin->isDisplayVisible();
1427+ break;
1428+ }
1429+ }
1430+
1431+ if (_autoSwitchDisplayModeSupportedHMDPlugin) {
1432+ if (getActiveDisplayPlugin() != _autoSwitchDisplayModeSupportedHMDPlugin &&
1433+ !_autoSwitchDisplayModeSupportedHMDPlugin->isSessionActive()) {
1434+ startHMDStandBySession();
1435+ }
1436+ // Poll periodically to check whether the user has worn HMD or not. Switch Display mode accordingly.
1437+ // If the user wears HMD then switch to VR mode. If the user removes HMD then switch to Desktop mode.
1438+ QTimer* autoSwitchDisplayModeTimer = new QTimer(this);
1439+ connect(autoSwitchDisplayModeTimer, SIGNAL(timeout()), this, SLOT(switchDisplayMode()));
1440+ autoSwitchDisplayModeTimer->start(INTERVAL_TO_CHECK_HMD_WORN_STATUS);
1441+ }
1442+
14161443 auto glInfo = getGLContextData();
14171444 properties["gl_info"] = glInfo;
14181445 properties["gpu_used_memory"] = (int)BYTES_TO_MB(gpu::Context::getUsedGPUMemSize());
@@ -1646,7 +1673,10 @@ void Application::aboutToQuit() { · 227 unmodified lines
16461673 }
16471674
16481675 getActiveDisplayPlugin()->deactivate();
1649−
1676+ if (_autoSwitchDisplayModeSupportedHMDPlugin
1677+ && _autoSwitchDisplayModeSupportedHMDPlugin->isSessionActive()) {
1678+ _autoSwitchDisplayModeSupportedHMDPlugin->endSession();
1679+ }
16501680 // use the CloseEventSender via a QThread to send an event that says the user asked for the app to close
16511681 auto closeEventSender = DependencyManager::get<CloseEventSender>();
16521682 QThread* closureEventThread = new QThread(this);
@@ -6855,6 +6885,35 @@ void Application::updateDisplayMode() { · 5202 unmodified lines
68556885 Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");
68566886 }
68576887
6888+void Application::switchDisplayMode() {
6889+ if (!_autoSwitchDisplayModeSupportedHMDPlugin) {
6890+ return;
6891+ }
6892+ bool currentHMDWornStatus = _autoSwitchDisplayModeSupportedHMDPlugin->isDisplayVisible();
6893+ if (currentHMDWornStatus != _previousHMDWornStatus) {
6894+ // Switch to respective mode as soon as currentHMDWornStatus changes
6895+ if (currentHMDWornStatus) {
6896+ qCDebug(interfaceapp) << "Switching from Desktop to HMD mode";
6897+ endHMDSession();
6898+ setActiveDisplayPlugin(_autoSwitchDisplayModeSupportedHMDPluginName);
6899+ } else {
6900+ qCDebug(interfaceapp) << "Switching from HMD to desktop mode";
6901+ setActiveDisplayPlugin(DESKTOP_DISPLAY_PLUGIN_NAME);
6902+ startHMDStandBySession();
6903+ }
6904+ emit activeDisplayPluginChanged();
6905+ }
6906+ _previousHMDWornStatus = currentHMDWornStatus;
6907+}
6908+
6909+void Application::startHMDStandBySession() {
6910+ _autoSwitchDisplayModeSupportedHMDPlugin->startStandBySession();
6911+}
6912+
6913+void Application::endHMDSession() {
6914+ _autoSwitchDisplayModeSupportedHMDPlugin->endSession();
6915+}
6916+
68586917 mat4 Application::getEyeProjection(int eye) const {
68596918 QMutexLocker viewLocker(&_viewMutex);
68606919 if (isHMDMode()) {