From 4a975d75488814f7261a8005d8e803b0409b3ecb Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Mon, 4 Feb 2019 10:04:12 +0100 Subject: [PATCH] GeckoView update: switch between Gecko and Servo browserState/Mutex/Cond --- .../mozilla/vrbrowser/VRBrowserActivity.java | 6 +++ .../ui/widgets/WidgetManagerDelegate.java | 1 + .../vrbrowser/ui/widgets/WindowWidget.java | 3 ++ app/src/main/cpp/BrowserWorld.cpp | 9 +++++ app/src/main/cpp/BrowserWorld.h | 1 + app/src/main/cpp/ExternalVR.cpp | 39 +++++++++++++++---- app/src/main/cpp/ExternalVR.h | 5 +++ 7 files changed, 57 insertions(+), 7 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 6da1558dbb..4f0b53d111 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -862,6 +862,11 @@ public void popBackHandler(Runnable aRunnable) { mBackHandlers.removeLastOccurrence(aRunnable); } + @Override + public void setIsServoSession(boolean aIsServo) { + queueRunnable(() -> setIsServo(aIsServo)); + } + @Override public void pushWorldBrightness(Object aKey, float aBrightness) { if (mCurrentBrightness.second != aBrightness) { @@ -999,4 +1004,5 @@ public void resetUIYaw() { private native void resetUIYawNative(); private native void setControllersVisibleNative(boolean aVisible); private native void runCallbackNative(long aCallback); + private native void setIsServo(boolean aIsServo); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java index 5bd38c8cde..9b7f2b4926 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java @@ -38,6 +38,7 @@ interface WorldClickListener { void setTrayVisible(boolean visible); void setControllersVisible(boolean visible); void setWindowSize(float targetWidth, float targetHeight); + void setIsServoSession(boolean aIsServo); void keyboardDismissed(); void updateEnvironment(); void updatePointerColor(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java index 15362ca161..e82d5bf903 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java @@ -31,6 +31,7 @@ import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget; import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget; +import static org.mozilla.vrbrowser.utils.ServoUtils.isInstanceOfServoSession; public class WindowWidget extends UIWidget implements SessionStore.SessionChangeListener, GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, TrayListener, BookmarkListener { @@ -468,6 +469,8 @@ public void onCurrentSessionChange(GeckoSession aSession, int aId) { mDisplay = null; } + mWidgetManager.setIsServoSession(isInstanceOfServoSession(aSession)); + mSessionId = aId; mDisplay = aSession.acquireDisplay(); Log.d(LOGTAG, "surfaceChanged: " + aId); diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index 0c78298906..33454fbc59 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -911,6 +911,11 @@ BrowserWorld::ResetUIYaw() { m.device->SetReorientTransform(matrix); } +void +BrowserWorld::SetIsServo(const bool aIsServo) { + m.externalVR->SetSourceBrowser(aIsServo ? ExternalVR::VRBrowserType::Servo : ExternalVR::VRBrowserType::Gecko); +} + JNIEnv* BrowserWorld::GetJNIEnv() const { ASSERT_ON_RENDER_THREAD(nullptr); @@ -1269,5 +1274,9 @@ JNI_METHOD(void, runCallbackNative) } } +JNI_METHOD(void, setIsServo) +(JNIEnv* aEnv, jboolean aIsServo) { + crow::BrowserWorld::Instance().SetIsServo(aIsServo); +} } // extern "C" diff --git a/app/src/main/cpp/BrowserWorld.h b/app/src/main/cpp/BrowserWorld.h index b86d099849..dee11296a5 100644 --- a/app/src/main/cpp/BrowserWorld.h +++ b/app/src/main/cpp/BrowserWorld.h @@ -55,6 +55,7 @@ class BrowserWorld { void HideVRVideo(); void SetControllersVisible(const bool aVisible); void ResetUIYaw(); + void SetIsServo(const bool aIsServo); JNIEnv* GetJNIEnv() const; protected: struct State; diff --git a/app/src/main/cpp/ExternalVR.cpp b/app/src/main/cpp/ExternalVR.cpp index 2dcb74423d..6ad15b89ff 100644 --- a/app/src/main/cpp/ExternalVR.cpp +++ b/app/src/main/cpp/ExternalVR.cpp @@ -121,6 +121,9 @@ namespace crow { struct ExternalVR::State { static ExternalVR::State * sState; + pthread_mutex_t* browserMutex; + pthread_cond_t* browserCond; + mozilla::gfx::VRBrowserState* sourceBrowserState; mozilla::gfx::VRExternalShmem data; mozilla::gfx::VRSystemState system; mozilla::gfx::VRBrowserState browser; @@ -133,16 +136,20 @@ struct ExternalVR::State { State() : deviceCapabilities(0) { pthread_mutex_init(&data.systemMutex, nullptr); - pthread_mutex_init(&data.browserMutex, nullptr); + pthread_mutex_init(&data.geckoMutex, nullptr); + pthread_mutex_init(&data.servoMutex, nullptr); pthread_cond_init(&data.systemCond, nullptr); - pthread_cond_init(&data.browserCond, nullptr); + pthread_cond_init(&data.geckoCond, nullptr); + pthread_cond_init(&data.servoCond, nullptr); } ~State() { pthread_mutex_destroy(&(data.systemMutex)); - pthread_mutex_destroy(&(data.browserMutex)); + pthread_mutex_destroy(&(data.geckoMutex)); + pthread_mutex_destroy(&(data.servoMutex)); pthread_cond_destroy(&(data.systemCond)); - pthread_cond_destroy(&(data.browserCond)); + pthread_cond_destroy(&(data.geckoCond)); + pthread_cond_destroy(&(data.servoCond)); } void Reset() { @@ -160,6 +167,7 @@ struct ExternalVR::State { lastFrameId = 0; firstPresentingFrame = false; waitingForExit = false; + SetSourceBrowser(VRBrowserType::Gecko); } static ExternalVR::State& Instance() { @@ -172,7 +180,7 @@ struct ExternalVR::State { void PullBrowserStateWhileLocked() { const bool wasPresenting = IsPresenting(); - memcpy(&browser, &data.browserState, sizeof(mozilla::gfx::VRBrowserState)); + memcpy(&browser, sourceBrowserState, sizeof(mozilla::gfx::VRBrowserState)); if ((!wasPresenting && IsPresenting()) || browser.navigationTransitionActive) { @@ -187,6 +195,18 @@ struct ExternalVR::State { bool IsPresenting() const { return browser.presentationActive || browser.navigationTransitionActive || browser.layerState[0].type == mozilla::gfx::VRLayerType::LayerType_Stereo_Immersive; } + + void SetSourceBrowser(VRBrowserType aBrowser) { + if (aBrowser == VRBrowserType::Gecko) { + browserCond = &data.geckoCond; + browserMutex = &data.geckoMutex; + sourceBrowserState = &data.geckoState; + } else { + browserCond = &data.servoCond; + browserMutex = &data.servoMutex; + sourceBrowserState = &data.servoState; + } + } }; ExternalVR::State * ExternalVR::State::sState = nullptr; @@ -283,12 +303,17 @@ ExternalVR::PushSystemState() { void ExternalVR::PullBrowserState() { - Lock lock(m.data.browserMutex); + Lock lock(*m.browserMutex); if (lock.IsLocked()) { m.PullBrowserStateWhileLocked(); } } +void +ExternalVR::SetSourceBrowser(VRBrowserType aBrowser) { + m.SetSourceBrowser(aBrowser); +} + void ExternalVR::SetCompositorEnabled(bool aEnabled) { if (aEnabled == m.compositorEnabled) { @@ -409,7 +434,7 @@ ExternalVR::PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector< bool ExternalVR::WaitFrameResult() { - Wait wait(m.data.browserMutex, m.data.browserCond); + Wait wait(*m.browserMutex, *m.browserCond); wait.Lock(); // browserMutex is locked in wait.lock(). m.PullBrowserStateWhileLocked(); diff --git a/app/src/main/cpp/ExternalVR.h b/app/src/main/cpp/ExternalVR.h index 86556ba51b..78a4940230 100644 --- a/app/src/main/cpp/ExternalVR.h +++ b/app/src/main/cpp/ExternalVR.h @@ -29,6 +29,10 @@ class ExternalVR : public ImmersiveDisplay { LinkTraversal, Rendering }; + enum class VRBrowserType { + Gecko, + Servo + }; static ExternalVRPtr Create(); mozilla::gfx::VRExternalShmem* GetSharedData(); // DeviceDisplay interface @@ -51,6 +55,7 @@ class ExternalVR : public ImmersiveDisplay { bool WaitFrameResult(); void GetFrameResult(int32_t& aSurfaceHandle, device::EyeRect& aLeftEye, device::EyeRect& aRightEye) const; void StopPresenting(); + void SetSourceBrowser(VRBrowserType aBrowser); ~ExternalVR(); protected: struct State;