From 1f310e886e67f0ca0b88db458e03c924f5f0dd4c Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 24 Jan 2019 17:18:37 +0100 Subject: [PATCH] Add curved display setting --- .../mozilla/vrbrowser/VRBrowserActivity.java | 16 ++- .../vrbrowser/browser/SettingsStore.java | 11 ++- .../vrbrowser/ui/widgets/CurvatureWidget.java | 97 ------------------- .../ui/widgets/WidgetManagerDelegate.java | 1 - .../widgets/options/DisplayOptionsWidget.java | 10 ++ app/src/main/cpp/BrowserWorld.cpp | 20 ++-- app/src/main/cpp/BrowserWorld.h | 2 +- app/src/main/cpp/Widget.cpp | 14 +-- app/src/main/cpp/Widget.h | 2 +- app/src/main/res/layout/options_display.xml | 6 ++ app/src/main/res/values/dimen.xml | 2 +- app/src/main/res/values/non_L10n.xml | 1 + app/src/main/res/values/strings.xml | 4 + 13 files changed, 50 insertions(+), 136 deletions(-) delete mode 100644 app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/CurvatureWidget.java diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 0f8632c18..6625b763b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -46,8 +46,7 @@ import org.mozilla.vrbrowser.telemetry.TelemetryWrapper; import org.mozilla.vrbrowser.ui.OffscreenDisplay; import org.mozilla.vrbrowser.ui.widgets.BookmarkListener; -import org.mozilla.vrbrowser.ui.views.BookmarksView; -import org.mozilla.vrbrowser.ui.widgets.CurvatureWidget; +import org.mozilla.vrbrowser.ui.views.BookmarksView;; import org.mozilla.vrbrowser.ui.widgets.KeyboardWidget; import org.mozilla.vrbrowser.ui.widgets.NavigationBarWidget; import org.mozilla.vrbrowser.ui.widgets.RootWidget; @@ -186,6 +185,7 @@ protected void onCreate(Bundle savedInstanceState) { queueRunnable(() -> createOffscreenDisplay()); final String tempPath = getCacheDir().getAbsolutePath(); queueRunnable(() -> setTemporaryFilePath(tempPath)); + setCylinderDensity(SettingsStore.getInstance(this).getCylinderDensity()); initializeWorld(); // Setup the search engine @@ -236,10 +236,7 @@ protected void initializeWorld() { mTray.addListeners(new TrayListener[]{mWindowWidget, mNavigationBar}); mBookmarksView.addListeners(new BookmarkListener[]{mWindowWidget, mNavigationBar, mTray}); - CurvatureWidget curvature = new CurvatureWidget(this); - curvature.setParentWidget(mTray.getHandle()); - - addWidgets(Arrays.asList(mRootWidget, mWindowWidget, mNavigationBar, mKeyboard, mTray, curvature)); + addWidgets(Arrays.asList(mRootWidget, mWindowWidget, mNavigationBar, mKeyboard, mTray)); } @Override @@ -987,9 +984,8 @@ public void resetUIYaw() { queueRunnable(this::resetUIYawNative); } - @Override - public void setCurvatureRatio(final float aRatio) { - queueRunnable(() -> setCurvatureRatioNative(aRatio)); + public void setCylinderDensity(final float aDensity) { + queueRunnable(() -> setCylinderDensityNative(aDensity)); } private native void addWidgetNative(int aHandle, WidgetPlacement aPlacement); @@ -1008,5 +1004,5 @@ public void setCurvatureRatio(final float aRatio) { private native void resetUIYawNative(); private native void setControllersVisibleNative(boolean aVisible); private native void runCallbackNative(long aCallback); - private native void setCurvatureRatioNative(float aRatio); + private native void setCylinderDensityNative(float aDensity); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java index 89299a8e3..cdfea3c26 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java @@ -55,6 +55,7 @@ SettingsStore getInstance(final @NonNull Context aContext) { public final static float BROWSER_WORLD_HEIGHT_DEFAULT = 2.25f; public final static int MSAA_DEFAULT_LEVEL = 1; public final static boolean AUDIO_ENABLED = false; + public final static float CYLINDER_DENSITY_ENABLED_DEFAULT = 4680.0f; // Enable telemetry by default (opt-out). private final static boolean enableCrashReportingByDefault = false; @@ -327,7 +328,7 @@ public void setMSAALevel(int level) { public boolean getLayersEnabled() { if (BuildConfig.FLAVOR_platform.equalsIgnoreCase("oculusvr")) { - return false; + return true; } return false; } @@ -361,13 +362,13 @@ public void setVoiceSearchLanguage(String language) { editor.commit(); } - public float getCurvatureRatio() { - return mPrefs.getFloat("curvature", 4680.0f / 8000.0f); + public float getCylinderDensity() { + return mPrefs.getFloat(mContext.getString(R.string.settings_key_cylinder_density), 0); } - public void setCurvatureRatio(float aRatio) { + public void setCylinderDensity(float aDensity) { SharedPreferences.Editor editor = mPrefs.edit(); - editor.putFloat("curvature", aRatio); + editor.putFloat(mContext.getString(R.string.settings_key_cylinder_density), aDensity); editor.commit(); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/CurvatureWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/CurvatureWidget.java deleted file mode 100644 index a5474852e..000000000 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/CurvatureWidget.java +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.vrbrowser.ui.widgets; - -import android.content.Context; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; -import android.widget.SeekBar; -import android.widget.TextView; - -import org.mozilla.geckoview.MediaElement; -import org.mozilla.vrbrowser.R; -import org.mozilla.vrbrowser.browser.Media; -import org.mozilla.vrbrowser.browser.SettingsStore; -import org.mozilla.vrbrowser.ui.views.MediaSeekBar; -import org.mozilla.vrbrowser.ui.views.UIButton; -import org.mozilla.vrbrowser.ui.views.VolumeControl; - -public class CurvatureWidget extends UIWidget { - - private static final String LOGTAG = "VRB"; - private SeekBar mSeekBar; - - public CurvatureWidget(Context aContext) { - super(aContext); - initialize(aContext); - } - - public CurvatureWidget(Context aContext, AttributeSet aAttrs) { - super(aContext, aAttrs); - initialize(aContext); - } - - public CurvatureWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) { - super(aContext, aAttrs, aDefStyle); - initialize(aContext); - } - - private void initialize(Context aContext) { - inflate(aContext, R.layout.curvature_controls, this); - - mSeekBar = findViewById(R.id.curvatureSeekBar); - mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - postDelayed(CurvatureWidget.this::notifyCurvature, 100); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - postDelayed(CurvatureWidget.this::notifyCurvature, 100); - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - postDelayed(CurvatureWidget.this::notifyCurvature, 100); - } - }); - float ratio = SettingsStore.getInstance(getContext()).getCurvatureRatio(); - mSeekBar.setProgress((int)(ratio * mSeekBar.getMax())); - mWidgetManager.setCurvatureRatio(ratio); - mSeekBar.setSecondaryProgress((int)(mSeekBar.getMax() * 4680.0f / 8000.0f)); - } - - void notifyCurvature() { - float ratio = (float)mSeekBar.getProgress() / (float) mSeekBar.getMax(); - mWidgetManager.setCurvatureRatio(ratio); - SettingsStore.getInstance(getContext()).setCurvatureRatio(ratio); - } - - @Override - protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { - Context context = getContext(); - aPlacement.width = WidgetPlacement.dpDimension(context, R.dimen.tray_width) * 2; - aPlacement.height = 22; - aPlacement.anchorX = 0.5f; - aPlacement.anchorY = 1.0f; - aPlacement.parentAnchorX = 0.5f; - aPlacement.parentAnchorY = 0.0f; - aPlacement.cylinder = false; - } - - public void setParentWidget(int aHandle) { - mWidgetPlacement.parentHandle = aHandle; - } - - @Override - public void releaseWidget() { - super.releaseWidget(); - } -} 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 0e16409c8..5bd38c8cd 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 @@ -52,5 +52,4 @@ interface WorldClickListener { void removeWorldClickListener(WorldClickListener aListener); boolean isPermissionGranted(@NonNull String permission); void requestPermission(@NonNull String uri, @NonNull String permission, GeckoSession.PermissionDelegate.Callback aCallback); - void setCurvatureRatio(float aRatio); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java index 1edb88c68..f045e46ae 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java @@ -8,6 +8,7 @@ import android.content.Context; import android.util.AttributeSet; import android.view.View; +import android.widget.CompoundButton; import android.widget.ScrollView; import org.mozilla.vrbrowser.R; @@ -19,6 +20,7 @@ import org.mozilla.vrbrowser.ui.views.settings.DoubleEditSetting; import org.mozilla.vrbrowser.ui.views.settings.RadioGroupSetting; import org.mozilla.vrbrowser.ui.views.settings.SingleEditSetting; +import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting; import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; import org.mozilla.vrbrowser.ui.widgets.dialogs.RestartDialogWidget; import org.mozilla.vrbrowser.ui.widgets.UIWidget; @@ -31,6 +33,7 @@ public class DisplayOptionsWidget extends UIWidget implements private AudioEngine mAudio; private UIButton mBackButton; + private SwitchSetting mCurvedDisplaySwitch; private RadioGroupSetting mUaModeRadio; private RadioGroupSetting mMSAARadio; @@ -76,6 +79,13 @@ private void initialize(Context aContext) { } }); + mCurvedDisplaySwitch = findViewById(R.id.curved_display_switch); + mCurvedDisplaySwitch.setChecked(SettingsStore.getInstance(getContext()).getCylinderDensity() > 0.0f); + mCurvedDisplaySwitch.setOnCheckedChangeListener((compoundButton, enabled, apply) -> { + SettingsStore.getInstance(getContext()).setCylinderDensity(enabled ? SettingsStore.CYLINDER_DENSITY_ENABLED_DEFAULT : 0.0f); + showRestartDialog(); + }); + int uaMode = SettingsStore.getInstance(getContext()).getUaMode(); mUaModeRadio = findViewById(R.id.ua_radio); mUaModeRadio.setOnCheckedChangeListener(mUaModeListener); diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index c994431af..579d7ec77 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -151,7 +151,7 @@ struct BrowserWorld::State { DrawableListPtr drawList; CameraPtr leftCamera; CameraPtr rightCamera; - float curvatureRatio; + float cylinderDensity; float nearClip; float farClip; JNIEnv* env; @@ -169,7 +169,7 @@ struct BrowserWorld::State { SplashAnimationPtr splashAnimation; VRVideoPtr vrVideo; - State() : paused(true), glInitialized(false), modelsLoaded(false), env(nullptr), curvatureRatio(0.0f), nearClip(0.1f), + State() : paused(true), glInitialized(false), modelsLoaded(false), env(nullptr), cylinderDensity(0.0f), nearClip(0.1f), farClip(300.0f), activity(nullptr), windowsInitialized(false), exitImmersiveRequested(false), loaderDelay(0) { context = RenderContext::Create(); create = context->GetRenderThreadCreationContext(); @@ -712,7 +712,7 @@ BrowserWorld::AddWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement) { const float worldHeight = worldWidth / aspect; WidgetPtr widget; - if (aPlacement->cylinder && m.device) { + if (aPlacement->cylinder && m.cylinderDensity > 0 && m.device) { VRLayerCylinderPtr layer = m.device->CreateLayerCylinder(textureWidth, textureHeight, VRLayerQuad::SurfaceType::AndroidSurface); CylinderPtr cylinder = Cylinder::Create(m.create, layer); widget = Widget::Create(m.context, aHandle, textureWidth, textureHeight, worldWidth, worldHeight, cylinder); @@ -755,7 +755,7 @@ BrowserWorld::UpdateWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement } widget->SetPlacement(aPlacement); - widget->SetCurvatureRatio(m.curvatureRatio); + widget->SetCylinderDensity(m.cylinderDensity); widget->ToggleWidget(aPlacement->visible); widget->SetSurfaceTextureSize((int32_t)(ceilf(aPlacement->width * aPlacement->density)), (int32_t)(ceilf(aPlacement->height * aPlacement->density))); @@ -930,10 +930,10 @@ BrowserWorld::ResetUIYaw() { } void -BrowserWorld::SetCurvatureRatio(const float aRatio) { - m.curvatureRatio = aRatio; +BrowserWorld::SetCylinderDensity(const float aDensity) { + m.cylinderDensity = aDensity; for (WidgetPtr& widget: m.widgets) { - widget->SetCurvatureRatio(aRatio); + widget->SetCylinderDensity(aDensity); } } @@ -1291,9 +1291,9 @@ JNI_METHOD(void, resetUIYawNative) crow::BrowserWorld::Instance().ResetUIYaw(); } -JNI_METHOD(void, setCurvatureRatioNative) -(JNIEnv* aEnv, jobject, jfloat aRatio) { - crow::BrowserWorld::Instance().SetCurvatureRatio(aRatio); +JNI_METHOD(void, setCylinderDensityNative) +(JNIEnv* aEnv, jobject, jfloat aDensity) { + crow::BrowserWorld::Instance().SetCylinderDensity(aDensity); } diff --git a/app/src/main/cpp/BrowserWorld.h b/app/src/main/cpp/BrowserWorld.h index 6236a4f8d..b2f7d1304 100644 --- a/app/src/main/cpp/BrowserWorld.h +++ b/app/src/main/cpp/BrowserWorld.h @@ -55,7 +55,7 @@ class BrowserWorld { void HideVRVideo(); void SetControllersVisible(const bool aVisible); void ResetUIYaw(); - void SetCurvatureRatio(const float aRatio); + void SetCylinderDensity(const float aDensity); JNIEnv* GetJNIEnv() const; protected: struct State; diff --git a/app/src/main/cpp/Widget.cpp b/app/src/main/cpp/Widget.cpp index 430b73488..6f1ceaea4 100644 --- a/app/src/main/cpp/Widget.cpp +++ b/app/src/main/cpp/Widget.cpp @@ -416,17 +416,11 @@ Widget::HoverExitResize() { } void -Widget::SetCurvatureRatio(const float aRatio) { - if (!m.cylinder) { - return; +Widget::SetCylinderDensity(const float aDensity) { + m.cylinderDensity = aDensity; + if (m.cylinder) { + m.UpdateCylinderMatrix(); } - - const float minDensity = 2000.0f; - const float maxDensity = 8000.0f; - const float t = 1.0f - aRatio; - m.cylinderDensity = minDensity + (maxDensity - minDensity) * t; - - m.UpdateCylinderMatrix(); } Widget::Widget(State& aState, vrb::RenderContextPtr& aContext) : m(aState) { diff --git a/app/src/main/cpp/Widget.h b/app/src/main/cpp/Widget.h index bf267912c..a36158704 100644 --- a/app/src/main/cpp/Widget.h +++ b/app/src/main/cpp/Widget.h @@ -67,7 +67,7 @@ class Widget { bool IsResizing() const; void HandleResize(const vrb::Vector& aPoint, bool aPressed, bool& aResized, bool &aResizeEnded); void HoverExitResize(); - void SetCurvatureRatio(const float aRatio); + void SetCylinderDensity(const float aDensity); protected: struct State; Widget(State& aState, vrb::RenderContextPtr& aContext); diff --git a/app/src/main/res/layout/options_display.xml b/app/src/main/res/layout/options_display.xml index 8404c7a92..2f818155d 100644 --- a/app/src/main/res/layout/options_display.xml +++ b/app/src/main/res/layout/options_display.xml @@ -45,6 +45,12 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + 1.5 - 800dp + 720dp 44dp 24dp 44dp diff --git a/app/src/main/res/values/non_L10n.xml b/app/src/main/res/values/non_L10n.xml index 8af89bb21..c2a08dca7 100644 --- a/app/src/main/res/values/non_L10n.xml +++ b/app/src/main/res/values/non_L10n.xml @@ -25,6 +25,7 @@ settings_gfx_msaa settings_audio settings_voice_search_language + settings_cylinder_density https://support.mozilla.org/kb/private-mode-firefox-reality settings_browser_world_width settings_browser_world_height diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4eee2ad0..1d9223818 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -162,6 +162,10 @@ from being restarted. --> Restart Later + + Enable Curved Display + Enable Remote Debugging