Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86ab512e authored by Melody Hsu's avatar Melody Hsu
Browse files

[legacy sf flag] - Remove layerLifecycleManagerEnabled

New frontend is enabled in SurfaceFlinger and code guarded
behind the flag can be removed, along with the flag itself.

Bug: b/330785038
Test: presubmit
Flag: EXEMPT (removing old flags)
Change-Id: I65d5bd142a708897507e804223200ada91fc7489
parent 73469a12
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -2540,10 +2540,6 @@ bool Layer::hasInputInfo() const {
compositionengine::OutputLayer* Layer::findOutputLayerForDisplay(
        const DisplayDevice* display) const {
    if (!display) return nullptr;
    if (!mFlinger->mLayerLifecycleManagerEnabled) {
        return display->getCompositionDisplay()->getOutputLayerForLayer(
                getCompositionEngineLayerFE());
    }
    sp<LayerFE> layerFE;
    frontend::LayerHierarchy::TraversalPath path{.id = static_cast<uint32_t>(sequence)};
    for (auto& [p, layer] : mLayerFEs) {
@@ -2559,10 +2555,6 @@ compositionengine::OutputLayer* Layer::findOutputLayerForDisplay(
compositionengine::OutputLayer* Layer::findOutputLayerForDisplay(
        const DisplayDevice* display, const frontend::LayerHierarchy::TraversalPath& path) const {
    if (!display) return nullptr;
    if (!mFlinger->mLayerLifecycleManagerEnabled) {
        return display->getCompositionDisplay()->getOutputLayerForLayer(
                getCompositionEngineLayerFE());
    }
    sp<LayerFE> layerFE;
    for (auto& [p, layer] : mLayerFEs) {
        if (p == path) {
+90 −223
Original line number Diff line number Diff line
@@ -534,9 +534,6 @@ SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipI

    mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false);

    mLayerLifecycleManagerEnabled =
            base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true);

    // These are set by the HWC implementation to indicate that they will use the workarounds.
    mIsHotplugErrViaNegVsync =
            base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false);
@@ -2676,11 +2673,8 @@ bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId,

        const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded);
        bool transactionsAreEmpty = false;
        if (mLayerLifecycleManagerEnabled) {
            mustComposite |=
                    updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(),
        mustComposite |= updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(),
                                              flushTransactions, transactionsAreEmpty);
        }

        // Tell VsyncTracker that we are going to present this frame before scheduling
        // setTransactionFlags which will schedule another SF frame. This was if the tracker
@@ -2714,9 +2708,7 @@ bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId,
        mUpdateAttachedChoreographer = false;

        Mutex::Autolock lock(mStateLock);
        mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled
                                                        ? &mLayerHierarchyBuilder.getHierarchy()
                                                        : nullptr,
        mScheduler->chooseRefreshRateForContent(&mLayerHierarchyBuilder.getHierarchy(),
                                                updateAttachedChoreographer);

        if (FlagManager::getInstance().connected_display()) {
@@ -2837,7 +2829,7 @@ CompositeResultsPerDisplay SurfaceFlinger::composite(
    constexpr bool kCursorOnly = false;
    const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly);

    if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) {
    if (!mVisibleRegionsDirty) {
        for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) {
            auto compositionDisplay = display->getCompositionDisplay();
            if (!compositionDisplay->getState().isEnabled) continue;
@@ -3253,11 +3245,10 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
                        }
                    };

            if (mLayerLifecycleManagerEnabled) {
            mLayerSnapshotBuilder.forEachVisibleSnapshot(
                    [&, compositionDisplay = compositionDisplay](
                                std::unique_ptr<frontend::LayerSnapshot>&
                                        snapshot) FTL_FAKE_GUARD(kMainThreadContext) {
                            std::unique_ptr<frontend::LayerSnapshot>& snapshot)
                            FTL_FAKE_GUARD(kMainThreadContext) {
                                auto it = mLegacyLayers.find(snapshot->sequence);
                                LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(),
                                                                "Couldnt find layer object for %s",
@@ -3268,13 +3259,6 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,

                                updateInfoFn(compositionDisplay, *snapshot, layerFe);
                            });
            } else {
                mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) {
                    const auto layerFe = layer->getCompositionEngineLayerFE();
                    const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot();
                    updateInfoFn(compositionDisplay, snapshot, layerFe);
                });
            }
            listener->dispatchHdrLayerInfo(info);
        }
    }
@@ -3320,9 +3304,8 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
            if (!layer->hasTrustedPresentationListener()) {
                return;
            }
            const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled
                    ? mLayerSnapshotBuilder.getSnapshot(layer->sequence)
                    : layer->getLayerSnapshot();
            const frontend::LayerSnapshot* snapshot =
                    mLayerSnapshotBuilder.getSnapshot(layer->sequence);
            std::optional<const DisplayDevice*> displayOpt = std::nullopt;
            if (snapshot) {
                displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack);
@@ -4047,13 +4030,6 @@ void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) {
    // Commit display transactions.
    const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded;
    mFrontEndDisplayInfosChanged = displayTransactionNeeded;
    if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) {
        processDisplayChangesLocked();
        mFrontEndDisplayInfos.clear();
        for (const auto& [_, display] : mDisplays) {
            mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo());
        }
    }
    mForceTransactionDisplayChange = displayTransactionNeeded;

    if (mSomeChildrenChanged) {
@@ -4234,23 +4210,10 @@ void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos,
    outWindowInfos.reserve(sNumWindowInfos);
    sNumWindowInfos = 0;

    if (mLayerLifecycleManagerEnabled) {
    mLayerSnapshotBuilder.forEachInputSnapshot(
            [&outWindowInfos](const frontend::LayerSnapshot& snapshot) {
                outWindowInfos.push_back(snapshot.inputInfo);
            });
    } else {
        mDrawingState.traverseInReverseZOrder([&](Layer* layer) FTL_FAKE_GUARD(kMainThreadContext) {
            if (!layer->needsInputInfo()) return;
            const auto opt =
                    mFrontEndDisplayInfos.get(layer->getLayerStack())
                            .transform([](const frontend::DisplayInfo& info) {
                                return Layer::InputDisplayArgs{&info.transform, info.isSecure};
                            });

            outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{})));
        });
    }

    sNumWindowInfos = outWindowInfos.size();

@@ -4324,11 +4287,9 @@ void SurfaceFlinger::notifyCpuLoadUp() {

void SurfaceFlinger::onChoreographerAttached() {
    SFTRACE_CALL();
    if (mLayerLifecycleManagerEnabled) {
    mUpdateAttachedChoreographer = true;
    scheduleCommit(FrameHint::kNone);
}
}

void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime,
                                                 ftl::NonNull<DisplayModePtr> modePtr,
@@ -5077,15 +5038,8 @@ TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferC
void SurfaceFlinger::addTransactionReadyFilters() {
    mTransactionHandler.addTransactionReadyFilter(
            std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1));
    if (mLayerLifecycleManagerEnabled) {
        mTransactionHandler.addTransactionReadyFilter(
                std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this,
                          std::placeholders::_1));
    } else {
    mTransactionHandler.addTransactionReadyFilter(
                std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this,
                          std::placeholders::_1));
    }
            std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, std::placeholders::_1));
}

// For tests only
@@ -5317,11 +5271,6 @@ bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin
                                           const std::vector<ListenerCallbacks>& listenerCallbacks,
                                           int originPid, int originUid, uint64_t transactionId) {
    uint32_t transactionFlags = 0;
    if (!mLayerLifecycleManagerEnabled) {
        for (DisplayState& display : displays) {
            transactionFlags |= setDisplayStateLocked(display);
        }
    }

    // start and end registration for listeners w/ no surface so they can get their callback.  Note
    // that listeners with SurfaceControls will start registration during setClientStateLocked
@@ -5329,27 +5278,11 @@ bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin
    for (const auto& listener : listenerCallbacks) {
        mTransactionCallbackInvoker.addEmptyTransaction(listener);
    }
    nsecs_t now = systemTime();
    uint32_t clientStateFlags = 0;
    for (auto& resolvedState : states) {
        clientStateFlags |=
                updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, desiredPresentTime,
                                             isAutoTimestamp, postTime, transactionId);
        if (!mLayerLifecycleManagerEnabled) {
            if ((flags & eAnimation) && resolvedState.state.surface) {
                if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) {
                    const auto layerProps = scheduler::LayerProps{
                            .visible = layer->isVisible(),
                            .bounds = layer->getBounds(),
                            .transform = layer->getTransform(),
                            .setFrameRateVote = layer->getFrameRateForLayerTree(),
                            .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(),
                            .isFrontBuffered = layer->isFrontBuffered(),
                    };
                    layer->recordLayerHistoryAnimationTx(layerProps, now);
                }
            }
        }
    }

    transactionFlags |= clientStateFlags;
@@ -6661,23 +6594,6 @@ void SurfaceFlinger::dumpFrontEnd(std::string& result) {
}

void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) {
    if (!mLayerLifecycleManagerEnabled) {
        StringAppendF(&result, "Composition layers\n");
        mDrawingState.traverseInZOrder([&](Layer* layer) {
            auto* compositionState = layer->getCompositionState();
            if (!compositionState || !compositionState->isVisible) return;
            android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer,
                                         layer->getDebugName() ? layer->getDebugName()
                                                               : "<unknown>");
            compositionState->dump(result);
        });

        StringAppendF(&result, "Offscreen Layers\n");
        for (Layer* offscreenLayer : mOffscreenLayers) {
            offscreenLayer->traverse(LayerVector::StateSet::Drawing,
                                     [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); });
        }
    } else {
    std::ostringstream out;
    out << "\nComposition list\n";
    ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK;
@@ -6708,7 +6624,6 @@ void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) {
    result = out.str();
    dumpHwcLayersMinidump(result);
}
}

perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const {
    std::unordered_set<uint64_t> stackIdsToSkip;
@@ -6828,9 +6743,6 @@ void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) cons
}

void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const {
    if (!mLayerLifecycleManagerEnabled) {
        return dumpHwcLayersMinidumpLockedLegacy(result);
    }
    for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) {
        const auto displayId = HalDisplayId::tryCast(display->getId());
        if (!displayId) {
@@ -6910,8 +6822,7 @@ void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositio
     * Dump the visible layer list
     */
    colorizer.bold(result);
    StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n",
                  mLayerLifecycleManagerEnabled ? "true" : "false");
    StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", "true");
    StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n",
                  mNumLayers.load());
    colorizer.reset(result);
@@ -8635,13 +8546,9 @@ ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl(
}

void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const {
    if (mLayerLifecycleManagerEnabled) {
    for (auto& layer : mLegacyLayers) {
        visitor(layer.second.get());
    }
    } else {
        mDrawingState.traverse(visitor);
    }
}

// ---------------------------------------------------------------------------
@@ -9357,7 +9264,6 @@ void SurfaceFlinger::updateLayerMetadataSnapshot() {
void SurfaceFlinger::moveSnapshotsFromCompositionArgs(
        compositionengine::CompositionRefreshArgs& refreshArgs,
        const std::vector<std::pair<Layer*, LayerFE*>>& layers) {
    if (mLayerLifecycleManagerEnabled) {
    std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots =
            mLayerSnapshotBuilder.getSnapshots();
    for (auto [_, layerFE] : layers) {
@@ -9365,17 +9271,10 @@ void SurfaceFlinger::moveSnapshotsFromCompositionArgs(
        snapshots[i] = std::move(layerFE->mSnapshot);
    }
}
    if (!mLayerLifecycleManagerEnabled) {
        for (auto [layer, layerFE] : layers) {
            layer->updateLayerSnapshot(std::move(layerFE->mSnapshot));
        }
    }
}

std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs(
        compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) {
    std::vector<std::pair<Layer*, LayerFE*>> layers;
    if (mLayerLifecycleManagerEnabled) {
    nsecs_t currentTime = systemTime();
    const bool needsMetadata = mCompositionEngine->getFeatureFlags().test(
            compositionengine::Feature::kSnapshotLayerMetadata);
@@ -9406,40 +9305,8 @@ std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToComposit
            [needsMetadata](const frontend::LayerSnapshot& snapshot) {
                return snapshot.isVisible ||
                        (needsMetadata &&
                             snapshot.changes.test(
                                     frontend::RequestedLayerState::Changes::Metadata));
                         snapshot.changes.test(frontend::RequestedLayerState::Changes::Metadata));
            });
    }
    if (!mLayerLifecycleManagerEnabled) {
        auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) {
            if (const auto& layerFE = layer->getCompositionEngineLayerFE()) {
                if (cursorOnly &&
                    layer->getLayerSnapshot()->compositionType !=
                            aidl::android::hardware::graphics::composer3::Composition::CURSOR)
                    return;
                layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame);
                layerFE->mSnapshot = layer->stealLayerSnapshot();
                refreshArgs.layers.push_back(layerFE);
                layers.emplace_back(layer, layerFE.get());
            }
        };

        if (cursorOnly || !mVisibleRegionsDirty) {
            // for hot path avoid traversals by walking though the previous composition list
            for (sp<Layer> layer : mPreviouslyComposedLayers) {
                moveSnapshots(layer.get());
            }
        } else {
            mPreviouslyComposedLayers.clear();
            mDrawingState.traverseInZOrder(
                    [&moveSnapshots](Layer* layer) { moveSnapshots(layer); });
            mPreviouslyComposedLayers.reserve(layers.size());
            for (auto [layer, _] : layers) {
                mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer));
            }
        }
    }

    return layers;
}

+0 −2
Original line number Diff line number Diff line
@@ -1506,8 +1506,6 @@ private:
    }

    bool mPowerHintSessionEnabled;

    bool mLayerLifecycleManagerEnabled = true;
    // Whether a display should be turned on when initialized
    bool mSkipPowerOnForQuiescent;