History

Merge remote-tracking branch 'upstream/master' into kasenvr-kpi-v1-modkit-rc-merge

humbletim committed 7 years ago

Commit 271fac42 parents bad32e9 96f67931529 files · +58136 −6493Browse files

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

Unified · Split

interface/src/Application.cpp+125−46
@@ -58,6 +58,7 @@ · 57 unmodified lines
5858
5959 #include <shared/FileUtils.h>
6060 #include <shared/QtHelpers.h>
61+#include <shared/PlatformHelper.h>
6162 #include <shared/GlobalAppProperties.h>
6263 #include <StatTracker.h>
6364 #include <Trace.h>
@@ -73,6 +74,7 @@ · 9 unmodified lines
7374 #include <Midi.h>
7475 #include <AudioInjectorManager.h>
7576 #include <AvatarBookmarks.h>
77+#include <CrashHelpers.h>
7678 #include <CursorManager.h>
7779 #include <VirtualPadManager.h>
7880 #include <DebugDraw.h>
@@ -137,6 +139,7 @@ · 58 unmodified lines
137139 #include <SoundCacheScriptingInterface.h>
138140 #include <ui/TabletScriptingInterface.h>
139141 #include <ui/ToolbarScriptingInterface.h>
142+#include <ui/types/ContextAwareProfile.h>
140143 #include <Tooltip.h>
141144 #include <udt/PacketHeaders.h>
142145 #include <UserActivityLogger.h>
@@ -257,10 +260,6 @@ extern "C" { · 114 unmodified lines
257260 }
258261 #endif
259262
260−#ifdef Q_OS_MAC
261−#include "MacHelper.h"
262−#endif
263−
264263 #if defined(Q_OS_ANDROID)
265264 #include <android/log.h>
266265 #include "AndroidHelper.h"
@@ -292,7 +291,7 @@ static const uint32_t MAX_CONCURRENT_RESOURCE_DOWNLOADS = 4; · 25 unmodified lines
292291 // For processing on QThreadPool, we target a number of threads after reserving some
293292 // based on how many are being consumed by the application and the display plugin. However,
294293 // we will never drop below the 'min' value
295−static const int MIN_PROCESSING_THREAD_POOL_SIZE = 1;
294+static const int MIN_PROCESSING_THREAD_POOL_SIZE = 2;
296295
297296 static const QString SNAPSHOT_EXTENSION = ".jpg";
298297 static const QString JPG_EXTENSION = ".jpg";
@@ -552,13 +551,6 @@ public: · 253 unmodified lines
552551 return true;
553552 }
554553
555− if (message->message == WM_POWERBROADCAST) {
556− if (message->wParam == PBT_APMRESUMEAUTOMATIC) {
557− qCInfo(interfaceapp) << "Waking up from sleep or hybernation.";
558− QMetaObject::invokeMethod(DependencyManager::get<NodeList>().data(), "noteAwakening", Qt::QueuedConnection);
559− }
560− }
561−
562554 if (message->message == WM_COPYDATA) {
563555 COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam);
564556 QUrl url = QUrl((const char*)(pcds->lpData));
@@ -964,9 +956,12 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 399 unmodified lines
964956 DependencyManager::set<KeyboardScriptingInterface>();
965957 DependencyManager::set<GrabManager>();
966958 DependencyManager::set<AvatarPackager>();
967−#ifdef Q_OS_MAC
968− DependencyManager::set<MacHelper>();
969−#endif
959+ PlatformHelper::setup();
960+
961+ QObject::connect(PlatformHelper::instance(), &PlatformHelper::systemWillWake, [] {
962+ QMetaObject::invokeMethod(DependencyManager::get<NodeList>().data(), "noteAwakening", Qt::QueuedConnection);
963+ });
964+
970965
971966 QString setBookmarkValue = getCmdOption(argc, constArgv, "--setBookmark");
972967 if (!setBookmarkValue.isEmpty()) {
@@ -1149,7 +1144,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 176 unmodified lines
11491144 QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "fonts/Graphik-SemiBold.ttf");
11501145 QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "fonts/Graphik-Regular.ttf");
11511146 QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "fonts/Graphik-Medium.ttf");
1152− _window->setWindowTitle("High Fidelity Interface");
1147+ _window->setWindowTitle("High Fidelity");
11531148
11541149 Model::setAbstractViewStateInterface(this); // The model class will sometimes need to know view state details from us
11551150
@@ -1172,6 +1167,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 16 unmodified lines
11721167 deadlockWatchdogThread->setMainThreadID(QThread::currentThreadId());
11731168 deadlockWatchdogThread->start();
11741169
1170+ // Pause the deadlock watchdog when we sleep, or it might
1171+ // trigger a false positive when we wake back up
1172+ auto platformHelper = PlatformHelper::instance();
1173+
1174+ connect(platformHelper, &PlatformHelper::systemWillSleep, [] {
1175+ DeadlockWatchdogThread::pause();
1176+ });
1177+
1178+ connect(platformHelper, &PlatformHelper::systemWillWake, [] {
1179+ DeadlockWatchdogThread::resume();
1180+ });
11751181
11761182 // Main thread timer to keep the watchdog updated
11771183 QTimer* watchdogUpdateTimer = new QTimer(this);
@@ -1225,8 +1231,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 47 unmodified lines
12251231 #endif
12261232
12271233 bool isStore = property(hifi::properties::OCULUS_STORE).toBool();
1228−
1229− DependencyManager::get<WalletScriptingInterface>()->setLimitedCommerce(isStore); // Or we could make it a separate arg, or if either arg is set, etc. And should this instead by a hifi::properties?
1234+ // Or we could make it a separate arg, or if either arg is set, etc. And should this instead by a hifi::properties?
1235+ DependencyManager::get<WalletScriptingInterface>()->setLimitedCommerce(isStore || property(hifi::properties::STEAM).toBool());
12301236
12311237 updateHeartbeat();
12321238
@@ -1659,7 +1665,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 426 unmodified lines
16591665 // The value will be 0 if the user blew away settings this session, which is both a feature and a bug.
16601666 static const QString TESTER = "HIFI_TESTER";
16611667 auto gpuIdent = GPUIdent::getInstance();
1662− auto glContextData = getGLContextData();
1668+ auto glContextData = gl::ContextInfo::get();
16631669 QJsonObject properties = {
16641670 { "version", applicationVersion() },
16651671 { "tester", QProcessEnvironment::systemEnvironment().contains(TESTER) || isTester },
@@ -1676,11 +1682,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 10 unmodified lines
16761682 { "gpu_name", gpuIdent->getName() },
16771683 { "gpu_driver", gpuIdent->getDriver() },
16781684 { "gpu_memory", static_cast<qint64>(gpuIdent->getMemory()) },
1679− { "gl_version_int", glVersionToInteger(glContextData.value("version").toString()) },
1680− { "gl_version", glContextData["version"] },
1681− { "gl_vender", glContextData["vendor"] },
1682− { "gl_sl_version", glContextData["sl_version"] },
1683− { "gl_renderer", glContextData["renderer"] },
1685+ { "gl_version_int", glVersionToInteger(glContextData.version.c_str()) },
1686+ { "gl_version", glContextData.version.c_str() },
1687+ { "gl_vender", glContextData.vendor.c_str() },
1688+ { "gl_sl_version", glContextData.shadingLanguageVersion.c_str() },
1689+ { "gl_renderer", glContextData.renderer.c_str() },
16841690 { "ideal_thread_count", QThread::idealThreadCount() }
16851691 };
16861692 auto macVersion = QSysInfo::macVersion();
@@ -2282,8 +2288,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 595 unmodified lines
22822288 properties["active_display_plugin"] = getActiveDisplayPlugin()->getName();
22832289 properties["using_hmd"] = isHMDMode();
22842290
2285− auto glInfo = getGLContextData();
2286− properties["gl_info"] = glInfo;
2291+ auto contextInfo = gl::ContextInfo::get();
2292+ properties["gl_info"] = QJsonObject{
2293+ { "version", contextInfo.version.c_str() },
2294+ { "sl_version", contextInfo.shadingLanguageVersion.c_str() },
2295+ { "vendor", contextInfo.vendor.c_str() },
2296+ { "renderer", contextInfo.renderer.c_str() },
2297+ };
22872298 properties["gpu_used_memory"] = (int)BYTES_TO_MB(gpu::Context::getUsedGPUMemSize());
22882299 properties["gpu_free_memory"] = (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemSize());
22892300 properties["gpu_frame_time"] = (float)(qApp->getGPUContext()->getFrameTimerGPUAverage());
@@ -2670,6 +2681,8 @@ void Application::updateHeartbeat() const { · 380 unmodified lines
26702681 }
26712682
26722683 void Application::onAboutToQuit() {
2684+ setCrashAnnotation("shutdown", "1");
2685+
26732686 // quickly save AvatarEntityData before the EntityTree is dismantled
26742687 getMyAvatar()->saveAvatarEntityDataToSettings();
26752688
@@ -2708,6 +2721,11 @@ void Application::onAboutToQuit() { · 32 unmodified lines
27082721
27092722 cleanupBeforeQuit();
27102723
2724+ if (_crashOnShutdown) {
2725+ // triggered by crash menu
2726+ crash::nullDeref();
2727+ }
2728+
27112729 getRefreshRateManager().setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::SHUTDOWN);
27122730 }
27132731
@@ -2756,7 +2774,6 @@ void Application::cleanupBeforeQuit() { · 42 unmodified lines
27562774 }
27572775
27582776 getEntities()->shutdown(); // tell the entities system we're shutting down, so it will stop running scripts
2759− getEntities()->clear();
27602777
27612778 // Clear any queued processing (I/O, FBX/OBJ/Texture parsing)
27622779 QThreadPool::globalInstance()->clear();
@@ -2864,9 +2881,7 @@ Application::~Application() { · 101 unmodified lines
28642881 _gameWorkload.shutdown();
28652882
28662883 DependencyManager::destroy<Preferences>();
2867−#ifdef Q_OS_MAC
2868− DependencyManager::destroy<MacHelper>();
2869−#endif
2884+ PlatformHelper::shutdown();
28702885
28712886 _entityClipboard->eraseAllOctreeElements();
28722887 _entityClipboard.reset();
@@ -2996,6 +3011,9 @@ void Application::initializeGL() { · 123 unmodified lines
29963011 qCWarning(interfaceapp, "Unable to make window context current");
29973012 }
29983013
3014+ // Populate the global OpenGL context based on the information for the primary window GL context
3015+ gl::ContextInfo::get(true);
3016+
29993017 #if !defined(DISABLE_QML)
30003018 QStringList chromiumFlags;
30013019 // HACK: re-expose mic and camera to prevent crash on domain-change in chromium's media::FakeAudioInputStream::ReadAudioFromSource()
@@ -3133,7 +3151,7 @@ void Application::showLoginScreen() { · 131 unmodified lines
31333151 QJsonObject loginData = {};
31343152 loginData["action"] = "login dialog popped up";
31353153 UserActivityLogger::getInstance().logAction("encourageLoginDialog", loginData);
3136− _window->setWindowTitle("High Fidelity Interface");
3154+ _window->setWindowTitle("High Fidelity");
31373155 } else {
31383156 resumeAfterLoginDialogActionTaken();
31393157 }
@@ -3268,6 +3286,9 @@ void Application::initializeUi() { · 128 unmodified lines
32683286 }
32693287 return result.toPoint();
32703288 });
3289+
3290+ // BUGZ-1365 - the root context should explicitly default to being unable to load local HTML content
3291+ ContextAwareProfile::restrictContext(offscreenUi->getSurfaceContext(), true);
32713292 offscreenUi->resume();
32723293 #endif
32733294 connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect& r){
@@ -3555,6 +3576,9 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona · 281 unmodified lines
35553576 surfaceContext->setContextProperty("WalletScriptingInterface", DependencyManager::get<WalletScriptingInterface>().data());
35563577 surfaceContext->setContextProperty("ResourceRequestObserver", DependencyManager::get<ResourceRequestObserver>().data());
35573578 surfaceContext->setContextProperty("PlatformInfo", PlatformInfoScriptingInterface::getInstance());
3579+ // This `module` context property is blank for the QML scripting interface so that we don't get log errors when importing
3580+ // certain JS files from both scripts (in the JS context) and QML (in the QML context).
3581+ surfaceContext->setContextProperty("module", "");
35583582 }
35593583 }
35603584
@@ -4228,12 +4252,43 @@ bool Application::event(QEvent* event) { · 667 unmodified lines
42284252 }
42294253
42304254 bool Application::eventFilter(QObject* object, QEvent* event) {
4255+ auto eventType = event->type();
42314256
4232− if (_aboutToQuit && event->type() != QEvent::DeferredDelete && event->type() != QEvent::Destroy) {
4257+ if (_aboutToQuit && eventType != QEvent::DeferredDelete && eventType != QEvent::Destroy) {
42334258 return true;
42344259 }
42354260
4236− auto eventType = event->type();
4261+#if defined(Q_OS_MAC)
4262+ // On Mac OS, Cmd+LeftClick is treated as a RightClick (more specifically, it seems to
4263+ // be Cmd+RightClick without the modifier being dropped). Starting in Qt 5.12, only
4264+ // on Mac, the MouseButtonRelease event for these mouse presses is sent to the top
4265+ // level QWidgetWindow, but are not propagated further. This means that the Application
4266+ // will see a MouseButtonPress, but no MouseButtonRelease, causing the client to get
4267+ // stuck in "mouse-look." The cause of the problem is in the way QWidgetWindow processes
4268+ // events where QMouseEvent::button() is not equal to QMouseEvent::buttons(). In this case
4269+ // QMouseEvent::button() is Qt::RightButton, while QMouseEvent::buttons() is (correctly?)
4270+ // Qt::LeftButton.
4271+ //
4272+ // The change here gets around this problem by capturing these
4273+ // pseudo-RightClicks, and re-emitting them as "pure" RightClicks, where
4274+ // QMouseEvent::button() == QMouseEvent::buttons() == Qt::RightButton.
4275+ //
4276+ if (eventType == QEvent::MouseButtonPress) {
4277+ auto mouseEvent = static_cast<QMouseEvent*>(event);
4278+ if (mouseEvent->button() == Qt::RightButton
4279+ && mouseEvent->buttons() == Qt::LeftButton
4280+ && mouseEvent->modifiers() == Qt::MetaModifier) {
4281+
4282+ QMouseEvent* newEvent = new QMouseEvent(
4283+ QEvent::MouseButtonPress, mouseEvent->localPos(), mouseEvent->windowPos(),
4284+ mouseEvent->screenPos(), Qt::RightButton, Qt::MouseButtons(Qt::RightButton),
4285+ mouseEvent->modifiers());
4286+ QApplication::postEvent(object, newEvent);
4287+ return true;
4288+ }
4289+ }
4290+#endif
4291+
42374292 if (eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease || eventType == QEvent::MouseMove) {
42384293 getRefreshRateManager().resetInactiveTimer();
42394294 }
@@ -4410,8 +4465,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 170 unmodified lines
44104465 } else if (isMeta) {
44114466 auto dialogsManager = DependencyManager::get<DialogsManager>();
44124467 dialogsManager->toggleAddressBar();
4413− } else if (isShifted) {
4414− Menu::getInstance()->triggerOption(MenuOption::LodTools);
44154468 }
44164469 break;
44174470
@@ -6246,11 +6299,13 @@ void Application::tryToEnablePhysics() { · 1828 unmodified lines
62466299 // process octree stats packets are sent in between full sends of a scene (this isn't currently true).
62476300 // We keep physics disabled until we've received a full scene and everything near the avatar in that
62486301 // scene is ready to compute its collision shape.
6249− if (getMyAvatar()->isReadyForPhysics()) {
6302+ auto myAvatar = getMyAvatar();
6303+ if (myAvatar->isReadyForPhysics()) {
6304+ myAvatar->getCharacterController()->setPhysicsEngine(_physicsEngine);
62506305 _octreeProcessor.resetSafeLanding();
62516306 _physicsEnabled = true;
62526307 setIsInterstitialMode(false);
6253− getMyAvatar()->updateMotionBehaviorFromMenu();
6308+ myAvatar->updateMotionBehaviorFromMenu();
62546309 }
62556310 }
62566311 }
@@ -6541,7 +6596,7 @@ void Application::update(float deltaTime) { · 284 unmodified lines
65416596 avatarManager->handleProcessedPhysicsTransaction(transaction);
65426597
65436598 myAvatar->prepareForPhysicsSimulation();
6544− _physicsEngine->enableGlobalContactAddedCallback(myAvatar->isFlying());
6599+ myAvatar->getCharacterController()->preSimulation();
65456600 }
65466601 }
65476602
@@ -6594,6 +6649,7 @@ void Application::update(float deltaTime) { · 46 unmodified lines
65946649
65956650 {
65966651 PROFILE_RANGE(simulation_physics, "MyAvatar");
6652+ myAvatar->getCharacterController()->postSimulation();
65976653 myAvatar->harvestResultsFromPhysicsSimulation(deltaTime);
65986654 }
65996655
@@ -6809,8 +6865,8 @@ void Application::updateRenderArgs(float deltaTime) { · 209 unmodified lines
68096865 _viewFrustum.setProjection(adjustedProjection);
68106866 _viewFrustum.calculate();
68116867 }
6812− appRenderArgs._renderArgs = RenderArgs(_graphicsEngine.getGPUContext(), lodManager->getOctreeSizeScale(),
6813− lodManager->getBoundaryLevelAdjust(), lodManager->getLODAngleHalfTan(), RenderArgs::DEFAULT_RENDER_MODE,
6868+ appRenderArgs._renderArgs = RenderArgs(_graphicsEngine.getGPUContext(), lodManager->getVisibilityDistance(),
6869+ lodManager->getBoundaryLevelAdjust(), lodManager->getLODHalfAngleTan(), RenderArgs::DEFAULT_RENDER_MODE,
68146870 RenderArgs::MONO, RenderArgs::DEFERRED, RenderArgs::RENDER_DEBUG_NONE);
68156871 appRenderArgs._renderArgs._scene = getMain3DScene();
68166872
@@ -7405,7 +7461,7 @@ void Application::addingEntityWithCertificate(const QString& certificateID, cons · 588 unmodified lines
74057461 ledger->updateLocation(certificateID, placeName);
74067462 }
74077463
7408−void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointer scriptEngine) {
7464+void Application::registerScriptEngineWithApplicationServices(const ScriptEnginePointer& scriptEngine) {
74097465
74107466 scriptEngine->setEmitScriptUpdatesFunction([this]() {
74117467 SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
@@ -7444,9 +7500,19 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe · 32 unmodified lines
74447500 qScriptRegisterMetaType(scriptEngine.data(), RayToOverlayIntersectionResultToScriptValue,
74457501 RayToOverlayIntersectionResultFromScriptValue);
74467502
7503+ bool clientScript = scriptEngine->isClientScript();
7504+
74477505 #if !defined(DISABLE_QML)
74487506 scriptEngine->registerGlobalObject("OffscreenFlags", getOffscreenUI()->getFlags());
7449− scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
7507+ if (clientScript) {
7508+ scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
7509+ } else {
7510+ auto desktopScriptingInterface = new DesktopScriptingInterface(nullptr, true);
7511+ scriptEngine->registerGlobalObject("Desktop", desktopScriptingInterface);
7512+ if (QThread::currentThread() != thread()) {
7513+ desktopScriptingInterface->moveToThread(thread());
7514+ }
7515+ }
74507516 #endif
74517517
74527518 qScriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue<ToolbarProxy>, wrapperFromScriptValue<ToolbarProxy>);
@@ -7471,7 +7537,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe · 18 unmodified lines
74717537 scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
74727538 LocationScriptingInterface::locationSetter);
74737539
7474− bool clientScript = scriptEngine->isClientScript();
74757540 scriptEngine->registerFunction("OverlayWindow", clientScript ? QmlWindowClass::constructor : QmlWindowClass::restricted_constructor);
74767541 #if !defined(Q_OS_ANDROID) && !defined(DISABLE_QML)
74777542 scriptEngine->registerFunction("OverlayWebWindow", clientScript ? QmlWebWindowClass::constructor : QmlWebWindowClass::restricted_constructor);
@@ -7789,9 +7854,15 @@ bool Application::askToWearAvatarAttachmentUrl(const QString& url) { · 311 unmodified lines
77897854 return true;
77907855 }
77917856
7792−void Application::replaceDomainContent(const QString& url) {
7857+static const QString CONTENT_SET_NAME_QUERY_PARAM = "name";
7858+
7859+void Application::replaceDomainContent(const QString& url, const QString& itemName) {
77937860 qCDebug(interfaceapp) << "Attempting to replace domain content";
7794− QByteArray urlData(url.toUtf8());
7861+ QUrl msgUrl(url);
7862+ QUrlQuery urlQuery(msgUrl.query());
7863+ urlQuery.addQueryItem(CONTENT_SET_NAME_QUERY_PARAM, itemName);
7864+ msgUrl.setQuery(urlQuery.query(QUrl::QUrl::FullyEncoded));
7865+ QByteArray urlData(msgUrl.toString(QUrl::QUrl::FullyEncoded).toUtf8());
77957866 auto limitedNodeList = DependencyManager::get<NodeList>();
77967867 const auto& domainHandler = limitedNodeList->getDomainHandler();
77977868
@@ -7825,7 +7896,7 @@ bool Application::askToReplaceDomainContent(const QString& url) { · 27 unmodified lines
78257896 QString details;
78267897 if (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes) {
78277898 // Given confirmation, send request to domain server to replace content
7828− replaceDomainContent(url);
7899+ replaceDomainContent(url, QString());
78297900 details = "SuccessfulRequestToReplaceContent";
78307901 } else {
78317902 details = "UserDeclinedToReplaceContent";
@@ -9477,6 +9548,14 @@ void Application::showUrlHandler(const QUrl& url) { · 1645 unmodified lines
94779548 }
94789549 });
94799550 }
9551+
9552+// used to test "shutdown" crash annotation.
9553+void Application::crashOnShutdown() {
9554+ qDebug() << "crashOnShutdown(), ON PURPOSE!";
9555+ _crashOnShutdown = true;
9556+ quit();
9557+}
9558+
94809559 void Application::overrideEntry(){
94819560 _overrideEntry = true;
94829561 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t