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:
@@ -16,7 +16,11 @@ AndroidExternalTextureGL::AndroidExternalTextureGL(
|
|||||||
const fml::jni::JavaObjectWeakGlobalRef& surfaceTexture)
|
const fml::jni::JavaObjectWeakGlobalRef& surfaceTexture)
|
||||||
: Texture(id), surface_texture_(surfaceTexture), transform(SkMatrix::I()) {}
|
: Texture(id), surface_texture_(surfaceTexture), transform(SkMatrix::I()) {}
|
||||||
|
|
||||||
AndroidExternalTextureGL::~AndroidExternalTextureGL() = default;
|
AndroidExternalTextureGL::~AndroidExternalTextureGL() {
|
||||||
|
if (state_ == AttachmentState::attached) {
|
||||||
|
glDeleteTextures(1, &texture_name_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AndroidExternalTextureGL::OnGrContextCreated() {
|
void AndroidExternalTextureGL::OnGrContextCreated() {
|
||||||
state_ = AttachmentState::uninitialized;
|
state_ = AttachmentState::uninitialized;
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ public class FlutterRenderer implements TextureRegistry {
|
|||||||
if (released) {
|
if (released) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unregisterTexture(id);
|
|
||||||
surfaceTexture.release();
|
surfaceTexture.release();
|
||||||
|
unregisterTexture(id);
|
||||||
released = true;
|
released = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1128,11 +1128,16 @@ public class FlutterView extends SurfaceView
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
released = true;
|
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
|
// Otherwise onFrameAvailableListener might be called after mNativeView==null
|
||||||
// (https://github.com/flutter/flutter/issues/20951). See also the check in onFrameAvailable.
|
// (https://github.com/flutter/flutter/issues/20951). See also the check in onFrameAvailable.
|
||||||
surfaceTexture.setOnFrameAvailableListener(null);
|
surfaceTexture.setOnFrameAvailableListener(null);
|
||||||
surfaceTexture.release();
|
surfaceTexture.release();
|
||||||
|
mNativeView.getFlutterJNI().unregisterTexture(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user