From 62079de75b5c4befb7590e9ecef08e172c2c0dce Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 8 Aug 2019 17:35:11 +0200 Subject: [PATCH 1/2] Update SurfaceChanged callback target when a Surface is moved to a different layer --- .../oculusvr/cpp/DeviceDelegateOculusVR.cpp | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp index b7386ed7b..9f1f4533d 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp @@ -124,6 +124,14 @@ struct OculusEyeSwapChain { class OculusLayer; typedef std::shared_ptr OculusLayerPtr; +struct SurfaceChangedTarget { + OculusLayer * layer; + SurfaceChangedTarget(OculusLayer * aLayer): layer(aLayer) {}; +}; + +typedef std::shared_ptr SurfaceChangedTargetPtr; +typedef std::weak_ptr SurfaceChangedTargetWeakPtr; + class OculusLayer { public: virtual void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) = 0; @@ -135,10 +143,13 @@ class OculusLayer { virtual bool GetDrawInFront() const = 0; virtual void ClearRequestDraw() = 0; virtual bool IsComposited() const = 0; + virtual void SetComposited(bool aValue) = 0; virtual VRLayerPtr GetLayer() const = 0; virtual void Destroy() = 0; typedef std::function BindDelegate; virtual void SetBindDelegate(const BindDelegate& aDelegate) = 0; + virtual jobject GetSurface() const = 0; + virtual SurfaceChangedTargetPtr GetSurfaceChangedTarget() const = 0; virtual ~OculusLayer() {} }; @@ -147,13 +158,19 @@ class OculusLayerBase: public OculusLayer { public: ovrTextureSwapChain * swapChain = nullptr; bool composited = false; + SurfaceChangedTargetPtr surfaceChangedTarget; T layer; U ovrLayer; void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) override { layer->SetInitialized(true); + surfaceChangedTarget = std::make_shared(this); + SurfaceChangedTargetWeakPtr weakTarget = surfaceChangedTarget; layer->NotifySurfaceChanged(VRLayer::SurfaceChange::Create, [=]() { - composited = true; + SurfaceChangedTargetPtr target = weakTarget.lock(); + if (target) { + target->layer->SetComposited(true); + } }); } @@ -193,6 +210,10 @@ class OculusLayerBase: public OculusLayer { return composited; } + void SetComposited(bool aValue) override { + composited = aValue; + } + VRLayerPtr GetLayer() const override { return layer; } @@ -217,6 +238,14 @@ class OculusLayerBase: public OculusLayer { void SetBindDelegate(const BindDelegate& aDelegate) override {} + jobject GetSurface() const override { + return nullptr; + } + + SurfaceChangedTargetPtr GetSurfaceChangedTarget() const override { + return surfaceChangedTarget; + } + virtual ~OculusLayerBase() {} }; @@ -290,12 +319,18 @@ class OculusLayerSurface: public OculusLayerBase { }); } + virtual jobject GetSurface() const override { + return surface; + } + protected: void TakeSurface(const OculusLayerPtr& aSource) { this->swapChain = aSource->GetSwapChain(); - VRLayerSurfacePtr sourceLayer = std::dynamic_pointer_cast(aSource->GetLayer()); - if (sourceLayer) { - this->surface = sourceLayer->GetSurface(); + this->surface = aSource->GetSurface(); + this->surfaceChangedTarget = aSource->GetSurfaceChangedTarget(); + if (this->surfaceChangedTarget) { + // Indicate that the first composite notification should be notified to this layer. + this->surfaceChangedTarget->layer = this; } this->composited = aSource->IsComposited(); this->layer->SetInitialized(aSource->GetLayer()->IsInitialized()); From 2f64af69dc0b331e11cc88fcd723fa026bc538f8 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 8 Aug 2019 19:00:53 +0200 Subject: [PATCH 2/2] Force curved mode in multiwindow --- .../mozilla/vrbrowser/VRBrowserActivity.java | 3 +- .../mozilla/vrbrowser/ui/widgets/Windows.java | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 4c4f5aa6b..1cb21dfbc 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -237,7 +237,6 @@ protected void onCreate(Bundle savedInstanceState) { queueRunnable(() -> createOffscreenDisplay()); final String tempPath = getCacheDir().getAbsolutePath(); queueRunnable(() -> setTemporaryFilePath(tempPath)); - setCylinderDensity(SettingsStore.getInstance(this).getCylinderDensity()); updateFoveatedLevel(); initializeWidgets(); @@ -1270,7 +1269,7 @@ public void resetUIYaw() { public void setCylinderDensity(final float aDensity) { queueRunnable(() -> setCylinderDensityNative(aDensity)); if (mWindows != null) { - mWindows.onCurvedModeChanged(); + mWindows.updateCurvedMode(); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java index 557cbea2e..328810c2d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java @@ -65,6 +65,7 @@ class WindowsState { public static final int MAX_WINDOWS = 3; private WindowWidget mFullscreenWindow; private WindowPlacement mPrevWindowPlacement; + private boolean mCurvedMode = false; public enum WindowPlacement{ FRONT(0), @@ -196,6 +197,7 @@ public WindowWidget addWindow() { updateMaxWindowScales(); mWidgetManager.addWidget(newWindow); focusWindow(newWindow); + updateCurvedMode(); updateViews(); return newWindow; } @@ -212,6 +214,7 @@ private WindowWidget addWindow(WindowState aState) { newWindow.getPlacement().worldWidth = aState.worldWidth; newWindow.setRestored(true); placeWindow(newWindow, aState.placement); + updateCurvedMode(); mWidgetManager.addWidget(newWindow); return newWindow; @@ -354,6 +357,7 @@ public void enterPrivateMode() { return; } mPrivateMode = true; + updateCurvedMode(); for (WindowWidget window: mRegularWindows) { setWindowVisible(window, false); } @@ -377,6 +381,7 @@ public void exitPrivateMode() { return; } mPrivateMode = false; + updateCurvedMode(); for (WindowWidget window: mRegularWindows) { setWindowVisible(window, true); } @@ -494,6 +499,7 @@ private void removeWindow(@NonNull WindowWidget aWindow) { aWindow.getSessionStack().removeContentListener(this); aWindow.close(); updateMaxWindowScales(); + updateCurvedMode(); if (aWindow.getSessionStack().isPrivateMode()) TelemetryWrapper.openWindowsEvent(mPrivateWindows.size()+1, mPrivateWindows.size(), true); @@ -509,7 +515,6 @@ private void setWindowVisible(@NonNull WindowWidget aWindow, boolean aVisible) { private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPosition) { WidgetPlacement placement = aWindow.getPlacement(); aWindow.setWindowPlacement(aPosition); - boolean curved = SettingsStore.getInstance(mContext).getCylinderDensity() > 0; switch (aPosition) { case FRONT: placement.anchorX = 0.5f; @@ -529,7 +534,7 @@ private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPositio placement.parentAnchorY = 0.0f; placement.rotationAxisX = 0; placement.rotationAxisZ = 0; - if (curved) { + if (mCurvedMode) { placement.rotationAxisY = 0; placement.rotation = 0; } else { @@ -547,7 +552,7 @@ private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPositio placement.parentAnchorY = 0.0f; placement.rotationAxisX = 0; placement.rotationAxisZ = 0; - if (curved) { + if (mCurvedMode) { placement.rotationAxisY = 0; placement.rotation = 0; } else { @@ -561,6 +566,19 @@ private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPositio } } + public void updateCurvedMode() { + float density = SettingsStore.getInstance(mContext).getCylinderDensity(); + boolean curved = getCurrentWindows().size() > 1 || density > 0; + if (curved != mCurvedMode) { + mCurvedMode = curved; + for (WindowWidget window: getCurrentWindows()) { + placeWindow(window, window.getWindowPlacement()); + } + updateViews(); + mWidgetManager.setCylinderDensity(curved ? SettingsStore.CYLINDER_DENSITY_ENABLED_DEFAULT : density); + } + } + private void updateViews() { WindowWidget frontWindow = getFrontWindow(); WindowWidget leftWindow = getLeftWindow(); @@ -619,12 +637,6 @@ private WindowWidget createWindow() { return window; } - public void onCurvedModeChanged() { - for (WindowWidget window: getCurrentWindows()) { - placeWindow(window, window.getWindowPlacement()); - } - updateViews(); - } // Tray Listener @Override