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.
This commit is contained in:
Hajime Hoshi 2024-09-09 15:20:04 +09:00
parent 6a51e5b003
commit fcef0a7c29
2 changed files with 9 additions and 6 deletions

View File

@ -96,6 +96,7 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
private void initialize() { private void initialize() {
setEGLContextClientVersion(3); setEGLContextClientVersion(3);
setEGLConfigChooser(8, 8, 8, 8, 0, 0); setEGLConfigChooser(8, 8, 8, 8, 0, 0);
setPreserveEGLContextOnPause(true);
// setRenderer must be called before setRenderRequester. // setRenderer must be called before setRenderRequester.
// Or, the application crashes. // Or, the application crashes.
setRenderer(new EbitenRenderer()); setRenderer(new EbitenRenderer());
@ -125,7 +126,6 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
@Override @Override
public synchronized void setStrictContextRestoration(boolean strictContextRestoration) { public synchronized void setStrictContextRestoration(boolean strictContextRestoration) {
strictContextRestoration_ = strictContextRestoration; strictContextRestoration_ = strictContextRestoration;
setPreserveEGLContextOnPause(!strictContextRestoration);
} }
private synchronized boolean hasStrictContextRestoration() { private synchronized boolean hasStrictContextRestoration() {

13
run.go
View File

@ -302,17 +302,20 @@ type RunGameOptions struct {
// //
// StrictContextRestration is available only on Android. Otherwise, StrictContextRestration is ignored. // 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)`. // 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. // 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. // 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. // for such minor cases.
// However, this might cause a performance issue since Ebitengine tries to keep all the information // However, this might cause a performance issue since Ebitengine tries to keep all the information
// to restore the context. // 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. // The default (zero) value is false.
StrictContextRestration bool StrictContextRestration bool
} }