diff options
author | 2018-12-11 12:07:25 -0800 | |
---|---|---|
committer | 2019-01-08 11:41:57 -0800 | |
commit | 6fb1a7e9627df030667304d88a3292f91e790ea9 (patch) | |
tree | 8b726ff0728f7813106cb6c02e5700da7b986065 /services/surfaceflinger/Layer.cpp | |
parent | abbbbd69c48056490c484a29af4aace65e5e7cf1 (diff) |
SurfaceFlinger: Remove removeLayer
We remove explicit layer destruction and replace it
with reparent->null, completing the transition to
a reference counted model.
Test: Manual
Bug: 62536731
Bug: 111373437
Bug: 111297488
Change-Id: I8ac7c5c5125e1c8daf84b42db00e1dd93a544bb5
Diffstat (limited to 'services/surfaceflinger/Layer.cpp')
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index b1827c191c..3f2d10a45b 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -179,6 +179,8 @@ void Layer::onRemovedFromCurrentState() { for (const auto& child : mCurrentChildren) { child->onRemovedFromCurrentState(); } + + mFlinger->markLayerPendingRemovalLocked(this); } void Layer::addToCurrentState() { @@ -1571,6 +1573,7 @@ void Layer::addChild(const sp<Layer>& layer) { ssize_t Layer::removeChild(const sp<Layer>& layer) { layer->setParent(nullptr); + return mCurrentChildren.remove(layer); } @@ -1605,14 +1608,14 @@ void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) { } bool Layer::reparent(const sp<IBinder>& newParentHandle) { - if (newParentHandle == nullptr) { - return false; - } - - auto handle = static_cast<Handle*>(newParentHandle.get()); - sp<Layer> newParent = handle->owner.promote(); - if (newParent == nullptr) { - ALOGE("Unable to promote Layer handle"); + bool callSetTransactionFlags = false; + + // While layers are detached, we allow most operations + // and simply halt performing the actual transaction. However + // for reparent != null we would enter the mRemovedFromCurrentState + // state, regardless of whether doTransaction was called, and + // so we need to prevent the update here. + if (mLayerDetached && newParentHandle == nullptr) { return false; } @@ -1620,17 +1623,31 @@ bool Layer::reparent(const sp<IBinder>& newParentHandle) { if (parent != nullptr) { parent->removeChild(this); } - newParent->addChild(this); - if (!newParent->isRemovedFromCurrentState()) { - addToCurrentState(); - } + if (newParentHandle != nullptr) { + auto handle = static_cast<Handle*>(newParentHandle.get()); + sp<Layer> newParent = handle->owner.promote(); + if (newParent == nullptr) { + ALOGE("Unable to promote Layer handle"); + return false; + } - if (mLayerDetached) { - mLayerDetached = false; - setTransactionFlags(eTransactionNeeded); + newParent->addChild(this); + if (!newParent->isRemovedFromCurrentState()) { + addToCurrentState(); + } else { + onRemovedFromCurrentState(); + } + + if (mLayerDetached) { + mLayerDetached = false; + callSetTransactionFlags = true; + } + } else { + onRemovedFromCurrentState(); } - if (attachChildren()) { + + if (callSetTransactionFlags || attachChildren()) { setTransactionFlags(eTransactionNeeded); } return true; |