Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup ProcessStateResumed #1580

Merged
merged 5 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ internal void SwapBuffers()
}
}

private void MakeCurrentContext()
{
if (!_egl.EglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext))
System.Diagnostics.Debug.WriteLine("Error Make Current" + GetErrorAsString());
}

internal void StartGameLoop()
{
_isCancellationRequested = false;
Expand Down Expand Up @@ -214,7 +208,7 @@ void RunStep()
switch (_appState)
{
case AppState.Resumed:
processStateResumed();
ProcessStateResumed();
break;

case AppState.Paused:
Expand All @@ -231,22 +225,11 @@ void RunStep()
return;
}

void processStateResumed()
void ProcessStateResumed()
{
// do not run game if surface is not available
if (_isAndroidSurfaceAvailable)
{
// create surface if context is available
if (_eglContext != null && !_isGLContextLost)
{
if (_eglSurface == null)
{
CreateGLSurface();
BindGLSurfaceGLContext();
GdmResetClientBounds();
}
}

// Restart due to context loss
bool contextLost = false;
if (_isGLContextLost)
Expand Down Expand Up @@ -286,7 +269,8 @@ void processStateResumed()
if (_eglSurface == null)
{
CreateGLSurface();
BindGLSurfaceGLContext();
System.Diagnostics.Debug.Assert(_eglContext != null);
MakeCurrentGLContext();
GdmResetClientBounds();
}

Expand All @@ -303,10 +287,11 @@ void processStateResumed()
}
}

if (_eglContext != null && _eglSurface == null)
if (_eglSurface == null)
{
CreateGLSurface();
BindGLSurfaceGLContext();
System.Diagnostics.Debug.Assert(_eglContext != null);
MakeCurrentGLContext();
GdmResetClientBounds();
}

Expand All @@ -322,8 +307,6 @@ void processStateResumed()

try
{
this.MakeCurrentContext();

var handler = Tick;
if (handler != null)
handler(this, EventArgs.Empty);
Expand Down Expand Up @@ -640,7 +623,7 @@ protected void CreateGLSurface()
}
}

private void BindGLSurfaceGLContext()
private void MakeCurrentGLContext()
{
try
{
Expand Down Expand Up @@ -743,9 +726,9 @@ public override bool OnGenericMotionEvent(MotionEvent e)
#region Properties

private IEGL10 _egl;
private EGLDisplay _eglDisplay;
private GLESVersion _glesVersion;
private EGLConfig _eglConfig;
private EGLDisplay _eglDisplay;
private EGLContext _eglContext;
private EGLSurface _eglSurface;

Expand All @@ -754,9 +737,9 @@ public override bool OnGenericMotionEvent(MotionEvent e)
#region ISurfaceView

IEGL10 ISurfaceView.Egl { get { return _egl; } }
EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } }
GLESVersion ISurfaceView.GLesVersion { get { return _glesVersion; } }
EGLConfig ISurfaceView.EglConfig { get { return _eglConfig; } }
EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } }
EGLContext ISurfaceView.EglContext { get { return _eglContext; } }

#endregion
Expand Down
40 changes: 10 additions & 30 deletions MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ internal void SwapBuffers()
// see: OnFinishFrame.
}

private void MakeCurrentContext()
{
// Surface & GL Context was created by GLSurfaceView.
return;

if (!_egl.EglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext))
System.Diagnostics.Debug.WriteLine("Error Make Current" + GetErrorAsString());
}

internal void StartGameLoop()
{
// Cardboard:
Expand Down Expand Up @@ -165,7 +156,7 @@ void RunStep()
switch (_appState)
{
case AppState.Resumed:
processStateResumed();
ProcessStateResumed();
break;

case AppState.Paused:
Expand All @@ -182,22 +173,11 @@ void RunStep()
return;
}

void processStateResumed()
void ProcessStateResumed()
{
// do not run game if surface is not available
if (_isAndroidSurfaceAvailable)
{
// create surface if context is available
if (_eglContext != null && !_isGLContextLost)
{
if (_eglSurface == null)
{
CreateGLSurface();
BindGLSurfaceGLContext();
GdmResetClientBounds();
}
}

// Restart due to context loss
bool contextLost = false;
if (_isGLContextLost)
Expand Down Expand Up @@ -237,7 +217,8 @@ void processStateResumed()
if (_eglSurface == null)
{
CreateGLSurface();
BindGLSurfaceGLContext();
System.Diagnostics.Debug.Assert(_eglContext != null);
MakeCurrentGLContext();
GdmResetClientBounds();
}

Expand All @@ -254,10 +235,11 @@ void processStateResumed()
}
}

if (_eglContext != null && _eglSurface == null)
if (_eglSurface == null)
{
CreateGLSurface();
BindGLSurfaceGLContext();
System.Diagnostics.Debug.Assert(_eglContext != null);
MakeCurrentGLContext();
GdmResetClientBounds();
}

Expand All @@ -273,8 +255,6 @@ void processStateResumed()

try
{
this.MakeCurrentContext();

var handler = Tick;
if (handler != null)
handler(this, EventArgs.Empty);
Expand Down Expand Up @@ -468,7 +448,7 @@ protected void CreateGLSurface()
}
}

private void BindGLSurfaceGLContext()
private void MakeCurrentGLContext()
{
try
{
Expand Down Expand Up @@ -573,9 +553,9 @@ public override bool OnGenericMotionEvent(MotionEvent e)
#region Properties

private IEGL10 _egl;
private EGLDisplay _eglDisplay;
private GLESVersion _glesVersion;
private EGLConfig _eglConfig;
private EGLDisplay _eglDisplay;
private EGLContext _eglContext;
private EGLSurface _eglSurface;

Expand All @@ -584,9 +564,9 @@ public override bool OnGenericMotionEvent(MotionEvent e)
#region ISurfaceView

IEGL10 ISurfaceView.Egl { get { return _egl; } }
EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } }
GLESVersion ISurfaceView.GLesVersion { get { return _glesVersion; } }
EGLConfig ISurfaceView.EglConfig { get { return _eglConfig; } }
EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } }
EGLContext ISurfaceView.EglContext { get { return _eglContext; } }

#endregion
Expand Down
Loading