Update the logic used to start / stop the render thread
Currently the render thread is started / stopped when the activity is respectively resumed / paused. However, according to the `GLSurfaceView` documentation, this should be done instead when the activity is started / stopped, so this change updates the start / stop logic for the render thread to match the documentation.
This commit is contained in:
parent
3a8524dd92
commit
f537cdefcf
7 changed files with 98 additions and 57 deletions
|
@ -484,6 +484,14 @@ class Godot(private val context: Context) : SensorEventListener {
|
|||
return containerLayout
|
||||
}
|
||||
|
||||
fun onStart(host: GodotHost) {
|
||||
if (host != primaryHost) {
|
||||
return
|
||||
}
|
||||
|
||||
renderView!!.onActivityStarted()
|
||||
}
|
||||
|
||||
fun onResume(host: GodotHost) {
|
||||
if (host != primaryHost) {
|
||||
return
|
||||
|
@ -528,6 +536,14 @@ class Godot(private val context: Context) : SensorEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
fun onStop(host: GodotHost) {
|
||||
if (host != primaryHost) {
|
||||
return
|
||||
}
|
||||
|
||||
renderView!!.onActivityStopped()
|
||||
}
|
||||
|
||||
fun onDestroy(primaryHost: GodotHost) {
|
||||
if (this.primaryHost != primaryHost) {
|
||||
return
|
||||
|
|
|
@ -270,6 +270,32 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
|
|||
godot.onPause(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (!godot.isInitialized()) {
|
||||
if (null != mDownloaderClientStub) {
|
||||
mDownloaderClientStub.disconnect(getActivity());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
godot.onStop(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (!godot.isInitialized()) {
|
||||
if (null != mDownloaderClientStub) {
|
||||
mDownloaderClientStub.connect(getActivity());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
godot.onStart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
|
|
@ -114,12 +114,30 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView
|
|||
|
||||
@Override
|
||||
public void onActivityPaused() {
|
||||
onPause();
|
||||
queueEvent(() -> {
|
||||
GodotLib.focusout();
|
||||
// Pause the renderer
|
||||
godotRenderer.onActivityPaused();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped() {
|
||||
pauseGLThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed() {
|
||||
onResume();
|
||||
queueEvent(() -> {
|
||||
// Resume the renderer
|
||||
godotRenderer.onActivityResumed();
|
||||
GodotLib.focusin();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted() {
|
||||
resumeGLThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -283,26 +301,4 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView
|
|||
/* Set the renderer responsible for frame rendering */
|
||||
setRenderer(godotRenderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
queueEvent(() -> {
|
||||
// Resume the renderer
|
||||
godotRenderer.onActivityResumed();
|
||||
GodotLib.focusin();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
queueEvent(() -> {
|
||||
GodotLib.focusout();
|
||||
// Pause the renderer
|
||||
godotRenderer.onActivityPaused();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,13 @@ public interface GodotRenderView {
|
|||
void queueOnRenderThread(Runnable event);
|
||||
|
||||
void onActivityPaused();
|
||||
|
||||
void onActivityStopped();
|
||||
|
||||
void onActivityResumed();
|
||||
|
||||
void onActivityStarted();
|
||||
|
||||
void onBackPressed();
|
||||
|
||||
GodotInputHandler getInputHandler();
|
||||
|
|
|
@ -92,12 +92,30 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV
|
|||
|
||||
@Override
|
||||
public void onActivityPaused() {
|
||||
onPause();
|
||||
queueOnVkThread(() -> {
|
||||
GodotLib.focusout();
|
||||
// Pause the renderer
|
||||
mRenderer.onVkPause();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped() {
|
||||
pauseRenderThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted() {
|
||||
resumeRenderThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed() {
|
||||
onResume();
|
||||
queueOnVkThread(() -> {
|
||||
// Resume the renderer
|
||||
mRenderer.onVkResume();
|
||||
GodotLib.focusin();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -211,26 +229,4 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV
|
|||
}
|
||||
return super.onResolvePointerIcon(me, pointerIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
queueOnVkThread(() -> {
|
||||
// Resume the renderer
|
||||
mRenderer.onVkResume();
|
||||
GodotLib.focusin();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
queueOnVkThread(() -> {
|
||||
GodotLib.focusout();
|
||||
// Pause the renderer
|
||||
mRenderer.onVkPause();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ import javax.microedition.khronos.opengles.GL10;
|
|||
* <p>
|
||||
* <h3>Activity Life-cycle</h3>
|
||||
* A GLSurfaceView must be notified when to pause and resume rendering. GLSurfaceView clients
|
||||
* are required to call {@link #onPause()} when the activity stops and
|
||||
* {@link #onResume()} when the activity starts. These calls allow GLSurfaceView to
|
||||
* are required to call {@link #pauseGLThread()} when the activity stops and
|
||||
* {@link #resumeGLThread()} when the activity starts. These calls allow GLSurfaceView to
|
||||
* pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate
|
||||
* the OpenGL display.
|
||||
* <p>
|
||||
|
@ -339,8 +339,8 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||
* setRenderer is called:
|
||||
* <ul>
|
||||
* <li>{@link #getRenderMode()}
|
||||
* <li>{@link #onPause()}
|
||||
* <li>{@link #onResume()}
|
||||
* <li>{@link #pauseGLThread()}
|
||||
* <li>{@link #resumeGLThread()}
|
||||
* <li>{@link #queueEvent(Runnable)}
|
||||
* <li>{@link #requestRender()}
|
||||
* <li>{@link #setRenderMode(int)}
|
||||
|
@ -568,6 +568,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||
}
|
||||
|
||||
|
||||
// -- GODOT start --
|
||||
/**
|
||||
* Pause the rendering thread, optionally tearing down the EGL context
|
||||
* depending upon the value of {@link #setPreserveEGLContextOnPause(boolean)}.
|
||||
|
@ -578,22 +579,23 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||
*
|
||||
* Must not be called before a renderer has been set.
|
||||
*/
|
||||
public void onPause() {
|
||||
protected final void pauseGLThread() {
|
||||
mGLThread.onPause();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes the rendering thread, re-creating the OpenGL context if necessary. It
|
||||
* is the counterpart to {@link #onPause()}.
|
||||
* is the counterpart to {@link #pauseGLThread()}.
|
||||
*
|
||||
* This method should typically be called in
|
||||
* {@link android.app.Activity#onStart Activity.onStart}.
|
||||
*
|
||||
* Must not be called before a renderer has been set.
|
||||
*/
|
||||
public void onResume() {
|
||||
protected final void resumeGLThread() {
|
||||
mGLThread.onResume();
|
||||
}
|
||||
// -- GODOT end --
|
||||
|
||||
/**
|
||||
* Queue a runnable to be run on the GL rendering thread. This can be used
|
||||
|
|
|
@ -99,7 +99,7 @@ open internal class VkSurfaceView(context: Context) : SurfaceView(context), Surf
|
|||
*
|
||||
* Must not be called before a [VkRenderer] has been set.
|
||||
*/
|
||||
open fun onResume() {
|
||||
protected fun resumeRenderThread() {
|
||||
vkThread.onResume()
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ open internal class VkSurfaceView(context: Context) : SurfaceView(context), Surf
|
|||
*
|
||||
* Must not be called before a [VkRenderer] has been set.
|
||||
*/
|
||||
open fun onPause() {
|
||||
protected fun pauseRenderThread() {
|
||||
vkThread.onPause()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue