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

Commit 328a831c authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Clear TrustedPresentationListener when a new listener is set

If a TrustedPresentationListener is overwritten for a Layer, the last
trusted presentation states need to be cleared.

It also needs to make sure composite is called after setting a
TrustedPresentationListener since the layer may already be in the
presented state and there's nothing new to compose. We need to make sure
the presentation state is computed at least once after setting the
TrustedPresentationListener

Test: TrustedPresentationCallbackTest
Bug: 256993331
Change-Id: I5cd344e9609d96c961fc70093ea705ee48f46817
parent 5fc135bf
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -4049,7 +4049,7 @@ void Layer::updateRelativeMetadataSnapshot(const LayerMetadata& relativeLayerMet
    }
}

void Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
bool Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
                                       TrustedPresentationListener const& listener) {
    bool hadTrustedPresentationListener = hasTrustedPresentationListener();
    mTrustedPresentationListener = listener;
@@ -4060,6 +4060,16 @@ void Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thre
    } else if (hadTrustedPresentationListener && !haveTrustedPresentationListener) {
        mFlinger->mNumTrustedPresentationListeners--;
    }

    // Reset trusted presentation states to ensure we start the time again.
    mEnteredTrustedPresentationStateTime = -1;
    mLastReportedTrustedPresentationState = false;
    mLastComputedTrustedPresentationState = false;

    // If there's a new trusted presentation listener, the code needs to go through the composite
    // path to ensure it recomutes the current state and invokes the TrustedPresentationListener if
    // we're already in the requested state.
    return haveTrustedPresentationListener;
}

// ---------------------------------------------------------------------------
+1 −1
Original line number Diff line number Diff line
@@ -754,7 +754,7 @@ public:
    std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer(
            const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName);

    void setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
    bool setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
                                    TrustedPresentationListener const& listener);

    // Creates a new handle each time, so we only expect
+8 −4
Original line number Diff line number Diff line
@@ -4848,8 +4848,10 @@ uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTime
    }

    if (what & layer_state_t::eTrustedPresentationInfoChanged) {
        layer->setTrustedPresentationInfo(s.trustedPresentationThresholds,
                                          s.trustedPresentationListener);
        if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds,
                                              s.trustedPresentationListener)) {
            flags |= eTraversalNeeded;
        }
    }

    if (what & layer_state_t::eFlushJankData) {
@@ -4951,8 +4953,10 @@ uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& f
    }

    if (what & layer_state_t::eTrustedPresentationInfoChanged) {
        layer->setTrustedPresentationInfo(s.trustedPresentationThresholds,
                                          s.trustedPresentationListener);
        if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds,
                                              s.trustedPresentationListener)) {
            flags |= eTraversalNeeded;
        }
    }

    const auto& snapshot = mLayerSnapshotBuilder.getSnapshot(layer->getSequence());