Sync surface destruction with main thread (#3368)

This commit is contained in:
Adrian Cojocaru
2025-04-09 14:58:10 +03:00
committed by GitHub
parent d693898757
commit 802586ed52
3 changed files with 20 additions and 0 deletions

View File

@@ -84,6 +84,14 @@ abstract class TextureViewRenderThread extends Thread implements TextureView.Sur
this.destroySurface = true;
this.requestRender = false;
lock.notifyAll();
while (this.hasNativeSurface) {
try {
lock.wait();
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
return true;
}

View File

@@ -73,6 +73,8 @@ public class GLTextureViewRenderThread extends TextureViewRenderThread {
if (destroySurface) {
eglHolder.destroySurface();
destroySurface = false;
this.hasNativeSurface = false;
lock.notifyAll();
break;
}
@@ -89,12 +91,14 @@ public class GLTextureViewRenderThread extends TextureViewRenderThread {
// Initialize EGL if needed
if (eglHolder.eglContext == EGL10.EGL_NO_CONTEXT) {
this.hasNativeSurface = true;
initializeEGL = true;
break;
}
// (re-)Initialize EGL Surface if needed
if (eglHolder.eglSurface == EGL10.EGL_NO_SURFACE) {
this.hasNativeSurface = true;
recreateSurface = true;
break;
}
@@ -195,6 +199,7 @@ public class GLTextureViewRenderThread extends TextureViewRenderThread {
// Signal we're done
synchronized (lock) {
this.hasNativeSurface = false;
this.exited = true;
lock.notifyAll();
}

View File

@@ -23,6 +23,8 @@ public class VulkanTextureViewRenderThread extends TextureViewRenderThread {
mapRenderer.onSurfaceDestroyed();
surface.release();
surface = null;
hasNativeSurface = false;
}
// Thread implementation
@@ -68,6 +70,7 @@ public class VulkanTextureViewRenderThread extends TextureViewRenderThread {
if (surface == null) {
surface = new Surface(surfaceTexture);
this.hasNativeSurface = true;
createSurface = true;
}
@@ -111,6 +114,10 @@ public class VulkanTextureViewRenderThread extends TextureViewRenderThread {
if (destroySurface) {
mapRenderer.onSurfaceDestroyed();
destroySurface = false;
synchronized (lock) {
this.hasNativeSurface = false;
lock.notifyAll();
}
continue;
}