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

Commit 781d7259 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

SF: Use snapshots for TrustedPresentationListener updates

Also pass the correct display to
the compute function.

Bug: 238781169
Test: presubmit
Change-Id: I465f275fa1247ff98b4d578a26416d8c100170de
parent dff1554c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -168,4 +168,11 @@ std::string LayerSnapshot::getDebugString() const {
    return debug.str();
}

FloatRect LayerSnapshot::sourceBounds() const {
    if (!externalTexture) {
        return geomLayerBounds;
    }
    return geomBufferSize.toFloatRect();
}

} // namespace android::surfaceflinger::frontend
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ struct LayerSnapshot : public compositionengine::LayerFECompositionState {
    std::string getDebugString() const;
    std::string getIsVisibleReason() const;
    bool hasInputInfo() const;
    FloatRect sourceBounds() const;
};

} // namespace android::surfaceflinger::frontend
+10 −8
Original line number Diff line number Diff line
@@ -254,7 +254,7 @@ Layer::~Layer() {
    }
    if (hasTrustedPresentationListener()) {
        mFlinger->mNumTrustedPresentationListeners--;
        updateTrustedPresentationState(nullptr, -1 /* time_in_ms */, true /* leaveState*/);
        updateTrustedPresentationState(nullptr, nullptr, -1 /* time_in_ms */, true /* leaveState*/);
    }
}

@@ -285,7 +285,7 @@ void Layer::removeFromCurrentState() {
        mRemovedFromDrawingState = true;
        mFlinger->mScheduler->deregisterLayer(this);
    }
    updateTrustedPresentationState(nullptr, -1 /* time_in_ms */, true /* leaveState*/);
    updateTrustedPresentationState(nullptr, nullptr, -1 /* time_in_ms */, true /* leaveState*/);

    mFlinger->markLayerPendingRemovalLocked(sp<Layer>::fromExisting(this));
}
@@ -384,8 +384,9 @@ FloatRect Layer::getBounds(const Region& activeTransparentRegion) const {
}

// No early returns.
void Layer::updateTrustedPresentationState(const DisplayDevice* display, int64_t time_in_ms,
                                           bool leaveState) {
void Layer::updateTrustedPresentationState(const DisplayDevice* display,
                                           const frontend::LayerSnapshot* snapshot,
                                           int64_t time_in_ms, bool leaveState) {
    if (!hasTrustedPresentationListener()) {
        return;
    }
@@ -394,12 +395,13 @@ void Layer::updateTrustedPresentationState(const DisplayDevice* display, int64_t

    if (!leaveState) {
        const auto outputLayer = findOutputLayerForDisplay(display);
        if (outputLayer != nullptr) {
        if (outputLayer != nullptr && snapshot != nullptr) {
            mLastComputedTrustedPresentationState =
                    computeTrustedPresentationState(mBounds, mSourceBounds,
                    computeTrustedPresentationState(snapshot->geomLayerBounds,
                                                    snapshot->sourceBounds(),
                                                    outputLayer->getState().coveredRegion,
                                                    mScreenBounds, getCompositionState()->alpha,
                                                    getCompositionState()->geomLayerTransform,
                                                    snapshot->transformedBounds, snapshot->alpha,
                                                    snapshot->geomLayerTransform,
                                                    mTrustedPresentationThresholds);
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -539,7 +539,8 @@ public:
                                                const FloatRect& screenBounds, float,
                                                const ui::Transform&,
                                                const TrustedPresentationThresholds&);
    void updateTrustedPresentationState(const DisplayDevice* display, int64_t time_in_ms,
    void updateTrustedPresentationState(const DisplayDevice* display,
                                        const frontend::LayerSnapshot* snapshot, int64_t time_in_ms,
                                        bool leaveState);

    inline bool hasTrustedPresentationListener() {
+12 −2
Original line number Diff line number Diff line
@@ -2750,13 +2750,23 @@ void SurfaceFlinger::postComposition(nsecs_t callTime) {
    }

    if (mNumTrustedPresentationListeners > 0) {
        display::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay;
        {
            Mutex::Autolock lock(mStateLock);
            for (const auto& [token, display] : mDisplays) {
                layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get());
            }
        }

        // We avoid any reverse traversal upwards so this shouldn't be too expensive
        mDrawingState.traverse([&](Layer* layer) {
            if (!layer->hasTrustedPresentationListener()) {
                return;
            }
            layer->updateTrustedPresentationState(display, nanoseconds_to_milliseconds(callTime),
                                                  false);
            const auto display =
                    layerStackToDisplay.get(layer->getLayerSnapshot()->outputFilter.layerStack);
            layer->updateTrustedPresentationState(display->get(), layer->getLayerSnapshot(),
                                                  nanoseconds_to_milliseconds(callTime), false);
        });
    }