Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Force curved mode in multiwindow #1541

Merged
merged 2 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1270,7 +1269,7 @@ public void resetUIYaw() {
public void setCylinderDensity(final float aDensity) {
queueRunnable(() -> setCylinderDensityNative(aDensity));
if (mWindows != null) {
mWindows.onCurvedModeChanged();
mWindows.updateCurvedMode();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -196,6 +197,7 @@ public WindowWidget addWindow() {
updateMaxWindowScales();
mWidgetManager.addWidget(newWindow);
focusWindow(newWindow);
updateCurvedMode();
updateViews();
return newWindow;
}
Expand All @@ -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;
Expand Down Expand Up @@ -354,6 +357,7 @@ public void enterPrivateMode() {
return;
}
mPrivateMode = true;
updateCurvedMode();
for (WindowWidget window: mRegularWindows) {
setWindowVisible(window, false);
}
Expand All @@ -377,6 +381,7 @@ public void exitPrivateMode() {
return;
}
mPrivateMode = false;
updateCurvedMode();
for (WindowWidget window: mRegularWindows) {
setWindowVisible(window, true);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -619,12 +637,6 @@ private WindowWidget createWindow() {
return window;
}

public void onCurvedModeChanged() {
for (WindowWidget window: getCurrentWindows()) {
placeWindow(window, window.getWindowPlacement());
}
updateViews();
}

// Tray Listener
@Override
Expand Down
43 changes: 39 additions & 4 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ struct OculusEyeSwapChain {
class OculusLayer;
typedef std::shared_ptr<OculusLayer> OculusLayerPtr;

struct SurfaceChangedTarget {
OculusLayer * layer;
SurfaceChangedTarget(OculusLayer * aLayer): layer(aLayer) {};
};

typedef std::shared_ptr<SurfaceChangedTarget> SurfaceChangedTargetPtr;
typedef std::weak_ptr<SurfaceChangedTarget> SurfaceChangedTargetWeakPtr;

class OculusLayer {
public:
virtual void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) = 0;
Expand All @@ -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<void(const vrb::FBOPtr&, GLenum aTarget, bool aBound)> BindDelegate;
virtual void SetBindDelegate(const BindDelegate& aDelegate) = 0;
virtual jobject GetSurface() const = 0;
virtual SurfaceChangedTargetPtr GetSurfaceChangedTarget() const = 0;
virtual ~OculusLayer() {}
};

Expand All @@ -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<SurfaceChangedTarget>(this);
SurfaceChangedTargetWeakPtr weakTarget = surfaceChangedTarget;
layer->NotifySurfaceChanged(VRLayer::SurfaceChange::Create, [=]() {
composited = true;
SurfaceChangedTargetPtr target = weakTarget.lock();
if (target) {
target->layer->SetComposited(true);
}
});
}

Expand Down Expand Up @@ -193,6 +210,10 @@ class OculusLayerBase: public OculusLayer {
return composited;
}

void SetComposited(bool aValue) override {
composited = aValue;
}

VRLayerPtr GetLayer() const override {
return layer;
}
Expand All @@ -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() {}
};

Expand Down Expand Up @@ -290,12 +319,18 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
});
}

virtual jobject GetSurface() const override {
return surface;
}

protected:
void TakeSurface(const OculusLayerPtr& aSource) {
this->swapChain = aSource->GetSwapChain();
VRLayerSurfacePtr sourceLayer = std::dynamic_pointer_cast<VRLayerSurface>(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());
Expand Down