History

merge from upstream

Seth Alves committed 8 years ago

Commit 1cbc2e32 parents f6b4cf4 7fe4f84218 files · +7684 −4531Browse files

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

Unified · Split

interface/src/Application.cpp+112−35
@@ -14,17 +14,20 @@ · 13 unmodified lines
1414 #include <chrono>
1515 #include <thread>
1616
17−#include <gl/Config.h>
1817 #include <glm/glm.hpp>
1918 #include <glm/gtx/component_wise.hpp>
2019 #include <glm/gtx/quaternion.hpp>
2120 #include <glm/gtx/vector_angle.hpp>
2221 #include <glm/gtc/type_ptr.hpp>
2322
23+#include <gl/Config.h>
24+
25+#include <QtCore/QResource>
2426 #include <QtCore/QAbstractNativeEventFilter>
2527 #include <QtCore/QCommandLineParser>
2628 #include <QtCore/QMimeData>
2729 #include <QtCore/QThreadPool>
30+#include <QtCore/QFileSelector>
2831 #include <QtConcurrent/QtConcurrentRun>
2932
3033 #include <QtGui/QScreen>
@@ -49,6 +52,7 @@ · 18 unmodified lines
4952
5053 #include <gl/QOpenGLContextWrapper.h>
5154
55+#include <shared/FileUtils.h>
5256 #include <shared/QtHelpers.h>
5357 #include <shared/GlobalAppProperties.h>
5458 #include <StatTracker.h>
@@ -211,8 +215,6 @@ · 156 unmodified lines
211215 #include "webbrowser/WebBrowserSuggestionsEngine.h"
212216 #include <DesktopPreviewProvider.h>
213217
214−// On Windows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
215−// FIXME seems to be broken.
216218 #if defined(Q_OS_WIN)
217219 #include <VersionHelpers.h>
218220
@@ -227,11 +229,17 @@ · 8 unmodified lines
227229 #undef QT_BOOTSTRAPPED
228230 #endif
229231
232+// On Windows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
233+// FIXME seems to be broken.
230234 extern "C" {
231235 _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
232236 }
233237 #endif
234238
239+#if defined(Q_OS_ANDROID)
240+#include <android/log.h>
241+#endif
242+
235243 enum ApplicationEvent {
236244 // Execute a lambda function
237245 Lambda = QEvent::User + 1,
@@ -241,7 +249,6 @@ enum ApplicationEvent { · 3 unmodified lines
241249 Idle,
242250 };
243251
244−
245252 class RenderEventHandler : public QObject {
246253 using Parent = QObject;
247254 Q_OBJECT
@@ -305,9 +312,19 @@ static QTimer locationUpdateTimer; · 57 unmodified lines
305312 static QTimer identityPacketTimer;
306313 static QTimer pingTimer;
307314
308−static const QString DISABLE_WATCHDOG_FLAG("HIFI_DISABLE_WATCHDOG");
315+#if defined(Q_OS_ANDROID)
316+static bool DISABLE_WATCHDOG = true;
317+#else
318+static const QString DISABLE_WATCHDOG_FLAG{ "HIFI_DISABLE_WATCHDOG" };
309319 static bool DISABLE_WATCHDOG = QProcessEnvironment::systemEnvironment().contains(DISABLE_WATCHDOG_FLAG);
320+#endif
310321
322+#if defined(USE_GLES)
323+static bool DISABLE_DEFERRED = true;
324+#else
325+static const QString RENDER_FORWARD{ "HIFI_RENDER_FORWARD" };
326+static bool DISABLE_DEFERRED = QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD);
327+#endif
311328
312329 static const int MAX_CONCURRENT_RESOURCE_DOWNLOADS = 16;
313330
@@ -504,7 +521,13 @@ public: · 190 unmodified lines
504521 }
505522
506523 if (message->message == WM_DEVICECHANGE) {
507− Midi::USBchanged(); // re-scan the MIDI bus
524+ const float MIN_DELTA_SECONDS = 2.0f; // de-bounce signal
525+ static float lastTriggerTime = 0.0f;
526+ const float deltaSeconds = secTimestampNow() - lastTriggerTime;
527+ lastTriggerTime = secTimestampNow();
528+ if (deltaSeconds > MIN_DELTA_SECONDS) {
529+ Midi::USBchanged(); // re-scan the MIDI bus
530+ }
508531 }
509532 }
510533 return false;
@@ -531,6 +554,26 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt · 20 unmodified lines
531554 #ifdef Q_OS_WIN
532555 OutputDebugStringA(logMessage.toLocal8Bit().constData());
533556 OutputDebugStringA("\n");
557+#elif defined Q_OS_ANDROID
558+ const char * local=logMessage.toStdString().c_str();
559+ switch (type) {
560+ case QtDebugMsg:
561+ __android_log_write(ANDROID_LOG_DEBUG,"Interface",local);
562+ break;
563+ case QtInfoMsg:
564+ __android_log_write(ANDROID_LOG_INFO,"Interface",local);
565+ break;
566+ case QtWarningMsg:
567+ __android_log_write(ANDROID_LOG_WARN,"Interface",local);
568+ break;
569+ case QtCriticalMsg:
570+ __android_log_write(ANDROID_LOG_ERROR,"Interface",local);
571+ break;
572+ case QtFatalMsg:
573+ default:
574+ __android_log_write(ANDROID_LOG_FATAL,"Interface",local);
575+ abort();
576+ }
534577 #endif
535578 qApp->getLogger()->addMessage(qPrintable(logMessage + "\n"));
536579 }
@@ -594,6 +637,24 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 57 unmodified lines
594637 qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, cacheDir);
595638 }
596639
640+ // FIXME fix the OSX installer to install the resources.rcc binary instead of resource files and remove
641+ // this conditional exclusion
642+#if !defined(Q_OS_OSX)
643+ {
644+#if defined(Q_OS_ANDROID)
645+ const QString resourcesBinaryFile = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/resources.rcc";
646+#else
647+ const QString resourcesBinaryFile = QCoreApplication::applicationDirPath() + "/resources.rcc";
648+#endif
649+ if (!QFile::exists(resourcesBinaryFile)) {
650+ throw std::runtime_error("Unable to find primary resources");
651+ }
652+ if (!QResource::registerResource(resourcesBinaryFile)) {
653+ throw std::runtime_error("Unable to load primary resources");
654+ }
655+ }
656+#endif
657+
597658 Setting::init();
598659
599660 // Tell the plugin manager about our statically linked plugins
@@ -637,11 +698,11 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 37 unmodified lines
637698 DependencyManager::set<StatTracker>();
638699 DependencyManager::set<ScriptEngines>(ScriptEngine::CLIENT_SCRIPT);
639700 DependencyManager::set<Preferences>();
640− DependencyManager::set<recording::ClipCache>();
641701 DependencyManager::set<recording::Deck>();
642702 DependencyManager::set<recording::Recorder>();
643703 DependencyManager::set<AddressManager>();
644704 DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
705+ DependencyManager::set<recording::ClipCache>();
645706 DependencyManager::set<GeometryCache>();
646707 DependencyManager::set<ModelCache>();
647708 DependencyManager::set<ScriptCache>();
@@ -730,8 +791,10 @@ OverlayID _keyboardFocusHighlightID{ UNKNOWN_OVERLAY_ID }; · 82 unmodified lines
730791 //
731792 // So instead we create a new offscreen context to share with the QGLWidget,
732793 // and manually set THAT to be the shared context for the Chromium helper
794+#if !defined(DISABLE_QML)
733795 OffscreenGLCanvas* _chromiumShareContext { nullptr };
734796 Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context);
797+#endif
735798
736799 Setting::Handle<int> sessionRunTime{ "sessionRunTime", 0 };
737800
@@ -777,6 +840,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 39 unmodified lines
777840 _sampleSound(nullptr)
778841
779842 {
843+
780844 auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
781845 setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
782846 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
@@ -997,8 +1061,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 214 unmodified lines
9971061 DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);
9981062
9991063 // Inititalize sample before registering
1000− QFileInfo infSample = QFileInfo(PathUtils::resourcesPath() + "sounds/sample.wav");
1001− _sampleSound = DependencyManager::get<SoundCache>()->getSound(QUrl::fromLocalFile(infSample.absoluteFilePath()));
1064+ _sampleSound = DependencyManager::get<SoundCache>()->getSound(PathUtils::resourcesUrl("sounds/sample.wav"));
10021065
10031066 auto scriptEngines = DependencyManager::get<ScriptEngines>().data();
10041067 scriptEngines->registerScriptInitializer([this](ScriptEnginePointer engine){
@@ -1083,9 +1146,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 78 unmodified lines
10831146 // Make sure we don't time out during slow operations at startup
10841147 updateHeartbeat();
10851148
1086− // Now that OpenGL is initialized, we are sure we have a valid context and can create the various pipeline shaders with success.
1087− DependencyManager::get<GeometryCache>()->initializeShapePipelines();
1088−
10891149 // sessionRunTime will be reset soon by loadSettings. Grab it now to get previous session value.
10901150 // The value will be 0 if the user blew away settings this session, which is both a feature and a bug.
10911151 static const QString TESTER = "HIFI_TESTER";
@@ -1731,7 +1791,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 639 unmodified lines
17311791 static int lastCountOfNearbyAvatars = -1;
17321792 QTimer* checkNearbyAvatarsTimer = new QTimer(this);
17331793 checkNearbyAvatarsTimer->setInterval(CHECK_NEARBY_AVATARS_INTERVAL_MS); // 10 seconds, Qt::CoarseTimer ok
1734− connect(checkNearbyAvatarsTimer, &QTimer::timeout, this, [this]() {
1794+ connect(checkNearbyAvatarsTimer, &QTimer::timeout, this, []() {
17351795 auto avatarManager = DependencyManager::get<AvatarManager>();
17361796 int nearbyAvatars = avatarManager->numberOfAvatarsInRange(avatarManager->getMyAvatar()->getWorldPosition(),
17371797 NEARBY_AVATAR_RADIUS_METERS) - 1;
@@ -1770,9 +1830,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 32 unmodified lines
17701830 PROFILE_RANGE(render, "Process Default Skybox");
17711831 auto textureCache = DependencyManager::get<TextureCache>();
17721832
1773− auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx";
1833+ QFileSelector fileSelector;
1834+ fileSelector.setExtraSelectors(FileUtils::getFileSelectors());
1835+ auto skyboxUrl = fileSelector.select(PathUtils::resourcesPath() + "images/Default-Sky-9-cubemap.ktx");
17741836
1775− _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl);
1837+ _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl.toStdString());
17761838 _defaultSkyboxAmbientTexture = _defaultSkyboxTexture;
17771839
17781840 _defaultSkybox->setCubemap(_defaultSkyboxTexture);
@@ -1783,8 +1845,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 4 unmodified lines
17831845 return entityServerNode && !isPhysicsEnabled();
17841846 });
17851847
1786− QFileInfo infSnap = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav");
1787− _snapshotSound = DependencyManager::get<SoundCache>()->getSound(QUrl::fromLocalFile(infSnap.absoluteFilePath()));
1848+ _snapshotSound = DependencyManager::get<SoundCache>()->getSound(PathUtils::resourcesUrl("sounds/snap.wav"));
17881849
17891850 QVariant testProperty = property(hifi::properties::TEST);
17901851 qDebug() << testProperty;
@@ -2182,11 +2243,16 @@ void Application::initializeGL() { · 391 unmodified lines
21822243 }
21832244
21842245 _glWidget->makeCurrent();
2185− _chromiumShareContext = new OffscreenGLCanvas();
2186− _chromiumShareContext->setObjectName("ChromiumShareContext");
2187− _chromiumShareContext->create(_glWidget->qglContext());
2188− _chromiumShareContext->makeCurrent();
2189− qt_gl_set_global_share_context(_chromiumShareContext->getContext());
2246+
2247+#if !defined(DISABLE_QML)
2248+ if (!nsightActive()) {
2249+ _chromiumShareContext = new OffscreenGLCanvas();
2250+ _chromiumShareContext->setObjectName("ChromiumShareContext");
2251+ _chromiumShareContext->create(_glWidget->qglContext());
2252+ _chromiumShareContext->makeCurrent();
2253+ qt_gl_set_global_share_context(_chromiumShareContext->getContext());
2254+ }
2255+#endif
21902256
21912257 _glWidget->makeCurrent();
21922258 gpu::Context::init<gpu::gl::GLBackend>();
@@ -2203,13 +2269,17 @@ void Application::initializeGL() { · 10 unmodified lines
22032269 // Set up the render engine
22042270 render::CullFunctor cullFunctor = LODManager::shouldRender;
22052271 static const QString RENDER_FORWARD = "HIFI_RENDER_FORWARD";
2206− bool isDeferred = !QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD);
22072272 _renderEngine->addJob<UpdateSceneTask>("UpdateScene");
2208− _renderEngine->addJob<SecondaryCameraRenderTask>("SecondaryCameraJob", cullFunctor);
2209− _renderEngine->addJob<RenderViewTask>("RenderMainView", cullFunctor, isDeferred, render::ItemKey::VISIBLE_MASK_0, render::ItemKey::VISIBLE_MASK_0);
2273+#ifndef Q_OS_ANDROID
2274+ _renderEngine->addJob<SecondaryCameraRenderTask>("SecondaryCameraJob", cullFunctor, !DISABLE_DEFERRED);
2275+#endif
2276+ _renderEngine->addJob<RenderViewTask>("RenderMainView", cullFunctor, !DISABLE_DEFERRED, render::ItemKey::VISIBLE_MASK_0, render::ItemKey::VISIBLE_MASK_0);
22102277 _renderEngine->load();
22112278 _renderEngine->registerScene(_main3DScene);
22122279
2280+ // Now that OpenGL is initialized, we are sure we have a valid context and can create the various pipeline shaders with success.
2281+ DependencyManager::get<GeometryCache>()->initializeShapePipelines();
2282+
22132283 _offscreenContext = new OffscreenGLCanvas();
22142284 _offscreenContext->setObjectName("MainThreadContext");
22152285 _offscreenContext->create(_glWidget->qglContext());
@@ -2314,8 +2384,7 @@ void Application::initializeUi() { · 98 unmodified lines
23142384 offscreenUi->setProxyWindow(_window->windowHandle());
23152385 // OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to
23162386 // support the window management and scripting proxies for VR use
2317− offscreenUi->createDesktop(QString("hifi/Desktop.qml"));
2318−
2387+ offscreenUi->createDesktop(PathUtils::qmlUrl("hifi/Desktop.qml"));
23192388 // FIXME either expose so that dialogs can set this themselves or
23202389 // do better detection in the offscreen UI of what has focus
23212390 offscreenUi->setNavigationFocused(false);
@@ -3910,12 +3979,18 @@ void Application::idle() { · 1588 unmodified lines
39103979 PROFILE_COUNTER_IF_CHANGED(app, "pendingProcessing", int, DependencyManager::get<StatTracker>()->getStat("PendingProcessing").toInt());
39113980 auto renderConfig = _renderEngine->getConfiguration();
39123981 PROFILE_COUNTER_IF_CHANGED(render, "gpuTime", float, (float)_gpuContext->getFrameTimerGPUAverage());
3982+ auto opaqueRangeTimer = renderConfig->getConfig("OpaqueRangeTimer");
3983+ auto linearDepth = renderConfig->getConfig("LinearDepth");
3984+ auto surfaceGeometry = renderConfig->getConfig("SurfaceGeometry");
3985+ auto renderDeferred = renderConfig->getConfig("RenderDeferred");
3986+ auto toneAndPostRangeTimer = renderConfig->getConfig("ToneAndPostRangeTimer");
3987+
39133988 PROFILE_COUNTER(render_detail, "gpuTimes", {
3914− { "OpaqueRangeTimer", renderConfig->getConfig("OpaqueRangeTimer")->property("gpuRunTime") },
3915− { "LinearDepth", renderConfig->getConfig("LinearDepth")->property("gpuRunTime") },
3916− { "SurfaceGeometry", renderConfig->getConfig("SurfaceGeometry")->property("gpuRunTime") },
3917− { "RenderDeferred", renderConfig->getConfig("RenderDeferred")->property("gpuRunTime") },
3918− { "ToneAndPostRangeTimer", renderConfig->getConfig("ToneAndPostRangeTimer")->property("gpuRunTime") }
3989+ { "OpaqueRangeTimer", opaqueRangeTimer ? opaqueRangeTimer->property("gpuRunTime") : 0 },
3990+ { "LinearDepth", linearDepth ? linearDepth->property("gpuRunTime") : 0 },
3991+ { "SurfaceGeometry", surfaceGeometry ? surfaceGeometry->property("gpuRunTime") : 0 },
3992+ { "RenderDeferred", renderDeferred ? renderDeferred->property("gpuRunTime") : 0 },
3993+ { "ToneAndPostRangeTimer", toneAndPostRangeTimer ? toneAndPostRangeTimer->property("gpuRunTime") : 0 }
39193994 });
39203995
39213996 PROFILE_RANGE(app, __FUNCTION__);
@@ -4280,9 +4355,9 @@ void Application::init() { · 358 unmodified lines
42804355
42814356 // Make sure Login state is up to date
42824357 DependencyManager::get<DialogsManager>()->toggleLoginDialog();
4283−
4284− DependencyManager::get<DeferredLightingEffect>()->init();
4285−
4358+ if (!DISABLE_DEFERRED) {
4359+ DependencyManager::get<DeferredLightingEffect>()->init();
4360+ }
42864361 DependencyManager::get<AvatarManager>()->init();
42874362
42884363 _timerStart.start();
@@ -5761,7 +5836,9 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe · 1472 unmodified lines
57615836 scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
57625837 LocationScriptingInterface::locationSetter);
57635838
5839+#if !defined(Q_OS_ANDROID)
57645840 scriptEngine->registerFunction("OverlayWebWindow", QmlWebWindowClass::constructor);
5841+#endif
57655842 scriptEngine->registerFunction("OverlayWindow", QmlWindowClass::constructor);
57665843
57675844 scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());