void SurfaceFlinger::onHandleDestroyed(sp<Layer>& layer)
{
Mutex::Autolock lock(mStateLock);
// If a layer has a parent, we allow it to out-live it's handle
// with the idea that the parent holds a reference and will eventually
// be cleaned up. However no one cleans up the top-level so we do so
// here.
if (layer->getParent() == nullptr) {
mCurrentState.layersSortedByZ.remove(layer);
}
markLayerPendingRemovalLocked(layer);
auto it = mLayersByLocalBinderToken.begin();
while (it != mLayersByLocalBinderToken.end()) {
if (it->second == layer) {
it = mLayersByLocalBinderToken.erase(it);
} else {
it++;
}
}
layer.clear();
}
void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) {
mLayersPendingRemoval.add(layer);
mLayersRemoved = true;
setTransactionFlags(eTransactionNeeded);
}
- 如果没有父,则从
layersSortedByZ
中移除 layer
。标记 layer
移除,设置 mLayersRemoved
,并安排一次 transaction。
- 从
mLayersByLocalBinderToken
中移除 layer
,最后调用 clear()
清除所有引用。