From 67e359c867ee817c647f02627d0a288a7eae607c Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Mon, 6 Mar 2023 14:10:15 +0000 Subject: [PATCH] GL: Delete frame buffers after use. Before, we used to never call glDeleteFramebuffers, which could in theory lead to leaks in the number of frame buffers available and make releasing the GL context more expensive. PiperOrigin-RevId: 514387847 --- .../java/com/google/android/exoplayer2/util/GlUtil.java | 8 ++++++++ .../exoplayer2/effect/FrameCacheGlShaderProgram.java | 1 + .../exoplayer2/effect/SingleFrameGlShaderProgram.java | 2 ++ 3 files changed, 11 insertions(+) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java b/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java index 5d41b04511..060a6f9395 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java @@ -644,6 +644,14 @@ public final class GlUtil { return fboId[0]; } + /** Deletes a framebuffer. */ + public static void deleteFbo(int fboId) throws GlException { + int[] fboIdArray = new int[1]; + fboIdArray[0] = fboId; + GLES20.glDeleteFramebuffers(/* n= */ 1, fboIdArray, /* offset= */ 0); + checkGlError(); + } + /** * Throws a {@link GlException} with the given message if {@code expression} evaluates to {@code * false}. diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameCacheGlShaderProgram.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameCacheGlShaderProgram.java index 31e9797587..611126dd14 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameCacheGlShaderProgram.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameCacheGlShaderProgram.java @@ -205,6 +205,7 @@ import java.util.concurrent.Executor; while (allTextures.hasNext()) { TextureInfo textureInfo = allTextures.next(); GlUtil.deleteTexture(textureInfo.texId); + GlUtil.deleteFbo(textureInfo.fboId); } freeOutputTextures.clear(); inUseOutputTextures.clear(); diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/SingleFrameGlShaderProgram.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/SingleFrameGlShaderProgram.java index d6ee29818d..ad07ca7248 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/SingleFrameGlShaderProgram.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/SingleFrameGlShaderProgram.java @@ -154,6 +154,7 @@ public abstract class SingleFrameGlShaderProgram implements GlShaderProgram { || outputSize.getHeight() != outputTexture.height) { if (outputTexture != null) { GlUtil.deleteTexture(outputTexture.texId); + GlUtil.deleteFbo(outputTexture.fboId); } int outputTexId = GlUtil.createTexture(outputSize.getWidth(), outputSize.getHeight(), useHdr); int outputFboId = GlUtil.createFboForTexture(outputTexId); @@ -187,6 +188,7 @@ public abstract class SingleFrameGlShaderProgram implements GlShaderProgram { if (outputTexture != null) { try { GlUtil.deleteTexture(outputTexture.texId); + GlUtil.deleteFbo(outputTexture.fboId); } catch (GlUtil.GlException e) { throw new VideoFrameProcessingException(e); }