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

[3.x] Android: Update the logic used to start / stop the GL thread #86380

Merged
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
34 changes: 27 additions & 7 deletions platform/android/java/lib/src/org/godotengine/godot/Godot.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
Expand All @@ -86,7 +85,6 @@
import android.view.WindowInsets;
import android.view.WindowInsetsAnimation;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
Expand All @@ -97,9 +95,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
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 com.google.android.vending.expansion.downloader.DownloadProgressInfo;
Expand Down Expand Up @@ -894,7 +889,7 @@ public void onPause() {
}
return;
}
mView.onPause();
mView.onActivityPaused();

mSensorManager.unregisterListener(this);

Expand All @@ -906,6 +901,18 @@ public void onPause() {
}
}

@Override
public void onStop() {
super.onStop();
if (!godot_initialized) {
if (null != mDownloaderClientStub) {
mDownloaderClientStub.disconnect(getActivity());
}
return;
}
mView.onActivityStopped();
}

public boolean hasClipboard() {
return mClipboard.hasPrimaryClip();
}
Expand All @@ -925,6 +932,19 @@ public void setClipboard(String p_text) {
mClipboard.setPrimaryClip(clip);
}

@Override
public void onStart() {
super.onStart();
if (!godot_initialized) {
if (null != mDownloaderClientStub) {
mDownloaderClientStub.connect(getActivity());
}
return;
}

mView.onActivityStarted();
}

@Override
public void onResume() {
super.onResume();
Expand All @@ -936,7 +956,7 @@ public void onResume() {
return;
}

mView.onResume();
mView.onActivityResumed();

mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,27 @@ public GodotInputHandler getInputHandler() {
return inputHandler;
}

@Override
public void onResume() {
super.onResume();
void onActivityStarted() {
resumeGLThread();
}

void onActivityResumed() {
queueEvent(() -> {
// Resume the renderer
godotRenderer.onActivityResumed();
GodotLib.focusin();
});
}

@Override
public void onPause() {
super.onPause();

void onActivityPaused() {
queueEvent(() -> {
GodotLib.focusout();
// Pause the renderer
godotRenderer.onActivityPaused();
});
}

void onActivityStopped() {
pauseGLThread();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
* <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>
Expand Down Expand Up @@ -339,8 +339,8 @@ public boolean getPreserveEGLContextOnPause() {
* 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)}
Expand Down Expand Up @@ -568,6 +568,7 @@ public void surfaceRedrawNeeded(SurfaceHolder holder) {
}


// -- GODOT start --
/**
* Pause the rendering thread, optionally tearing down the EGL context
* depending upon the value of {@link #setPreserveEGLContextOnPause(boolean)}.
Expand All @@ -578,22 +579,23 @@ public void surfaceRedrawNeeded(SurfaceHolder holder) {
*
* 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
Expand Down
Loading