Implement ServoSurface::onSurfaceChanged

This commit is contained in:
Paul Rouget 2019-01-30 07:40:37 +01:00
parent 8646d7dbbc
commit c146653707
2 changed files with 24 additions and 3 deletions

View file

@ -26,6 +26,7 @@ public class Servo {
private boolean mShuttingDown;
private boolean mShutdownComplete;
private boolean mSuspended;
private Callbacks mServoCallbacks;
public Servo(
ServoOptions options,
@ -38,10 +39,10 @@ public class Servo {
mAssetMgr = activity.getResources().getAssets();
Callbacks cbs = new Callbacks(client, gfxcb);
mServoCallbacks = new Callbacks(client, gfxcb);
mRunCallback.inGLThread(() -> {
mJNI.init(activity, options, cbs);
mJNI.init(activity, options, mServoCallbacks);
});
try {
@ -51,6 +52,10 @@ public class Servo {
}
}
public void resetGfxCallbacks(GfxCallbacks gfxcb) {
mServoCallbacks.resetGfxCallbacks(gfxcb);
}
public void shutdown() {
mShuttingDown = true;
FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() {
@ -198,7 +203,7 @@ public class Servo {
private class Callbacks implements JNIServo.Callbacks, Client {
private final GfxCallbacks mGfxCb;
private GfxCallbacks mGfxCb;
Client mClient;
Callbacks(Client client, GfxCallbacks gfxcb) {
@ -206,6 +211,10 @@ public class Servo {
mGfxCb = gfxcb;
}
private void resetGfxCallbacks(GfxCallbacks gfxcb) {
mGfxCb = gfxcb;
}
public void wakeup() {
if (!mSuspended && !mShuttingDown) {
mRunCallback.inGLThread(() -> mJNI.performUpdates());

View file

@ -51,6 +51,11 @@ public class ServoSurface {
mGLThread = new GLThread();
}
public void onSurfaceChanged(Surface surface) {
mASurface = surface;
mGLThread.onSurfaceChanged();
}
public void setClient(Client client) {
mClient = client;
}
@ -230,6 +235,13 @@ public class ServoSurface {
mMainLooperHandler.post(r);
}
public void onSurfaceChanged() {
Log.d(LOGTAG, "GLThread::onSurfaceChanged");
mSurface.destroy();
mSurface = new GLSurface(mASurface);
mServo.resetGfxCallbacks(mSurface);
}
public void shutdown() {
Log.d(LOGTAG, "GLThread::shutdown");
mSurface.destroy();