mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
6 Commits
6a51e5b003
...
15dfb02f9f
Author | SHA1 | Date | |
---|---|---|---|
|
15dfb02f9f | ||
|
a786f23e28 | ||
|
2a4374e012 | ||
|
7cc2f8ffcd | ||
|
07d29fa729 | ||
|
fcef0a7c29 |
@ -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();
|
||||||
@ -96,8 +95,8 @@ 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);
|
||||||
// setRenderer must be called before setRenderRequester.
|
setPreserveEGLContextOnPause(true);
|
||||||
// Or, the application crashes.
|
// setRenderer must be called before setRenderer. Or, setRenderMode in setExplicitRenderingMode will crash.
|
||||||
setRenderer(new EbitenRenderer());
|
setRenderer(new EbitenRenderer());
|
||||||
|
|
||||||
Ebitenmobileview.setRenderer(this);
|
Ebitenmobileview.setRenderer(this);
|
||||||
@ -115,6 +114,8 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void setExplicitRenderingMode(boolean explicitRendering) {
|
public synchronized void setExplicitRenderingMode(boolean explicitRendering) {
|
||||||
|
// TODO: Remove this logic when FPSModeVsyncOffMinimum is removed.
|
||||||
|
// This doesn't work when EbitenSurfaceView is recreated anyway.
|
||||||
if (explicitRendering) {
|
if (explicitRendering) {
|
||||||
setRenderMode(RENDERMODE_WHEN_DIRTY);
|
setRenderMode(RENDERMODE_WHEN_DIRTY);
|
||||||
} else {
|
} else {
|
||||||
@ -122,16 +123,6 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void setStrictContextRestoration(boolean strictContextRestoration) {
|
|
||||||
strictContextRestoration_ = strictContextRestoration;
|
|
||||||
setPreserveEGLContextOnPause(!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) {
|
||||||
|
@ -364,10 +364,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setStrictContextRestoration:(BOOL)strictContextRestoration {
|
|
||||||
// Do nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setExplicitRenderingMode:(BOOL)explicitRendering {
|
- (void)setExplicitRenderingMode:(BOOL)explicitRendering {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
explicitRendering_ = explicitRendering;
|
explicitRendering_ = explicitRendering;
|
||||||
|
2
input.go
2
input.go
@ -79,7 +79,7 @@ func KeyName(key Key) string {
|
|||||||
//
|
//
|
||||||
// CursorPosition returns (0, 0) before the main loop on desktops and browsers.
|
// CursorPosition returns (0, 0) before the main loop on desktops and browsers.
|
||||||
//
|
//
|
||||||
// CursorPosition always returns (0, 0) on mobiles.
|
// CursorPosition always returns (0, 0) on mobile native applications.
|
||||||
//
|
//
|
||||||
// CursorPosition is concurrent-safe.
|
// CursorPosition is concurrent-safe.
|
||||||
func CursorPosition() (x, y int) {
|
func CursorPosition() (x, y int) {
|
||||||
|
@ -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()
|
||||||
|
}
|
||||||
|
13
run.go
13
run.go
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user