Destroy eglSurface in FrameProcessor
Previously, FrameProcessor never had the usecase in which the output surface is replaced, while previewing introduced this usecase. When switching output surfaces, we need to destroy the EGL Surface linked to the surface that is being swapped out, because an EGL surface is linked to the EGL display (which is not destroyed even when releasing FrameProcessor). A GL exception will be thrown in the following scenario if we don't destroy the EGL surface: 1. Creates a Surface, the surface is identified by address 0x11 2. Sets Surface(0x11) on FrameProcessor. Eventually an EGL surface is created to wrap Surface(0x11) 3. Release FrameProcess, this releases the EGL context 4. Instantiate a new FrameProcessor, sets Surface(0x11) as the output 5. When FrameProcessor creates an EGL surface to wrap Surface(0x11), GL throws an exception, becasue Surface(0x11) has previouly been connected to an EGL surface. PiperOrigin-RevId: 489590072
This commit is contained in:
parent
81918d8da7
commit
dba9d81640
@ -469,6 +469,16 @@ public final class GlUtil {
|
||||
Api17.destroyEglContext(eglDisplay, eglContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the {@link EGLSurface} identified by the provided {@link EGLDisplay} and {@link
|
||||
* EGLSurface}.
|
||||
*/
|
||||
@RequiresApi(17)
|
||||
public static void destroyEglSurface(
|
||||
@Nullable EGLDisplay eglDisplay, @Nullable EGLSurface eglSurface) throws GlException {
|
||||
Api17.destroyEglSurface(eglDisplay, eglSurface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a FloatBuffer with the given data.
|
||||
*
|
||||
@ -734,6 +744,16 @@ public final class GlUtil {
|
||||
checkEglException("Error terminating display");
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
public static void destroyEglSurface(
|
||||
@Nullable EGLDisplay eglDisplay, @Nullable EGLSurface eglSurface) throws GlException {
|
||||
if (eglDisplay == null || eglSurface == null) {
|
||||
return;
|
||||
}
|
||||
EGL14.eglDestroySurface(eglDisplay, eglSurface);
|
||||
checkEglException("Error destroying surface");
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
private static EGLConfig getEglConfig(EGLDisplay eglDisplay, int[] attributes)
|
||||
throws GlException {
|
||||
|
@ -183,10 +183,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
@Override
|
||||
@WorkerThread
|
||||
public void release() throws FrameProcessingException {
|
||||
public synchronized void release() throws FrameProcessingException {
|
||||
if (matrixTextureProcessor != null) {
|
||||
matrixTextureProcessor.release();
|
||||
}
|
||||
try {
|
||||
GlUtil.destroyEglSurface(eglDisplay, outputEglSurface);
|
||||
} catch (GlUtil.GlException e) {
|
||||
throw new FrameProcessingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -226,6 +231,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
if (outputSurfaceInfo != null
|
||||
&& this.outputSurfaceInfo != null
|
||||
&& !this.outputSurfaceInfo.surface.equals(outputSurfaceInfo.surface)) {
|
||||
try {
|
||||
GlUtil.destroyEglSurface(eglDisplay, outputEglSurface);
|
||||
} catch (GlUtil.GlException e) {
|
||||
frameProcessorListener.onFrameProcessingError(FrameProcessingException.from(e));
|
||||
}
|
||||
this.outputEglSurface = null;
|
||||
}
|
||||
outputSizeOrRotationChanged =
|
||||
@ -307,6 +317,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
matrixTextureProcessor.release();
|
||||
matrixTextureProcessor = null;
|
||||
}
|
||||
GlUtil.destroyEglSurface(eglDisplay, outputEglSurface);
|
||||
outputEglSurface = null;
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user