From fcef0a7c29ef6dfd148921e0aaeaf10fce21153b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 9 Sep 2024 15:20:04 +0900 Subject: [PATCH] cmd/ebitenmobile: call setPreserveEGLContextOnPause(true) whatever the option is We found that an app freezes for a little while when resuming it. In order to improve user experience, always use setPreserveEGLContextOnPause(true) whichever StrictContextRestoration is true or false. --- cmd/ebitenmobile/_files/EbitenSurfaceView.java | 2 +- run.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/ebitenmobile/_files/EbitenSurfaceView.java b/cmd/ebitenmobile/_files/EbitenSurfaceView.java index 000e5f7db..63a82d995 100644 --- a/cmd/ebitenmobile/_files/EbitenSurfaceView.java +++ b/cmd/ebitenmobile/_files/EbitenSurfaceView.java @@ -96,6 +96,7 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer { private void initialize() { setEGLContextClientVersion(3); setEGLConfigChooser(8, 8, 8, 8, 0, 0); + setPreserveEGLContextOnPause(true); // setRenderer must be called before setRenderRequester. // Or, the application crashes. setRenderer(new EbitenRenderer()); @@ -125,7 +126,6 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer { @Override public synchronized void setStrictContextRestoration(boolean strictContextRestoration) { strictContextRestoration_ = strictContextRestoration; - setPreserveEGLContextOnPause(!strictContextRestoration); } private synchronized boolean hasStrictContextRestoration() { diff --git a/run.go b/run.go index bb97c5c7f..b2bb37143 100644 --- a/run.go +++ b/run.go @@ -302,17 +302,20 @@ type RunGameOptions struct { // // StrictContextRestration is available only on Android. Otherwise, StrictContextRestration is ignored. // - // When StrictContextRestration is false, Ebitengine tries to rely on the OS to restore the context. // In Android, Ebitengien uses `GLSurfaceView`'s `setPreserveEGLContextOnPause(true)`. // This works in most cases, but it is still possible that the context is lost in some minor cases. - // With StrictContextRestration false, the activity's launch mode should be singleInstance, - // or the activity no longer works correctly after the context is lost. // - // When StrictContextRestration is true, Ebitengine tries to restore the context more strictly. - // This is useful when you want to restore the context in any case. + // When StrictContextRestration is true, Ebitengine tries to restore the context more strictly + // for such minor cases. // However, this might cause a performance issue since Ebitengine tries to keep all the information // to restore the context. // + // When StrictContextRestration is false, Ebitengine does nothing special to restore the context and + // relies on the OS's behavior. + // + // As a side note, especially when StrictContextRestration is false, the activity's launch mode should + // be singleInstance, or the activity no longer works correctly after the context is lost. + // // The default (zero) value is false. StrictContextRestration bool }