From 18bb2737b0ba11a66f92dff91e4e1ed98918a7b9 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Tue, 19 Nov 2019 21:42:23 +0100 Subject: [PATCH] Enable software rendering (#2019) (#2184) * Enable software rendering (#2019) * Add a developer setting --- .../mozilla/vrbrowser/VRBrowserActivity.java | 2 ++ .../vrbrowser/browser/SettingsStore.java | 13 +++++++++++++ .../ui/widgets/UISurfaceTextureRenderer.java | 13 +++++++++++-- .../settings/DeveloperOptionsView.java | 19 +++++++++++++++++++ app/src/main/res/layout/options_developer.xml | 6 ++++++ app/src/main/res/values/non_L10n.xml | 1 + app/src/main/res/values/strings.xml | 6 ++++++ 7 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 9e010e91d..0891ce0c3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -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; @@ -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 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 f9b1d85b8..8a52d6384 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java @@ -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; @@ -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; @@ -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); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java index fc6f53c24..cdca45b5a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UISurfaceTextureRenderer.java @@ -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; @@ -62,7 +67,11 @@ Canvas drawBegin() { mSurfaceCanvas = null; if (mSurface != null) { try { - mSurfaceCanvas = mSurface.lockHardwareCanvas(); + if (sUseHarwareAcceleration) { + mSurfaceCanvas = mSurface.lockHardwareCanvas(); + } else { + mSurfaceCanvas = mSurface.lockCanvas(null); + } mSurfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); } catch (Exception e){ diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DeveloperOptionsView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DeveloperOptionsView.java index e7e0aa505..9325ba31d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DeveloperOptionsView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DeveloperOptionsView.java @@ -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; @@ -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 { @@ -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); }; @@ -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); diff --git a/app/src/main/res/layout/options_developer.xml b/app/src/main/res/layout/options_developer.xml index 20524b566..861302e08 100644 --- a/app/src/main/res/layout/options_developer.xml +++ b/app/src/main/res/layout/options_developer.xml @@ -67,6 +67,12 @@ android:layout_height="wrap_content" app:description="@string/developer_options_debug_logging" /> + + settings_key_bookmarks_sync settings_key_history_sync settings_key_whats_new_displayed + settings_key_ui_hardware_acceleration https://github.com/MozillaReality/FirefoxReality/wiki/Environments https://www.mozilla.org/privacy/firefox/ https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&label=browser-firefox-reality&url=%1$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac7526bc5..6d4520937 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -344,6 +344,12 @@ --> Enable Debug Logging + + Enable UI Hardware Acceleration + Enable Servo