From 0a1b8a419e87c8846717156b0e5775ada5c0ea5b Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Fri, 10 Jan 2020 20:34:05 +0100 Subject: [PATCH] Enable hardware renderer and don't draw after onStop/onDestroy (#2482) --- .../org/mozilla/vrbrowser/VRBrowserActivity.java | 3 +++ .../org/mozilla/vrbrowser/browser/SettingsStore.java | 2 +- .../ui/widgets/UISurfaceTextureRenderer.java | 11 +++++++++++ app/src/main/res/values/non_L10n.xml | 2 +- 4 files changed, 16 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 b097ba535..707fb33e7 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -273,6 +273,7 @@ protected void onCreate(Bundle savedInstanceState) { protected void initializeWidgets() { UISurfaceTextureRenderer.setUseHardwareAcceleration(SettingsStore.getInstance(getBaseContext()).isUIHardwareAccelerationEnabled()); + UISurfaceTextureRenderer.setRenderActive(true); mWindows = new Windows(this); mWindows.setDelegate(new Windows.Delegate() { @Override @@ -360,6 +361,7 @@ protected void onStart() { SettingsStore.getInstance(getBaseContext()).setPid(Process.myPid()); super.onStart(); TelemetryWrapper.start(); + UISurfaceTextureRenderer.setRenderActive(true); } @Override @@ -369,6 +371,7 @@ protected void onStop() { TelemetryWrapper.stop(); GleanMetricsService.sessionStop(); + UISurfaceTextureRenderer.setRenderActive(false); } @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 44e432e55..0b99e4a11 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java @@ -51,7 +51,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 UI_HARDWARE_ACCELERATION_DEFAULT = true; public final static boolean PERFORMANCE_MONITOR_DEFAULT = true; public final static boolean DRM_PLAYBACK_DEFAULT = false; public final static boolean TRACKING_DEFAULT = true; 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 cdca45b5a..df45f433f 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,6 +12,8 @@ import android.graphics.SurfaceTexture; import android.view.Surface; +import androidx.annotation.Nullable; + public class UISurfaceTextureRenderer { private int mTextureWidth; private int mTextureHeight; @@ -19,11 +21,16 @@ public class UISurfaceTextureRenderer { private Surface mSurface; private Canvas mSurfaceCanvas; private static boolean sUseHarwareAcceleration; + private static boolean sRenderActive = true; public static void setUseHardwareAcceleration(boolean aEnabled) { sUseHarwareAcceleration = aEnabled; } + public static void setRenderActive(boolean aActive) { + sRenderActive = aActive; + } + UISurfaceTextureRenderer(SurfaceTexture aTexture, int aWidth, int aHeight) { mTextureWidth = aWidth; mTextureHeight = aHeight; @@ -63,8 +70,12 @@ void release() { mSurfaceTexture = null; } + @Nullable Canvas drawBegin() { mSurfaceCanvas = null; + if (!sRenderActive) { + return null; + } if (mSurface != null) { try { if (sUseHarwareAcceleration) { diff --git a/app/src/main/res/values/non_L10n.xml b/app/src/main/res/values/non_L10n.xml index ff04196dd..fbb97a183 100644 --- a/app/src/main/res/values/non_L10n.xml +++ b/app/src/main/res/values/non_L10n.xml @@ -49,7 +49,7 @@ settings_key_bookmarks_sync settings_key_history_sync settings_key_whats_new_displayed - settings_key_ui_hardware_acceleration + settings_key_ui_hardware_acceleration_v2 settings_key_fxa_last_sync settings_key_restore_tabs https://github.com/MozillaReality/FirefoxReality/wiki/Environments