Re-parent invoked on child instead of on parent.
The function to re-parent an individual child is now invoked on
the child instead of the parent. This ensures the child ends up with
the last parent set if multiple reparent requests are made in the same
transaction.
This also allows adding a parent to a layer that didn't have one
previously.
Test: Transaction_test -> Reparent, ReparentToNoParent,
ReparentFromNoParent
Change-Id: Idab429eb2dca5a4ae1b020a5a7629d719dd4d995
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 9435a18..fd30e16 100755
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2625,8 +2625,8 @@
return true;
}
-bool Layer::reparentChild(const sp<IBinder>& newParentHandle, const sp<IBinder>& childHandle) {
- if (newParentHandle == nullptr || childHandle == nullptr) {
+bool Layer::reparent(const sp<IBinder>& newParentHandle) {
+ if (newParentHandle == nullptr) {
return false;
}
@@ -2637,29 +2637,19 @@
return false;
}
- handle = static_cast<Handle*>(childHandle.get());
- sp<Layer> child = handle->owner.promote();
- if (child == nullptr) {
- ALOGE("Unable to promote child Layer handle");
- return false;
+ sp<Layer> parent = getParent();
+ if (parent != nullptr) {
+ parent->removeChild(this);
}
+ newParent->addChild(this);
- if (mCurrentChildren.indexOf(child) < 0) {
- ALOGE("Child layer is not child of current layer");
- return false;
- }
-
- sp<Client> parentClient(mClientRef.promote());
- sp<Client> childClient(child->mClientRef.promote());
+ sp<Client> client(mClientRef.promote());
sp<Client> newParentClient(newParent->mClientRef.promote());
- if (parentClient != childClient || childClient != newParentClient) {
- ALOGE("Current layer, child layer, and new parent layer must have the same client");
- return false;
+ if (client != newParentClient) {
+ client->setParentLayer(newParent);
}
- newParent->addChild(child);
- mCurrentChildren.remove(child);
return true;
}