Revert "SF: use shared_ptr to track hwcLayer"
This reverts commit 5d89c1d614426144b6430868a69db2b29b179213.
The original commit was part of a larger set that has been backed
out temporarily while some bugs are sorted out. This change
should have been backed out as well as it depends on the others
in the larger change.
Test: run cts -m CtsViewTestCases
Bug: 79264214
Change-Id: Ifa9388d9f9573073832a40075317fdabf74b180c
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 1384993..8c1199b 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -218,14 +218,15 @@
bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
"Already have a layer for hwcId %d", hwcId);
-
- std::shared_ptr<LayerContainer> layer(new LayerContainer(hwc, hwcId));
+ HWC2::Layer* layer = hwc->createLayer(hwcId);
if (!layer) {
return false;
}
LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[hwcId];
hwcInfo.hwc = hwc;
hwcInfo.layer = layer;
+ layer->setLayerDestroyedListener(
+ [this, hwcId](HWC2::Layer* /*layer*/) { getBE().mHwcLayers.erase(hwcId); });
return true;
}
@@ -236,12 +237,11 @@
auto& hwcInfo = getBE().mHwcLayers[hwcId];
LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
- hwcInfo.layer = nullptr;
-
- if (getBE().mHwcLayers.count(hwcId) == 1) {
- getBE().mHwcLayers.erase(hwcId);
- }
-
+ hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer);
+ // The layer destroyed listener should have cleared the entry from
+ // mHwcLayers. Verify that.
+ LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
+ "Stale layer entry in getBE().mHwcLayers");
return true;
}
@@ -500,7 +500,7 @@
blendMode =
mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
}
- auto error = (*hwcLayer)->setBlendMode(blendMode);
+ auto error = hwcLayer->setBlendMode(blendMode);
ALOGE_IF(error != HWC2::Error::None,
"[%s] Failed to set blend mode %s:"
" %s (%d)",
@@ -548,7 +548,7 @@
}
const Transform& tr(displayDevice->getTransform());
Rect transformedFrame = tr.transform(frame);
- error = (*hwcLayer)->setDisplayFrame(transformedFrame);
+ error = hwcLayer->setDisplayFrame(transformedFrame);
if (error != HWC2::Error::None) {
ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
transformedFrame.left, transformedFrame.top, transformedFrame.right,
@@ -558,7 +558,7 @@
}
FloatRect sourceCrop = computeCrop(displayDevice);
- error = (*hwcLayer)->setSourceCrop(sourceCrop);
+ error = hwcLayer->setSourceCrop(sourceCrop);
if (error != HWC2::Error::None) {
ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
"%s (%d)",
@@ -569,13 +569,13 @@
}
float alpha = static_cast<float>(getAlpha());
- error = (*hwcLayer)->setPlaneAlpha(alpha);
+ error = hwcLayer->setPlaneAlpha(alpha);
ALOGE_IF(error != HWC2::Error::None,
"[%s] Failed to set plane alpha %.3f: "
"%s (%d)",
mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
- error = (*hwcLayer)->setZOrder(z);
+ error = hwcLayer->setZOrder(z);
ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
to_string(error).c_str(), static_cast<int32_t>(error));
@@ -590,7 +590,7 @@
}
}
- error = (*hwcLayer)->setInfo(type, appId);
+ error = hwcLayer->setInfo(type, appId);
ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
static_cast<int32_t>(error));
@@ -633,7 +633,7 @@
} else {
auto transform = static_cast<HWC2::Transform>(orientation);
hwcInfo.transform = transform;
- auto error = (*hwcLayer)->setTransform(transform);
+ auto error = hwcLayer->setTransform(transform);
ALOGE_IF(error != HWC2::Error::None,
"[%s] Failed to set transform %s: "
"%s (%d)",
@@ -686,7 +686,7 @@
auto& displayTransform(displayDevice->getTransform());
auto position = displayTransform.transform(frame);
- auto error = (*getBE().mHwcLayers[hwcId].layer)->setCursorPosition(position.left,
+ auto error = getBE().mHwcLayers[hwcId].layer->setCursorPosition(position.left,
position.top);
ALOGE_IF(error != HWC2::Error::None,
"[%s] Failed to set cursor position "
@@ -730,13 +730,13 @@
}
auto& hwcInfo = getBE().mHwcLayers[hwcId];
auto& hwcLayer = hwcInfo.layer;
- ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", (*hwcLayer)->getId(), to_string(type).c_str(),
+ ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
static_cast<int>(callIntoHwc));
if (hwcInfo.compositionType != type) {
ALOGV(" actually setting");
hwcInfo.compositionType = type;
if (callIntoHwc) {
- auto error = (*hwcLayer)->setCompositionType(type);
+ auto error = hwcLayer->setCompositionType(type);
ALOGE_IF(error != HWC2::Error::None,
"[%s] Failed to set "
"composition type %s: %s (%d)",