History

Merge branch 'master' into multiSphereAvatar04

luiscuenca committed 7 years ago

Commit cc736492 parents 49659f0 b5a1dc5125 files · +5011 −4152Browse files

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

Unified · Split

interface/src/Application.cpp+166−4
@@ -120,6 +120,7 @@ · 119 unmodified lines
120120 #include <plugins/PluginManager.h>
121121 #include <plugins/PluginUtils.h>
122122 #include <plugins/SteamClientPlugin.h>
123+#include <plugins/OculusPlatformPlugin.h>
123124 #include <plugins/InputConfiguration.h>
124125 #include <RecordingScriptingInterface.h>
125126 #include <render/EngineStats.h>
@@ -151,6 +152,7 @@ · 25 unmodified lines
151152 #include <trackers/EyeTracker.h>
152153 #include <avatars-renderer/ScriptAvatar.h>
153154 #include <RenderableEntityItem.h>
155+#include <RenderableWebEntityItem.h>
154156 #include <model-networking/MaterialCache.h>
155157 #include "recording/ClipCache.h"
156158
@@ -800,7 +802,6 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 643 unmodified lines
800802 if (auto steamClient = pluginManager->getSteamClientPlugin()) {
801803 steamClient->init();
802804 }
803−
804805 PROFILE_SET_THREAD_NAME("Main Thread");
805806
806807 #if defined(Q_OS_WIN)
@@ -2321,6 +2322,76 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 1514 unmodified lines
23212322 return DependencyManager::get<AvatarManager>()->getMyAvatar()->getWorldOrientation() * Vectors::UP;
23222323 });
23232324
2325+ render::entities::WebEntityRenderer::setAcquireWebSurfaceOperator([this](const QString& url, bool htmlContent, QSharedPointer<OffscreenQmlSurface>& webSurface, bool& cachedWebSurface) {
2326+ bool isTablet = url == TabletScriptingInterface::QML;
2327+ if (htmlContent) {
2328+ webSurface = DependencyManager::get<OffscreenQmlSurfaceCache>()->acquire(render::entities::WebEntityRenderer::QML);
2329+ cachedWebSurface = true;
2330+ auto rootItemLoadedFunctor = [url, webSurface] {
2331+ webSurface->getRootItem()->setProperty(render::entities::WebEntityRenderer::URL_PROPERTY, url);
2332+ };
2333+ if (webSurface->getRootItem()) {
2334+ rootItemLoadedFunctor();
2335+ } else {
2336+ QObject::connect(webSurface.data(), &hifi::qml::OffscreenSurface::rootContextCreated, rootItemLoadedFunctor);
2337+ }
2338+ } else {
2339+ // FIXME: the tablet should use the OffscreenQmlSurfaceCache
2340+ webSurface = QSharedPointer<OffscreenQmlSurface>(new OffscreenQmlSurface(), [](OffscreenQmlSurface* webSurface) {
2341+ AbstractViewStateInterface::instance()->sendLambdaEvent([webSurface] {
2342+ // WebEngineView may run other threads (wasapi), so they must be deleted for a clean shutdown
2343+ // if the application has already stopped its event loop, delete must be explicit
2344+ delete webSurface;
2345+ });
2346+ });
2347+ auto rootItemLoadedFunctor = [webSurface, url, isTablet] {
2348+ Application::setupQmlSurface(webSurface->getSurfaceContext(), isTablet || url == OVERLAY_LOGIN_DIALOG.toString());
2349+ };
2350+ if (webSurface->getRootItem()) {
2351+ rootItemLoadedFunctor();
2352+ } else {
2353+ QObject::connect(webSurface.data(), &hifi::qml::OffscreenSurface::rootContextCreated, rootItemLoadedFunctor);
2354+ }
2355+ webSurface->load(url);
2356+ cachedWebSurface = false;
2357+ }
2358+ const uint8_t DEFAULT_MAX_FPS = 10;
2359+ const uint8_t TABLET_FPS = 90;
2360+ webSurface->setMaxFps(isTablet ? TABLET_FPS : DEFAULT_MAX_FPS);
2361+ });
2362+ render::entities::WebEntityRenderer::setReleaseWebSurfaceOperator([this](QSharedPointer<OffscreenQmlSurface>& webSurface, bool& cachedWebSurface, std::vector<QMetaObject::Connection>& connections) {
2363+ QQuickItem* rootItem = webSurface->getRootItem();
2364+
2365+ // Fix for crash in QtWebEngineCore when rapidly switching domains
2366+ // Call stop on the QWebEngineView before destroying OffscreenQMLSurface.
2367+ if (rootItem) {
2368+ // stop loading
2369+ QMetaObject::invokeMethod(rootItem, "stop");
2370+ }
2371+
2372+ webSurface->pause();
2373+
2374+ for (auto& connection : connections) {
2375+ QObject::disconnect(connection);
2376+ }
2377+ connections.clear();
2378+
2379+ // If the web surface was fetched out of the cache, release it back into the cache
2380+ if (cachedWebSurface) {
2381+ // If it's going back into the cache make sure to explicitly set the URL to a blank page
2382+ // in order to stop any resource consumption or audio related to the page.
2383+ if (rootItem) {
2384+ rootItem->setProperty("url", "about:blank");
2385+ }
2386+ auto offscreenCache = DependencyManager::get<OffscreenQmlSurfaceCache>();
2387+ if (offscreenCache) {
2388+ offscreenCache->release(render::entities::WebEntityRenderer::QML, webSurface);
2389+ }
2390+ cachedWebSurface = false;
2391+ }
2392+ webSurface.reset();
2393+ });
2394+
23242395 // Preload Tablet sounds
23252396 DependencyManager::get<TabletScriptingInterface>()->preloadSounds();
23262397 DependencyManager::get<Keyboard>()->createKeyboard();
@@ -2347,7 +2418,6 @@ void Application::updateVerboseLogging() { · 20 unmodified lines
23472418 bool enable = menu->isOptionChecked(MenuOption::VerboseLogging);
23482419
23492420 QString rules =
2350− "hifi.*.debug=%1\n"
23512421 "hifi.*.info=%1\n"
23522422 "hifi.audio-stream.debug=false\n"
23532423 "hifi.audio-stream.info=false";
@@ -2674,6 +2744,7 @@ Application::~Application() { · 320 unmodified lines
26742744 if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
26752745 steamClient->shutdown();
26762746 }
2747+
26772748 DependencyManager::destroy<PluginManager>();
26782749
26792750 DependencyManager::destroy<CompositorHelper>(); // must be destroyed before the FramebufferCache
@@ -3029,7 +3100,7 @@ void Application::initializeUi() { · 349 unmodified lines
30293100 });
30303101
30313102 offscreenSurfaceCache->reserve(TabletScriptingInterface::QML, 1);
3032− offscreenSurfaceCache->reserve(Web3DOverlay::QML, 2);
3103+ offscreenSurfaceCache->reserve(render::entities::WebEntityRenderer::QML, 2);
30333104 #endif
30343105
30353106 flushMenuUpdates();
@@ -3169,6 +3240,61 @@ void Application::onDesktopRootItemCreated(QQuickItem* rootItem) { · 133 unmodified lines
31693240 #endif
31703241 }
31713242
3243+void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditionalContextProperties) {
3244+ surfaceContext->setContextProperty("Users", DependencyManager::get<UsersScriptingInterface>().data());
3245+ surfaceContext->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
3246+ surfaceContext->setContextProperty("UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data());
3247+ surfaceContext->setContextProperty("Preferences", DependencyManager::get<Preferences>().data());
3248+ surfaceContext->setContextProperty("Vec3", new Vec3());
3249+ surfaceContext->setContextProperty("Quat", new Quat());
3250+ surfaceContext->setContextProperty("MyAvatar", DependencyManager::get<AvatarManager>()->getMyAvatar().get());
3251+ surfaceContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
3252+ surfaceContext->setContextProperty("Snapshot", DependencyManager::get<Snapshot>().data());
3253+
3254+ if (setAdditionalContextProperties) {
3255+ auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
3256+ auto flags = tabletScriptingInterface->getFlags();
3257+
3258+ surfaceContext->setContextProperty("offscreenFlags", flags);
3259+ surfaceContext->setContextProperty("AddressManager", DependencyManager::get<AddressManager>().data());
3260+
3261+ surfaceContext->setContextProperty("Settings", SettingsScriptingInterface::getInstance());
3262+ surfaceContext->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance());
3263+ surfaceContext->setContextProperty("KeyboardScriptingInterface", DependencyManager::get<KeyboardScriptingInterface>().data());
3264+
3265+ surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
3266+ surfaceContext->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
3267+ surfaceContext->setContextProperty("AccountServices", AccountServicesScriptingInterface::getInstance());
3268+
3269+ // in Qt 5.10.0 there is already an "Audio" object in the QML context
3270+ // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface"
3271+ surfaceContext->setContextProperty("AudioScriptingInterface", DependencyManager::get<AudioScriptingInterface>().data());
3272+
3273+ surfaceContext->setContextProperty("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());
3274+ surfaceContext->setContextProperty("fileDialogHelper", new FileDialogHelper());
3275+ surfaceContext->setContextProperty("ScriptDiscoveryService", DependencyManager::get<ScriptEngines>().data());
3276+ surfaceContext->setContextProperty("Assets", DependencyManager::get<AssetMappingsScriptingInterface>().data());
3277+ surfaceContext->setContextProperty("LODManager", DependencyManager::get<LODManager>().data());
3278+ surfaceContext->setContextProperty("OctreeStats", DependencyManager::get<OctreeStatsProvider>().data());
3279+ surfaceContext->setContextProperty("DCModel", DependencyManager::get<DomainConnectionModel>().data());
3280+ surfaceContext->setContextProperty("AvatarInputs", AvatarInputs::getInstance());
3281+ surfaceContext->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data());
3282+ surfaceContext->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance());
3283+ surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
3284+ surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
3285+ surfaceContext->setContextProperty("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
3286+ surfaceContext->setContextProperty("Render", AbstractViewStateInterface::instance()->getRenderEngine()->getConfiguration().get());
3287+ surfaceContext->setContextProperty("Workload", qApp->getGameWorkload()._engine->getConfiguration().get());
3288+ surfaceContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
3289+ surfaceContext->setContextProperty("Pointers", DependencyManager::get<PointerScriptingInterface>().data());
3290+ surfaceContext->setContextProperty("Window", DependencyManager::get<WindowScriptingInterface>().data());
3291+ surfaceContext->setContextProperty("Reticle", qApp->getApplicationCompositor().getReticleInterface());
3292+ surfaceContext->setContextProperty("HiFiAbout", AboutUtil::getInstance());
3293+ surfaceContext->setContextProperty("WalletScriptingInterface", DependencyManager::get<WalletScriptingInterface>().data());
3294+ surfaceContext->setContextProperty("ResourceRequestObserver", DependencyManager::get<ResourceRequestObserver>().data());
3295+ }
3296+}
3297+
31723298 void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
31733299 PROFILE_RANGE(render, __FUNCTION__);
31743300 PerformanceTimer perfTimer("updateCamera");
@@ -4755,6 +4881,10 @@ void Application::idle() { · 1580 unmodified lines
47554881 steamClient->runCallbacks();
47564882 }
47574883
4884+ if (auto oculusPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) {
4885+ oculusPlugin->handleOVREvents();
4886+ }
4887+
47584888 float secondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_MSEC / MSECS_PER_SECOND;
47594889 _lastTimeUpdated.start();
47604890
@@ -5939,6 +6069,13 @@ void Application::update(float deltaTime) { · 1178 unmodified lines
59396069
59406070 auto userInputMapper = DependencyManager::get<UserInputMapper>();
59416071
6072+ controller::HmdAvatarAlignmentType hmdAvatarAlignmentType;
6073+ if (myAvatar->getHmdAvatarAlignmentType() == "eyes") {
6074+ hmdAvatarAlignmentType = controller::HmdAvatarAlignmentType::Eyes;
6075+ } else {
6076+ hmdAvatarAlignmentType = controller::HmdAvatarAlignmentType::Head;
6077+ }
6078+
59426079 controller::InputCalibrationData calibrationData = {
59436080 myAvatar->getSensorToWorldMatrix(),
59446081 createMatFromQuatAndPos(myAvatar->getWorldOrientation(), myAvatar->getWorldPosition()),
@@ -5952,7 +6089,8 @@ void Application::update(float deltaTime) { · 7 unmodified lines
59526089 myAvatar->getRightArmCalibrationMat(),
59536090 myAvatar->getLeftArmCalibrationMat(),
59546091 myAvatar->getRightHandCalibrationMat(),
5955− myAvatar->getLeftHandCalibrationMat()
6092+ myAvatar->getLeftHandCalibrationMat(),
6093+ hmdAvatarAlignmentType
59566094 };
59576095
59586096 InputPluginPointer keyboardMousePlugin;
@@ -8117,7 +8255,18 @@ void Application::toggleLogDialog() { · 2158 unmodified lines
81178255 return;
81188256 }
81198257 if (! _logDialog) {
8258+
8259+ bool keepOnTop =_keepLogWindowOnTop.get();
8260+#ifdef Q_OS_WIN
8261+ _logDialog = new LogDialog(keepOnTop ? qApp->getWindow() : nullptr, getLogger());
8262+#else
81208263 _logDialog = new LogDialog(nullptr, getLogger());
8264+
8265+ if (keepOnTop) {
8266+ Qt::WindowFlags flags = _logDialog->windowFlags() | Qt::Tool;
8267+ _logDialog->setWindowFlags(flags);
8268+ }
8269+#endif
81218270 }
81228271
81238272 if (_logDialog->isVisible()) {
@@ -8127,6 +8276,19 @@ void Application::toggleLogDialog() { · 3 unmodified lines
81278276 }
81288277 }
81298278
8279+ void Application::recreateLogWindow(int keepOnTop) {
8280+ _keepLogWindowOnTop.set(keepOnTop != 0);
8281+ if (_logDialog) {
8282+ bool toggle = _logDialog->isVisible();
8283+ _logDialog->close();
8284+ _logDialog = nullptr;
8285+
8286+ if (toggle) {
8287+ toggleLogDialog();
8288+ }
8289+ }
8290+ }
8291+
81308292 void Application::toggleEntityScriptServerLogDialog() {
81318293 if (! _entityScriptServerLogDialog) {
81328294 _entityScriptServerLogDialog = new EntityScriptServerLogDialog(nullptr);

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