summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/surfaceflinger/Layer.cpp10
-rw-r--r--services/surfaceflinger/Scheduler/LayerHistory.cpp13
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp8
3 files changed, 24 insertions, 7 deletions
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 4fee723f09..77137496d1 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -221,7 +221,10 @@ void Layer::removeRelativeZ(const std::vector<Layer*>& layersInTree) {
}
void Layer::removeFromCurrentState() {
- mRemovedFromCurrentState = true;
+ if (!mRemovedFromCurrentState) {
+ mRemovedFromCurrentState = true;
+ mFlinger->mScheduler->deregisterLayer(this);
+ }
mFlinger->markLayerPendingRemovalLocked(this);
}
@@ -246,7 +249,10 @@ void Layer::onRemovedFromCurrentState() {
}
void Layer::addToCurrentState() {
- mRemovedFromCurrentState = false;
+ if (mRemovedFromCurrentState) {
+ mRemovedFromCurrentState = false;
+ mFlinger->mScheduler->registerLayer(this);
+ }
for (const auto& child : mCurrentChildren) {
child->addToCurrentState();
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index f4bc2a10cb..0563795c79 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -84,8 +84,11 @@ LayerHistory::LayerHistory(const RefreshRateConfigs& refreshRateConfigs)
LayerHistory::~LayerHistory() = default;
void LayerHistory::registerLayer(Layer* layer, LayerVoteType type) {
- auto info = std::make_unique<LayerInfo>(layer->getName(), layer->getOwnerUid(), type);
std::lock_guard lock(mLock);
+ for (const auto& info : mLayerInfos) {
+ LOG_ALWAYS_FATAL_IF(info.first == layer, "%s already registered", layer->getName().c_str());
+ }
+ auto info = std::make_unique<LayerInfo>(layer->getName(), layer->getOwnerUid(), type);
mLayerInfos.emplace_back(layer, std::move(info));
}
@@ -94,7 +97,7 @@ void LayerHistory::deregisterLayer(Layer* layer) {
const auto it = std::find_if(mLayerInfos.begin(), mLayerInfos.end(),
[layer](const auto& pair) { return pair.first == layer; });
- LOG_FATAL_IF(it == mLayerInfos.end(), "%s: unknown layer %p", __FUNCTION__, layer);
+ LOG_ALWAYS_FATAL_IF(it == mLayerInfos.end(), "%s: unknown layer %p", __FUNCTION__, layer);
const size_t i = static_cast<size_t>(it - mLayerInfos.begin());
if (i < mActiveLayersEnd) {
@@ -111,7 +114,11 @@ void LayerHistory::record(Layer* layer, nsecs_t presentTime, nsecs_t now,
const auto it = std::find_if(mLayerInfos.begin(), mLayerInfos.end(),
[layer](const auto& pair) { return pair.first == layer; });
- LOG_FATAL_IF(it == mLayerInfos.end(), "%s: unknown layer %p", __FUNCTION__, layer);
+ if (it == mLayerInfos.end()) {
+ // Offscreen layer
+ ALOGV("LayerHistory::record: %s not registered", layer->getName().c_str());
+ return;
+ }
const auto& info = it->second;
const auto layerProps = LayerInfo::LayerProps{
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ecee97783c..eaefc652e0 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -6437,13 +6437,17 @@ wp<Layer> SurfaceFlinger::fromHandleLocked(const sp<IBinder>& handle) const {
void SurfaceFlinger::onLayerFirstRef(Layer* layer) {
mNumLayers++;
- mScheduler->registerLayer(layer);
+ if (!layer->isRemovedFromCurrentState()) {
+ mScheduler->registerLayer(layer);
+ }
}
void SurfaceFlinger::onLayerDestroyed(Layer* layer) {
- mScheduler->deregisterLayer(layer);
mNumLayers--;
removeFromOffscreenLayers(layer);
+ if (!layer->isRemovedFromCurrentState()) {
+ mScheduler->deregisterLayer(layer);
+ }
}
// WARNING: ONLY CALL THIS FROM LAYER DTOR