Delete GL textures when they are released from the texture registry. (flutter/engine#7836)

On Android we were never deleting the textures allocated for
the texture registry, which resulted in a memory leak, see:
https://github.com/flutter/flutter/issues/24145
This commit is contained in:
Amir Hardon 2019-02-15 13:11:49 -08:00 committed by GitHub
parent cd5ceb29be
commit 333458c95e
3 changed files with 12 additions and 3 deletions

View File

@ -16,7 +16,11 @@ AndroidExternalTextureGL::AndroidExternalTextureGL(
const fml::jni::JavaObjectWeakGlobalRef& surfaceTexture)
: Texture(id), surface_texture_(surfaceTexture), transform(SkMatrix::I()) {}
AndroidExternalTextureGL::~AndroidExternalTextureGL() = default;
AndroidExternalTextureGL::~AndroidExternalTextureGL() {
if (state_ == AttachmentState::attached) {
glDeleteTextures(1, &texture_name_);
}
}
void AndroidExternalTextureGL::OnGrContextCreated() {
state_ = AttachmentState::uninitialized;

View File

@ -134,8 +134,8 @@ public class FlutterRenderer implements TextureRegistry {
if (released) {
return;
}
unregisterTexture(id);
surfaceTexture.release();
unregisterTexture(id);
released = true;
}
}

View File

@ -1128,11 +1128,16 @@ public class FlutterView extends SurfaceView
return;
}
released = true;
mNativeView.getFlutterJNI().unregisterTexture(id);
// The ordering of the next 3 calls is important:
// First we remove the frame listener, then we release the SurfaceTexture, and only after we unregister
// the texture which actually deletes the GL texture.
// Otherwise onFrameAvailableListener might be called after mNativeView==null
// (https://github.com/flutter/flutter/issues/20951). See also the check in onFrameAvailable.
surfaceTexture.setOnFrameAvailableListener(null);
surfaceTexture.release();
mNativeView.getFlutterJNI().unregisterTexture(id);
}
}
}