// Android 12
private void releaseSurfaces(Transaction transaction) {
if (mSurfaceControl != null) {
transaction.remove(mSurfaceControl);
mSurfaceControl = null;
}
if (mBackgroundControl != null) {
transaction.remove(mBackgroundControl);
mBackgroundControl = null;
}
if (mBlastSurfaceControl != null) {
transaction.remove(mBlastSurfaceControl);
mBlastSurfaceControl = null;
}
}
分别对 mSurfaceControl
、mBackgroundControl
和 mBlastSurfaceControl
调用 Transaction.remove() 递减 SurfaceControl native 强引用计数。
// Android 11
private void releaseSurfaces() {
mSurfaceAlpha = 1f;
synchronized (mSurfaceControlLock) {
mSurface.release();
if (mRtHandlingPositionUpdates) {
mRtReleaseSurfaces = true;
return;
}
if (mSurfaceControl != null) {
mTmpTransaction.remove(mSurfaceControl);
mSurfaceControl = null;
}
if (mBackgroundControl != null) {
mTmpTransaction.remove(mBackgroundControl);
mBackgroundControl = null;
}
mTmpTransaction.apply();
}
}
调用 Surface.release() 释放 mSurface
,调用 Transaction.remove() 释放 mSurfaceControl
和 mBackgroundControl
。