Skip to content

Commit

Permalink
Add a developer setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and bluemarvin committed Nov 19, 2019
1 parent f11213d commit 3a3eeca
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
Expand Up @@ -59,6 +59,7 @@
import org.mozilla.vrbrowser.ui.widgets.NavigationBarWidget;
import org.mozilla.vrbrowser.ui.widgets.RootWidget;
import org.mozilla.vrbrowser.ui.widgets.TrayWidget;
import org.mozilla.vrbrowser.ui.widgets.UISurfaceTextureRenderer;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.Widget;
Expand Down Expand Up @@ -280,6 +281,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

protected void initializeWidgets() {
UISurfaceTextureRenderer.setUseHardwareAcceleration(SettingsStore.getInstance(getBaseContext()).isUIHardwareAccelerationEnabled());
mWindows = new Windows(this);
mWindows.setDelegate(new Windows.Delegate() {
@Override
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.widgets.UISurfaceTextureRenderer;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.LocaleUtils;
import org.mozilla.vrbrowser.utils.StringUtils;
Expand Down Expand Up @@ -48,6 +49,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean CONSOLE_LOGS_DEFAULT = false;
public final static boolean ENV_OVERRIDE_DEFAULT = false;
public final static boolean MULTIPROCESS_DEFAULT = true;
public final static boolean UI_HARDWARE_ACCELERATION_DEFAULT = false;
public final static boolean PERFORMANCE_MONITOR_DEFAULT = true;
public final static boolean DRM_PLAYBACK_DEFAULT = false;
public final static boolean TRACKING_DEFAULT = true;
Expand Down Expand Up @@ -234,6 +236,17 @@ public void setMultiprocessEnabled(boolean isEnabled) {
editor.commit();
}

public boolean isUIHardwareAccelerationEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_ui_hardware_acceleration), UI_HARDWARE_ACCELERATION_DEFAULT);
}

public void setUIHardwareAccelerationEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_ui_hardware_acceleration), isEnabled);
editor.commit();
}

public boolean isPerformanceMonitorEnabled() {
// Disabling Performance Monitor until it can properly handle multi-window
return false; // mPrefs.getBoolean(mContext.getString(R.string.settings_key_performance_monitor), PERFORMANCE_MONITOR_DEFAULT);
Expand Down
Expand Up @@ -12,12 +12,17 @@
import android.graphics.SurfaceTexture;
import android.view.Surface;

class UISurfaceTextureRenderer {
public class UISurfaceTextureRenderer {
private int mTextureWidth;
private int mTextureHeight;
private SurfaceTexture mSurfaceTexture;
private Surface mSurface;
private Canvas mSurfaceCanvas;
private static boolean sUseHarwareAcceleration;

public static void setUseHardwareAcceleration(boolean aEnabled) {
sUseHarwareAcceleration = aEnabled;
}

UISurfaceTextureRenderer(SurfaceTexture aTexture, int aWidth, int aHeight) {
mTextureWidth = aWidth;
Expand Down Expand Up @@ -62,7 +67,11 @@ Canvas drawBegin() {
mSurfaceCanvas = null;
if (mSurface != null) {
try {
mSurfaceCanvas = mSurface.lockCanvas(null);
if (sUseHarwareAcceleration) {
mSurfaceCanvas = mSurface.lockHardwareCanvas();
} else {
mSurfaceCanvas = mSurface.lockCanvas(null);
}
mSurfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
}
catch (Exception e){
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.OptionsDeveloperBinding;
import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting;
import org.mozilla.vrbrowser.ui.widgets.UISurfaceTextureRenderer;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;

import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;
Expand Down Expand Up @@ -59,6 +60,9 @@ private void initialize(Context aContext) {
// Hide Performance Monitor switch until it can handle multiple windows.
mBinding.performanceMonitorSwitch.setVisibility(View.GONE);

mBinding.hardwareAccelerationSwitch.setOnCheckedChangeListener(mUIHardwareAccelerationListener);
setUIHardwareAcceleration(SettingsStore.getInstance(getContext()).isUIHardwareAccelerationEnabled(), false);

if (BuildConfig.DEBUG) {
mBinding.debugLoggingSwitch.setVisibility(View.GONE);
} else {
Expand Down Expand Up @@ -94,6 +98,10 @@ private void initialize(Context aContext) {
setDebugLogging(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mUIHardwareAccelerationListener = (compoundButton, value, doApply) -> {
setUIHardwareAcceleration(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mServoListener = (compoundButton, b, doApply) -> {
setServo(b, true);
};
Expand Down Expand Up @@ -164,6 +172,17 @@ private void setMultiprocess(boolean value, boolean doApply) {
}
}

private void setUIHardwareAcceleration(boolean value, boolean doApply) {
mBinding.hardwareAccelerationSwitch.setOnCheckedChangeListener(null);
mBinding.hardwareAccelerationSwitch.setValue(value, false);
mBinding.hardwareAccelerationSwitch.setOnCheckedChangeListener(mUIHardwareAccelerationListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setUIHardwareAccelerationEnabled(value);
showRestartDialog();
}
}

private void setPerformance(boolean value, boolean doApply) {
mBinding.performanceMonitorSwitch.setOnCheckedChangeListener(null);
mBinding.performanceMonitorSwitch.setValue(value, false);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_developer.xml
Expand Up @@ -67,6 +67,12 @@
android:layout_height="wrap_content"
app:description="@string/developer_options_debug_logging" />

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

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/servo_switch"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Expand Up @@ -49,6 +49,7 @@
<string name="settings_key_bookmarks_sync" translatable="false">settings_key_bookmarks_sync</string>
<string name="settings_key_history_sync" translatable="false">settings_key_history_sync</string>
<string name="settings_key_whats_new_displayed" translatable="false">settings_key_whats_new_displayed</string>
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -344,6 +344,12 @@
-->
<string name="developer_options_debug_logging">Enable Debug Logging</string>

<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
UI render mode. If enables it uses hardware acceleration which should be faster but it may be more unstable.
If disabled it uses software rendering which is stable but not as performant as hardware acceleration
-->
<string name="hardware_acceleration_switch">Enable UI Hardware Acceleration</string>

<!-- The string labels an On/Off switch in the developer options dialog and is used to toggle enabling Servo. -->
<string name="developer_options_servo">Enable Servo</string>

Expand Down

0 comments on commit 3a3eeca

Please sign in to comment.