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

Commit 43752eba authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: get nextPredictedPresentTime directly from frame timeline

ag/13715677 moved the call to check whether a frame is early or not
before a transaction is applied.
This created a bug in BufferStateLayer::nextPredictedPresentTime since
it is checking the drawing state surface frame, which is not valid since
the transaction is not applied yet. This CL is fixing this by pasing the
vsync id itself, and getting the expected present time base on that
vsync id.

Change-Id: I0f95f2a3a2efff921964a6fb5f9b50e0fcc65a85
Test: launch an app and observe systraces
Bug: 181978893
parent a170ec6a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -424,12 +424,12 @@ bool BufferLayer::shouldPresentNow(nsecs_t expectedPresentTime) const {
    return isBufferDue(expectedPresentTime);
}

bool BufferLayer::frameIsEarly(nsecs_t expectedPresentTime) const {
bool BufferLayer::frameIsEarly(nsecs_t expectedPresentTime, int64_t vsyncId) const {
    // TODO(b/169901895): kEarlyLatchVsyncThreshold should be based on the
    // vsync period. We can do this change as soon as ag/13100772 is merged.
    constexpr static std::chrono::nanoseconds kEarlyLatchVsyncThreshold = 5ms;

    const auto presentTime = nextPredictedPresentTime();
    const auto presentTime = nextPredictedPresentTime(vsyncId);
    if (!presentTime.has_value()) {
        return false;
    }
+2 −2
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ protected:

    // Returns true if the next frame is considered too early to present
    // at the given expectedPresentTime
    bool frameIsEarly(nsecs_t expectedPresentTime) const;
    bool frameIsEarly(nsecs_t expectedPresentTime, int64_t vsyncId) const;

    std::atomic<bool> mAutoRefresh{false};
    std::atomic<bool> mSidebandStreamChanged{false};
@@ -238,7 +238,7 @@ private:
    FloatRect computeSourceBounds(const FloatRect& parentBounds) const override;

    // Returns the predicted present time of the next frame if available
    virtual std::optional<nsecs_t> nextPredictedPresentTime() const = 0;
    virtual std::optional<nsecs_t> nextPredictedPresentTime(int64_t vsyncId) const = 0;

    // The amount of time SF can delay a frame if it is considered early based
    // on the VsyncModulator::VsyncConfig::appWorkDuration
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ bool BufferQueueLayer::hasFrameUpdate() const {
    return mQueuedFrames > 0;
}

std::optional<nsecs_t> BufferQueueLayer::nextPredictedPresentTime() const {
std::optional<nsecs_t> BufferQueueLayer::nextPredictedPresentTime(int64_t /*vsyncId*/) const {
    Mutex::Autolock lock(mQueueItemLock);
    if (mQueueItems.empty()) {
        return std::nullopt;
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ private:
    // Temporary - Used only for LEGACY camera mode.
    uint32_t getProducerStickyTransform() const;

    std::optional<nsecs_t> nextPredictedPresentTime() const override;
    std::optional<nsecs_t> nextPredictedPresentTime(int64_t vsyncId) const override;

    sp<BufferLayerConsumer> mConsumer;
    sp<IGraphicBufferProducer> mProducer;
+5 −4
Original line number Diff line number Diff line
@@ -605,13 +605,14 @@ bool BufferStateLayer::hasFrameUpdate() const {
    return mCurrentStateModified && (c.buffer != nullptr || c.bgColorLayer != nullptr);
}

std::optional<nsecs_t> BufferStateLayer::nextPredictedPresentTime() const {
    const State& drawingState(getDrawingState());
    if (!drawingState.isAutoTimestamp || !drawingState.bufferSurfaceFrameTX) {
std::optional<nsecs_t> BufferStateLayer::nextPredictedPresentTime(int64_t vsyncId) const {
    const auto prediction =
            mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(vsyncId);
    if (!prediction.has_value()) {
        return std::nullopt;
    }

    return drawingState.bufferSurfaceFrameTX->getPredictions().presentTime;
    return prediction->presentTime;
}

status_t BufferStateLayer::updateTexImage(bool& /*recomputeVisibleRegions*/, nsecs_t latchTime,
Loading