mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-09 20:47:26 +01:00
cmd/ebitenmobile: bug fix: consider EbitenSurfaceView recreation
On Android Emulator (Small Desktop API 32), EbitenRenderer can be easily recreated by resizing the window. Thus, EbitenRenderer should not have any flags like strictContextRestoration. Also, the flag onceSurfaceCreated_ doesn't work there.
This commit is contained in:
parent
fcef0a7c29
commit
07d29fa729
@ -59,12 +59,13 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||||
if (!onceSurfaceCreated_) {
|
// As EbitenSurfaceView can be recreated anytime, this flag for strict context restoration must be checked every time.
|
||||||
onceSurfaceCreated_ = true;
|
if (Ebitenmobileview.usesStrictContextRestoration()) {
|
||||||
|
Ebitenmobileview.onContextLost();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (hasStrictContextRestoration()) {
|
if (!onceSurfaceCreated_) {
|
||||||
Ebitenmobileview.onContextLost();
|
onceSurfaceCreated_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
contextLost_ = true;
|
contextLost_ = true;
|
||||||
@ -81,8 +82,6 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean strictContextRestoration_ = false;
|
|
||||||
|
|
||||||
public EbitenSurfaceView(Context context) {
|
public EbitenSurfaceView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
initialize();
|
initialize();
|
||||||
@ -123,15 +122,6 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void setStrictContextRestoration(boolean strictContextRestoration) {
|
|
||||||
strictContextRestoration_ = strictContextRestoration;
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized boolean hasStrictContextRestoration() {
|
|
||||||
return strictContextRestoration_;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void requestRenderIfNeeded() {
|
public synchronized void requestRenderIfNeeded() {
|
||||||
if (getRenderMode() == RENDERMODE_WHEN_DIRTY) {
|
if (getRenderMode() == RENDERMODE_WHEN_DIRTY) {
|
||||||
|
@ -101,7 +101,7 @@ type userInterfaceImpl struct {
|
|||||||
fpsMode atomic.Int32
|
fpsMode atomic.Int32
|
||||||
renderer Renderer
|
renderer Renderer
|
||||||
|
|
||||||
strictContextRestoration bool
|
strictContextRestoration atomic.Bool
|
||||||
strictContextRestorationOnce sync.Once
|
strictContextRestorationOnce sync.Once
|
||||||
|
|
||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
@ -156,11 +156,11 @@ func (u *UserInterface) runMobile(game Game, options *RunOptions) (err error) {
|
|||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
u.setGraphicsLibrary(lib)
|
u.setGraphicsLibrary(lib)
|
||||||
close(u.graphicsLibraryInitCh)
|
close(u.graphicsLibraryInitCh)
|
||||||
u.strictContextRestoration = options.StrictContextRestoration
|
if options.StrictContextRestoration {
|
||||||
if !u.strictContextRestoration {
|
u.strictContextRestoration.Store(true)
|
||||||
|
} else {
|
||||||
restorable.Disable()
|
restorable.Disable()
|
||||||
}
|
}
|
||||||
u.renderer.SetStrictContextRestoration(u.strictContextRestoration)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if err := u.update(); err != nil {
|
if err := u.update(); err != nil {
|
||||||
@ -312,7 +312,6 @@ func (u *UserInterface) UpdateInput(keys map[Key]struct{}, runes []rune, touches
|
|||||||
|
|
||||||
type Renderer interface {
|
type Renderer interface {
|
||||||
SetExplicitRenderingMode(explicitRendering bool)
|
SetExplicitRenderingMode(explicitRendering bool)
|
||||||
SetStrictContextRestoration(strictContextRestoration bool)
|
|
||||||
RequestRenderIfNeeded()
|
RequestRenderIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,6 +330,10 @@ func (u *UserInterface) updateIconIfNeeded() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UserInterface) UsesStrictContextRestoration() bool {
|
||||||
|
return u.strictContextRestoration.Load()
|
||||||
|
}
|
||||||
|
|
||||||
func IsScreenTransparentAvailable() bool {
|
func IsScreenTransparentAvailable() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -132,3 +132,7 @@ func SetRenderer(renderer Renderer) {
|
|||||||
func SetSetGameNotifier(setGameNotifier SetGameNotifier) {
|
func SetSetGameNotifier(setGameNotifier SetGameNotifier) {
|
||||||
theState.setSetGameNotifier(setGameNotifier)
|
theState.setSetGameNotifier(setGameNotifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UsesStrictContextRestoration() bool {
|
||||||
|
return ui.Get().UsesStrictContextRestoration()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user