summaryrefslogtreecommitdiff
path: root/platform/android/java
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-09-20 23:18:40 +0200
committerGitHub <noreply@github.com>2019-09-20 23:18:40 +0200
commit2e065d8ad07bb20fede0d0c0b2d33d6628033024 (patch)
tree5c962a35deca66b703542bfcb89c3c8ae2263ca0 /platform/android/java
parent42af54ff758d51b212c3b45ed89480f2f51535a2 (diff)
parenta7712cc9e4f0451794ad7eb2685786c0f2e954e7 (diff)
Merge pull request #32064 from m4gr3d/propagate_gl_surface_events
Notify for app pause and resume events on Android
Diffstat (limited to 'platform/android/java')
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.java17
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java12
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java17
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotView.java32
4 files changed, 63 insertions, 15 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
index 7e852b7e08..739aa285bf 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
@@ -669,12 +669,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
return;
}
mView.onPause();
- mView.queueEvent(new Runnable() {
- @Override
- public void run() {
- GodotLib.focusout();
- }
- });
+
mSensorManager.unregisterListener(this);
for (int i = 0; i < singleton_count; i++) {
@@ -703,6 +698,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
@Override
protected void onResume() {
super.onResume();
+ activityResumed = true;
if (!godot_initialized) {
if (null != mDownloaderClientStub) {
mDownloaderClientStub.connect(this);
@@ -711,12 +707,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
}
mView.onResume();
- mView.queueEvent(new Runnable() {
- @Override
- public void run() {
- GodotLib.focusin();
- }
- });
+
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
@@ -737,8 +728,6 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
singletons[i].onMainResume();
}
-
- activityResumed = true;
}
public void UiChangeListener() {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
index af51c840cb..067fa6f4b9 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
@@ -211,4 +211,16 @@ public class GodotLib {
* Invoked on the GL thread to configure the height of the virtual keyboard.
*/
public static native void setVirtualKeyboardHeight(int p_height);
+
+ /**
+ * Invoked on the GL thread when the {@link GodotRenderer} has been resumed.
+ * @see GodotRenderer#onActivityResumed()
+ */
+ public static native void onRendererResumed();
+
+ /**
+ * Invoked on the GL thread when the {@link GodotRenderer} has been paused.
+ * @see GodotRenderer#onActivityPaused()
+ */
+ public static native void onRendererPaused();
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
index 8e3775c2a9..56ba88656e 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
@@ -40,7 +40,14 @@ import org.godotengine.godot.utils.GLUtils;
*/
class GodotRenderer implements GLSurfaceView.Renderer {
+ private boolean activityJustResumed = false;
+
public void onDrawFrame(GL10 gl) {
+ if (activityJustResumed) {
+ GodotLib.onRendererResumed();
+ activityJustResumed = false;
+ }
+
GodotLib.step();
for (int i = 0; i < Godot.singleton_count; i++) {
Godot.singletons[i].onGLDrawFrame(gl);
@@ -58,4 +65,14 @@ class GodotRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
GodotLib.newcontext(GLUtils.use_32);
}
+
+ void onActivityResumed() {
+ // We defer invoking GodotLib.onRendererResumed() until the first draw frame call.
+ // This ensures we have a valid GL context and surface when we do so.
+ activityJustResumed = true;
+ }
+
+ void onActivityPaused() {
+ GodotLib.onRendererPaused();
+ }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotView.java
index fc3e47e69d..5511e5d782 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotView.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotView.java
@@ -68,6 +68,7 @@ public class GodotView extends GLSurfaceView {
private final Godot activity;
private final GodotInputHandler inputHandler;
+ private final GodotRenderer godotRenderer;
public GodotView(Godot activity, XRMode xrMode, boolean p_use_gl3, boolean p_use_32_bits, boolean p_use_debug_opengl) {
super(activity);
@@ -77,6 +78,7 @@ public class GodotView extends GLSurfaceView {
this.activity = activity;
this.inputHandler = new GodotInputHandler(this);
+ this.godotRenderer = new GodotRenderer();
init(xrMode, false, 16, 0);
}
@@ -161,10 +163,38 @@ public class GodotView extends GLSurfaceView {
}
/* Set the renderer responsible for frame rendering */
- setRenderer(new GodotRenderer());
+ setRenderer(godotRenderer);
}
public void onBackPressed() {
activity.onBackPressed();
}
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ // Resume the renderer
+ godotRenderer.onActivityResumed();
+ GodotLib.focusin();
+ }
+ });
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ GodotLib.focusout();
+ // Pause the renderer
+ godotRenderer.onActivityPaused();
+ }
+ });
+ }
}