[sf] resolve handles to layer ids in binder thread
Remove layer handle dependencies from frontend
to make transaction tracing logic simpler.
Test: presubmit
Bug: 238781169
Change-Id: I00c7002b10815a00c6ff9b636edf10593f304407
diff --git a/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp b/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp
index 6659825..5efa394 100644
--- a/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp
@@ -65,6 +65,10 @@
}
}
+LayerCreationArgs::LayerCreationArgs(std::optional<uint32_t> id, bool internalLayer)
+ : LayerCreationArgs(nullptr, nullptr, /*name=*/"", /*flags=*/0, /*metadata=*/{}, id,
+ internalLayer) {}
+
LayerCreationArgs::LayerCreationArgs(const LayerCreationArgs& args)
: LayerCreationArgs(args.flinger, args.client, args.name, args.flags, args.metadata) {}
diff --git a/services/surfaceflinger/FrontEnd/LayerCreationArgs.h b/services/surfaceflinger/FrontEnd/LayerCreationArgs.h
index 2cd6b55..8341e1d 100644
--- a/services/surfaceflinger/FrontEnd/LayerCreationArgs.h
+++ b/services/surfaceflinger/FrontEnd/LayerCreationArgs.h
@@ -41,6 +41,8 @@
LayerCreationArgs(android::SurfaceFlinger*, sp<android::Client>, std::string name,
uint32_t flags, gui::LayerMetadata, std::optional<uint32_t> id = std::nullopt,
bool internalLayer = false);
+ LayerCreationArgs(std::optional<uint32_t> id, bool internalLayer = false);
+
LayerCreationArgs(const LayerCreationArgs&);
android::SurfaceFlinger* flinger;
@@ -56,6 +58,8 @@
wp<IBinder> parentHandle = nullptr;
wp<IBinder> mirrorLayerHandle = nullptr;
ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
+ uint32_t parentId = UNASSIGNED_LAYER_ID;
+ uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID;
};
} // namespace android::surfaceflinger
diff --git a/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp b/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp
index 33cc429..fe42422 100644
--- a/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp
@@ -20,8 +20,7 @@
#define LOG_TAG "LayerLifecycleManager"
#include "LayerLifecycleManager.h"
-#include "Layer.h" // temporarily needed for LayerHandle
-#include "LayerHandle.h"
+#include "Client.h" // temporarily needed for LayerCreationArgs
#include "LayerLog.h"
#include "SwapErase.h"
@@ -167,7 +166,7 @@
for (const auto& transaction : transactions) {
for (const auto& resolvedComposerState : transaction.states) {
const auto& clientState = resolvedComposerState.state;
- uint32_t layerId = LayerHandle::getLayerId(clientState.surface);
+ uint32_t layerId = resolvedComposerState.layerId;
if (layerId == UNASSIGNED_LAYER_ID) {
ALOGW("%s Handle %p is not valid", __func__, clientState.surface.get());
continue;
@@ -175,15 +174,14 @@
RequestedLayerState* layer = getLayerFromId(layerId);
if (layer == nullptr) {
- LOG_ALWAYS_FATAL("%s Layer with handle %p (layerid=%d) not found", __func__,
- clientState.surface.get(), layerId);
+ LOG_ALWAYS_FATAL("%s Layer with layerid=%d not found", __func__, layerId);
continue;
}
if (!layer->handleAlive) {
- LOG_ALWAYS_FATAL("%s Layer's handle %p (layerid=%d) is not alive. Possible out of "
+ LOG_ALWAYS_FATAL("%s Layer's with layerid=%d) is not alive. Possible out of "
"order LayerLifecycleManager updates",
- __func__, clientState.surface.get(), layerId);
+ __func__, layerId);
continue;
}
@@ -198,13 +196,11 @@
if (layer->what & layer_state_t::eBackgroundColorChanged) {
if (layer->bgColorLayerId == UNASSIGNED_LAYER_ID && layer->bgColor.a != 0) {
- LayerCreationArgs backgroundLayerArgs{nullptr,
- nullptr,
- layer->name + "BackgroundColorLayer",
- ISurfaceComposerClient::eFXSurfaceEffect,
- {},
- layer->id,
- /*internalLayer=*/true};
+ LayerCreationArgs backgroundLayerArgs(layer->id,
+ /*internalLayer=*/true);
+ backgroundLayerArgs.parentId = layer->id;
+ backgroundLayerArgs.name = layer->name + "BackgroundColorLayer";
+ backgroundLayerArgs.flags = ISurfaceComposerClient::eFXSurfaceEffect;
std::vector<std::unique_ptr<RequestedLayerState>> newLayers;
newLayers.emplace_back(
std::make_unique<RequestedLayerState>(backgroundLayerArgs));
diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
index e2cbe28..a5fdaf4 100644
--- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
+++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
@@ -24,7 +24,6 @@
#include "Layer.h"
#include "LayerCreationArgs.h"
-#include "LayerHandle.h"
#include "LayerLog.h"
#include "RequestedLayerState.h"
@@ -33,14 +32,6 @@
using namespace ftl::flag_operators;
namespace {
-uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) {
- if (!surfaceControl) {
- return UNASSIGNED_LAYER_ID;
- }
-
- return LayerHandle::getLayerId(surfaceControl->getHandle());
-}
-
std::string layerIdToString(uint32_t layerId) {
return layerId == UNASSIGNED_LAYER_ID ? "none" : std::to_string(layerId);
}
@@ -64,17 +55,17 @@
layerCreationFlags(args.flags),
textureName(args.textureName),
ownerUid(args.ownerUid),
- ownerPid(args.ownerPid) {
+ ownerPid(args.ownerPid),
+ parentId(args.parentId),
+ layerIdToMirror(args.layerIdToMirror) {
layerId = static_cast<int32_t>(args.sequence);
changes |= RequestedLayerState::Changes::Created;
metadata.merge(args.metadata);
changes |= RequestedLayerState::Changes::Metadata;
handleAlive = true;
- parentId = LayerHandle::getLayerId(args.parentHandle.promote());
- if (args.parentHandle != nullptr) {
+ if (parentId != UNASSIGNED_LAYER_ID) {
canBeRoot = false;
}
- layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote());
if (layerIdToMirror != UNASSIGNED_LAYER_ID) {
changes |= RequestedLayerState::Changes::Mirror;
} else if (args.layerStackToMirror != ui::INVALID_LAYER_STACK) {
@@ -209,7 +200,7 @@
}
if (clientState.what & layer_state_t::eReparent) {
changes |= RequestedLayerState::Changes::Parent;
- parentId = getLayerIdFromSurfaceControl(clientState.parentSurfaceControlForChild);
+ parentId = resolvedComposerState.parentId;
parentSurfaceControlForChild = nullptr;
// Once a layer has be reparented, it cannot be placed at the root. It sounds odd
// but thats the existing logic and until we make this behavior more explicit, we need
@@ -218,7 +209,7 @@
}
if (clientState.what & layer_state_t::eRelativeLayerChanged) {
changes |= RequestedLayerState::Changes::RelativeParent;
- relativeParentId = getLayerIdFromSurfaceControl(clientState.relativeLayerSurfaceControl);
+ relativeParentId = resolvedComposerState.relativeParentId;
isRelativeOf = true;
relativeLayerSurfaceControl = nullptr;
}
@@ -235,10 +226,8 @@
changes |= RequestedLayerState::Changes::RelativeParent;
}
if (clientState.what & layer_state_t::eInputInfoChanged) {
- wp<IBinder>& touchableRegionCropHandle =
- windowInfoHandle->editInfo()->touchableRegionCropHandle;
- touchCropId = LayerHandle::getLayerId(touchableRegionCropHandle.promote());
- touchableRegionCropHandle.clear();
+ touchCropId = resolvedComposerState.touchCropId;
+ windowInfoHandle->editInfo()->touchableRegionCropHandle.clear();
}
if (clientState.what & layer_state_t::eStretchChanged) {
stretchEffect.sanitize();
diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.h b/services/surfaceflinger/FrontEnd/RequestedLayerState.h
index 6f5485d..216e95f 100644
--- a/services/surfaceflinger/FrontEnd/RequestedLayerState.h
+++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.h
@@ -105,17 +105,17 @@
std::shared_ptr<renderengine::ExternalTexture> externalTexture;
gui::GameMode gameMode;
scheduler::LayerInfo::FrameRate requestedFrameRate;
- ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
+ uint32_t parentId = UNASSIGNED_LAYER_ID;
+ uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID;
+ ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
+ uint32_t touchCropId = UNASSIGNED_LAYER_ID;
+ uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID;
// book keeping states
bool handleAlive = true;
bool isRelativeOf = false;
- uint32_t parentId = UNASSIGNED_LAYER_ID;
- uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
std::vector<uint32_t> mirrorIds{};
- uint32_t touchCropId = UNASSIGNED_LAYER_ID;
- uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID;
ftl::Flags<RequestedLayerState::Changes> changes;
bool bgColorLayer = false;
};