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

Commit

Permalink
Add curved display setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Jan 24, 2019
1 parent 2136a60 commit 1f310e8
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 136 deletions.
16 changes: 6 additions & 10 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -327,7 +328,7 @@ public void setMSAALevel(int level) {

public boolean getLayersEnabled() {
if (BuildConfig.FLAVOR_platform.equalsIgnoreCase("oculusvr")) {
return false;
return true;
}
return false;
}
Expand Down Expand Up @@ -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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ struct BrowserWorld::State {
DrawableListPtr drawList;
CameraPtr leftCamera;
CameraPtr rightCamera;
float curvatureRatio;
float cylinderDensity;
float nearClip;
float farClip;
JNIEnv* env;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/BrowserWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions app/src/main/cpp/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/curved_display_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/developer_options_curved_display" />

<org.mozilla.vrbrowser.ui.views.settings.RadioGroupSetting
android:id="@+id/ua_radio"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<item name="browser_children_z_distance" format="float" type="dimen">1.5</item>

<!-- Navigation bar -->
<dimen name="navigation_bar_width">800dp</dimen>
<dimen name="navigation_bar_width">720dp</dimen>
<dimen name="navigation_bar_height">44dp</dimen>
<dimen name="url_bar_item_width">24dp</dimen>
<dimen name="url_bar_last_item_width">44dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="settings_key_msaa" translatable="false">settings_gfx_msaa</string>
<string name="settings_key_audio" translatable="false">settings_audio</string>
<string name="settings_key_voice_search_language" translatable="false">settings_voice_search_language</string>
<string name="settings_key_cylinder_density" translatable="false">settings_cylinder_density</string>
<string name="private_browsing_support_url" translatable="false">https://support.mozilla.org/kb/private-mode-firefox-reality</string>
<string name="settings_key_browser_world_width" translatable="false">settings_browser_world_width</string>
<string name="settings_key_browser_world_height" translatable="false">settings_browser_world_height</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
from being restarted. -->
<string name="restart_later_dialog_button">Restart Later</string>

<!-- This string labels an On/Off switch in the 'Developer Options' dialog
and is used to enable or disable curved display. -->
<string name="developer_options_curved_display">Enable Curved Display</string>

<!-- This string labels an On/Off switch in the 'Developer Options' dialog
and is used to toggle remote debugging of website content in the application. -->
<string name="developer_options_remote_debugging">Enable Remote Debugging</string>
Expand Down

0 comments on commit 1f310e8

Please sign in to comment.