Skip to content

Commit

Permalink
Ported: Update the logic used to start / stop the GL thread
Browse files Browse the repository at this point in the history
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.
- m4gr3d
godotengine/godot@194452b
  • Loading branch information
Relintai committed Feb 8, 2024
1 parent da41965 commit deec900
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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 @@ -75,7 +74,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 @@ -86,9 +84,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 @@ -919,7 +914,8 @@ public void onPause() {
}
return;
}
mView.onPause();

mView.onActivityPaused();

mSensorManager.unregisterListener(this);

Expand All @@ -931,6 +927,18 @@ public void onPause() {
}
}

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

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

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

mView.onActivityStarted();
}

@Override
public void onResume() {
super.onResume();
Expand All @@ -961,7 +982,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 @@ -284,25 +284,27 @@ public PandemoniumInputHandler getInputHandler() {
return inputHandler;
}

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

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

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

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

void onActivityStopped() {
pauseGLThread();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,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 @@ -489,6 +489,7 @@ public void requestFramebufferSwap() {
mGLThread.requestFramebufferSwap();
}

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

0 comments on commit deec900

Please sign in to comment.