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

Commit df59f474 authored by Vishnu Nair's avatar Vishnu Nair Committed by Ady Abraham
Browse files

SF: avoid a composition cycle when the FrameRate votes updates

SF would still do a composition if the display mode changes, but
it is not required for every frame rate vote change.

Bug: 339759346
Test: android.platform.test.scenario.gmail.OpenCloseComposeEmailMicrobenchmark#testOpenCloseComposeEmail
Change-Id: Ia01a13b1a167b3a0a67cf7be3db5e64b9405580a
parent ef7f5d11
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -279,6 +279,9 @@ struct layer_state_t {
            layer_state_t::eDropInputModeChanged | layer_state_t::eTrustedOverlayChanged |
            layer_state_t::eLayerStackChanged;

    // Changes requiring a composition pass.
    static constexpr uint64_t REQUIRES_COMPOSITION = layer_state_t::CONTENT_DIRTY;

    // Changes that affect the visible region on a display.
    static constexpr uint64_t VISIBLE_REGION_CHANGES = layer_state_t::GEOMETRY_CHANGES |
            layer_state_t::HIERARCHY_CHANGES | layer_state_t::eAlphaChanged;
+12 −6
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ void LayerLifecycleManager::addLayers(std::vector<std::unique_ptr<RequestedLayer
        return;
    }

    mGlobalChanges |= RequestedLayerState::Changes::Hierarchy;
    mGlobalChanges |= RequestedLayerState::Changes::Hierarchy |
            RequestedLayerState::Changes::RequiresComposition;
    for (auto& newLayer : newLayers) {
        RequestedLayerState& layer = *newLayer.get();
        auto [it, inserted] = mIdToLayer.try_emplace(layer.id, References{.owner = layer});
@@ -104,7 +105,8 @@ void LayerLifecycleManager::onHandlesDestroyed(
        if (!layer.canBeDestroyed()) {
            continue;
        }
        layer.changes |= RequestedLayerState::Changes::Destroyed;
        layer.changes |= RequestedLayerState::Changes::Destroyed |
                RequestedLayerState::Changes::RequiresComposition;
        layersToBeDestroyed.emplace_back(layerId);
    }

@@ -112,7 +114,8 @@ void LayerLifecycleManager::onHandlesDestroyed(
        return;
    }

    mGlobalChanges |= RequestedLayerState::Changes::Hierarchy;
    mGlobalChanges |= RequestedLayerState::Changes::Hierarchy |
            RequestedLayerState::Changes::RequiresComposition;
    for (size_t i = 0; i < layersToBeDestroyed.size(); i++) {
        uint32_t layerId = layersToBeDestroyed[i];
        auto it = mIdToLayer.find(layerId);
@@ -142,7 +145,8 @@ void LayerLifecycleManager::onHandlesDestroyed(
            if (linkedLayer->parentId == layer.id) {
                linkedLayer->parentId = UNASSIGNED_LAYER_ID;
                if (linkedLayer->canBeDestroyed()) {
                    linkedLayer->changes |= RequestedLayerState::Changes::Destroyed;
                    linkedLayer->changes |= RequestedLayerState::Changes::Destroyed |
                            RequestedLayerState::Changes::RequiresComposition;
                    layersToBeDestroyed.emplace_back(linkedLayer->id);
                }
            }
@@ -249,7 +253,8 @@ void LayerLifecycleManager::applyTransactions(const std::vector<TransactionState
                            layer_state_t::eDataspaceChanged | layer_state_t::eAlphaChanged;
                    bgColorLayer->changes |= RequestedLayerState::Changes::Content;
                    mChangedLayers.push_back(bgColorLayer);
                    mGlobalChanges |= RequestedLayerState::Changes::Content;
                    mGlobalChanges |= RequestedLayerState::Changes::Content |
                            RequestedLayerState::Changes::RequiresComposition;
                }
            }

@@ -407,7 +412,8 @@ void LayerLifecycleManager::fixRelativeZLoop(uint32_t relativeRootId) {
    layer.relativeParentId = unlinkLayer(layer.relativeParentId, layer.id);
    layer.changes |=
            RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::RelativeParent;
    mGlobalChanges |= RequestedLayerState::Changes::Hierarchy;
    mGlobalChanges |= RequestedLayerState::Changes::Hierarchy |
            RequestedLayerState::Changes::RequiresComposition;
}

// Some layers mirror the entire display stack. Since we don't have a single root layer per display
+6 −2
Original line number Diff line number Diff line
@@ -58,7 +58,8 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args)
        parentId(args.parentId),
        layerIdToMirror(args.layerIdToMirror) {
    layerId = static_cast<int32_t>(args.sequence);
    changes |= RequestedLayerState::Changes::Created;
    changes |= RequestedLayerState::Changes::Created |
            RequestedLayerState::Changes::RequiresComposition;
    metadata.merge(args.metadata);
    changes |= RequestedLayerState::Changes::Metadata;
    handleAlive = true;
@@ -248,7 +249,8 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta

    if (hadSomethingToDraw != hasSomethingToDraw()) {
        changes |= RequestedLayerState::Changes::Visibility |
                RequestedLayerState::Changes::VisibleRegion;
                RequestedLayerState::Changes::VisibleRegion |
                RequestedLayerState::Changes::RequiresComposition;
    }
    if (clientChanges & layer_state_t::HIERARCHY_CHANGES)
        changes |= RequestedLayerState::Changes::Hierarchy;
@@ -258,6 +260,8 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta
        changes |= RequestedLayerState::Changes::Geometry;
    if (clientChanges & layer_state_t::AFFECTS_CHILDREN)
        changes |= RequestedLayerState::Changes::AffectsChildren;
    if (clientChanges & layer_state_t::REQUIRES_COMPOSITION)
        changes |= RequestedLayerState::Changes::RequiresComposition;
    if (clientChanges & layer_state_t::INPUT_CHANGES)
        changes |= RequestedLayerState::Changes::Input;
    if (clientChanges & layer_state_t::VISIBLE_REGION_CHANGES)
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ struct RequestedLayerState : layer_state_t {
        BufferSize = 1u << 18,
        GameMode = 1u << 19,
        BufferUsageFlags = 1u << 20,
        RequiresComposition = 1u << 21,
    };
    static Rect reduce(const Rect& win, const Region& exclude);
    RequestedLayerState(const LayerCreationArgs&);
+16 −4
Original line number Diff line number Diff line
@@ -1411,11 +1411,12 @@ void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) {
    }
}

void SurfaceFlinger::initiateDisplayModeChanges() {
bool SurfaceFlinger::initiateDisplayModeChanges() {
    ATRACE_CALL();

    std::optional<PhysicalDisplayId> displayToUpdateImmediately;

    bool mustComposite = false;
    for (const auto& [id, physical] : mPhysicalDisplays) {
        const auto display = getDisplayDeviceLocked(id);
        if (!display) continue;
@@ -1472,7 +1473,11 @@ void SurfaceFlinger::initiateDisplayModeChanges() {
        mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline);

        if (outTimeline.refreshRequired) {
            if (FlagManager::getInstance().vrr_bugfix_24q4()) {
                mustComposite = true;
            } else {
                scheduleComposite(FrameHint::kNone);
            }
        } else {
            // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange`
            // for all displays. This was only needed when the loop iterated over `mDisplays` rather
@@ -1490,6 +1495,8 @@ void SurfaceFlinger::initiateDisplayModeChanges() {
            applyActiveMode(display);
        }
    }

    return mustComposite;
}

void SurfaceFlinger::disableExpensiveRendering() {
@@ -2439,7 +2446,12 @@ bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs,
        mUpdateAttachedChoreographer = true;
    }
    outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0;
    if (FlagManager::getInstance().vrr_bugfix_24q4()) {
        mustComposite |= mLayerLifecycleManager.getGlobalChanges().test(
                frontend::RequestedLayerState::Changes::RequiresComposition);
    } else {
        mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0;
    }

    bool newDataLatched = false;
    ATRACE_NAME("DisplayCallbackAndStatsUpdates");
@@ -2664,7 +2676,7 @@ bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId,
                                                        ? &mLayerHierarchyBuilder.getHierarchy()
                                                        : nullptr,
                                                updateAttachedChoreographer);
        initiateDisplayModeChanges();
        mustComposite |= initiateDisplayModeChanges();
    }

    updateCursorAsync();
Loading