You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
Update the logic used to start / stop the GL thread
Currently the GL 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 GL thread to match the documentation.
This commit is contained in:
@@ -60,7 +60,6 @@ import android.content.pm.ConfigurationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Point;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
@@ -86,7 +85,6 @@ import android.view.Window;
|
|||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
import android.view.WindowInsetsAnimation;
|
import android.view.WindowInsetsAnimation;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
@@ -97,9 +95,6 @@ import androidx.annotation.Keep;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.view.OnApplyWindowInsetsListener;
|
|
||||||
import androidx.core.view.ViewCompat;
|
|
||||||
import androidx.core.view.WindowInsetsCompat;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.google.android.vending.expansion.downloader.DownloadProgressInfo;
|
import com.google.android.vending.expansion.downloader.DownloadProgressInfo;
|
||||||
@@ -894,7 +889,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mView.onPause();
|
mView.onActivityPaused();
|
||||||
|
|
||||||
mSensorManager.unregisterListener(this);
|
mSensorManager.unregisterListener(this);
|
||||||
|
|
||||||
@@ -906,6 +901,18 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
if (!godot_initialized) {
|
||||||
|
if (null != mDownloaderClientStub) {
|
||||||
|
mDownloaderClientStub.disconnect(getActivity());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mView.onActivityStopped();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasClipboard() {
|
public boolean hasClipboard() {
|
||||||
return mClipboard.hasPrimaryClip();
|
return mClipboard.hasPrimaryClip();
|
||||||
}
|
}
|
||||||
@@ -925,6 +932,19 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||||||
mClipboard.setPrimaryClip(clip);
|
mClipboard.setPrimaryClip(clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if (!godot_initialized) {
|
||||||
|
if (null != mDownloaderClientStub) {
|
||||||
|
mDownloaderClientStub.connect(getActivity());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mView.onActivityStarted();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -936,7 +956,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mView.onResume();
|
mView.onActivityResumed();
|
||||||
|
|
||||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||||
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
|
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
|
||||||
|
|||||||
@@ -302,10 +302,11 @@ public class GodotView extends GLSurfaceView {
|
|||||||
return inputHandler;
|
return inputHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void onActivityStarted() {
|
||||||
public void onResume() {
|
resumeGLThread();
|
||||||
super.onResume();
|
}
|
||||||
|
|
||||||
|
void onActivityResumed() {
|
||||||
queueEvent(() -> {
|
queueEvent(() -> {
|
||||||
// Resume the renderer
|
// Resume the renderer
|
||||||
godotRenderer.onActivityResumed();
|
godotRenderer.onActivityResumed();
|
||||||
@@ -313,14 +314,15 @@ public class GodotView extends GLSurfaceView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void onActivityPaused() {
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
|
|
||||||
queueEvent(() -> {
|
queueEvent(() -> {
|
||||||
GodotLib.focusout();
|
GodotLib.focusout();
|
||||||
// Pause the renderer
|
// Pause the renderer
|
||||||
godotRenderer.onActivityPaused();
|
godotRenderer.onActivityPaused();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onActivityStopped() {
|
||||||
|
pauseGLThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,8 +122,8 @@ import javax.microedition.khronos.opengles.GL10;
|
|||||||
* <p>
|
* <p>
|
||||||
* <h3>Activity Life-cycle</h3>
|
* <h3>Activity Life-cycle</h3>
|
||||||
* A GLSurfaceView must be notified when to pause and resume rendering. GLSurfaceView clients
|
* A GLSurfaceView must be notified when to pause and resume rendering. GLSurfaceView clients
|
||||||
* are required to call {@link #onPause()} when the activity stops and
|
* are required to call {@link #pauseGLThread()} when the activity stops and
|
||||||
* {@link #onResume()} when the activity starts. These calls allow GLSurfaceView to
|
* {@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
|
* pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate
|
||||||
* the OpenGL display.
|
* the OpenGL display.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -339,8 +339,8 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
* setRenderer is called:
|
* setRenderer is called:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #getRenderMode()}
|
* <li>{@link #getRenderMode()}
|
||||||
* <li>{@link #onPause()}
|
* <li>{@link #pauseGLThread()}
|
||||||
* <li>{@link #onResume()}
|
* <li>{@link #resumeGLThread()}
|
||||||
* <li>{@link #queueEvent(Runnable)}
|
* <li>{@link #queueEvent(Runnable)}
|
||||||
* <li>{@link #requestRender()}
|
* <li>{@link #requestRender()}
|
||||||
* <li>{@link #setRenderMode(int)}
|
* <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
|
* Pause the rendering thread, optionally tearing down the EGL context
|
||||||
* depending upon the value of {@link #setPreserveEGLContextOnPause(boolean)}.
|
* 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.
|
* Must not be called before a renderer has been set.
|
||||||
*/
|
*/
|
||||||
public void onPause() {
|
protected final void pauseGLThread() {
|
||||||
mGLThread.onPause();
|
mGLThread.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resumes the rendering thread, re-creating the OpenGL context if necessary. It
|
* 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
|
* This method should typically be called in
|
||||||
* {@link android.app.Activity#onStart Activity.onStart}.
|
* {@link android.app.Activity#onStart Activity.onStart}.
|
||||||
*
|
*
|
||||||
* Must not be called before a renderer has been set.
|
* Must not be called before a renderer has been set.
|
||||||
*/
|
*/
|
||||||
public void onResume() {
|
protected final void resumeGLThread() {
|
||||||
mGLThread.onResume();
|
mGLThread.onResume();
|
||||||
}
|
}
|
||||||
|
// -- GODOT end --
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue a runnable to be run on the GL rendering thread. This can be used
|
* Queue a runnable to be run on the GL rendering thread. This can be used
|
||||||
|
|||||||
Reference in New Issue
Block a user