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

Commit 87f1e3fe authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge "SF: use FenceTime when possible" into sc-dev

parents ce40b1fb 6c1b7aca
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -97,6 +97,34 @@ bool FenceTime::isValid() const {
    return mState != State::INVALID;
}

status_t FenceTime::wait(int timeout) {
    // See if we already have a cached value we can return.
    nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed);
    if (signalTime != Fence::SIGNAL_TIME_PENDING) {
        return NO_ERROR;
    }

    // Hold a reference to the fence on the stack in case the class'
    // reference is removed by another thread. This prevents the
    // fence from being destroyed until the end of this method, where
    // we conveniently do not have the lock held.
    sp<Fence> fence;
    {
        // With the lock acquired this time, see if we have the cached
        // value or if we need to poll the fence.
        std::lock_guard<std::mutex> lock(mMutex);
        if (!mFence.get()) {
            // Another thread set the signal time just before we added the
            // reference to mFence.
            return NO_ERROR;
        }
        fence = mFence;
    }

    // Make the system call without the lock held.
    return fence->wait(timeout);
}

nsecs_t FenceTime::getSignalTime() {
    // See if we already have a cached value we can return.
    nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed);
+7 −0
Original line number Diff line number Diff line
@@ -112,6 +112,13 @@ public:
    // Returns a snapshot of the FenceTime in its current state.
    Snapshot getSnapshot() const;

    // wait waits for up to timeout milliseconds for the fence to signal.  If
    // the fence signals then NO_ERROR is returned. If the timeout expires
    // before the fence signals then -ETIME is returned.  A timeout of
    // TIMEOUT_NEVER may be used to indicate that the call should wait
    // indefinitely for the fence to signal.
    status_t wait(int timeout);

    void signalForTest(nsecs_t signalTime);

private:
+6 −3
Original line number Diff line number Diff line
@@ -432,10 +432,12 @@ bool BufferStateLayer::setBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence
}

bool BufferStateLayer::setAcquireFence(const sp<Fence>& fence) {
    mCurrentState.acquireFence = fence;
    mCurrentState.acquireFenceTime = std::make_unique<FenceTime>(fence);

    // The acquire fences of BufferStateLayers have already signaled before they are set
    mCallbackHandleAcquireTime = fence->getSignalTime();
    mCallbackHandleAcquireTime = mCurrentState.acquireFenceTime->getSignalTime();

    mCurrentState.acquireFence = fence;
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
@@ -691,7 +693,8 @@ status_t BufferStateLayer::updateTexImage(bool& /*recomputeVisibleRegions*/, nse
        // bufferSurfaceFrame could be seen here if a pending state was applied successfully and we
        // are processing the next state.
        addSurfaceFramePresentedForBuffer(bufferSurfaceFrame,
                                          mDrawingState.acquireFence->getSignalTime(), latchTime);
                                          mDrawingState.acquireFenceTime->getSignalTime(),
                                          latchTime);
    }

    mCurrentStateModified = false;
+2 −3
Original line number Diff line number Diff line
@@ -62,10 +62,9 @@ void FrameTracker::setActualPresentTime(nsecs_t presentTime) {
    mFrameRecords[mOffset].actualPresentTime = presentTime;
}

void FrameTracker::setActualPresentFence(
        std::shared_ptr<FenceTime>&& readyFence) {
void FrameTracker::setActualPresentFence(const std::shared_ptr<FenceTime>& readyFence) {
    Mutex::Autolock lock(mMutex);
    mFrameRecords[mOffset].actualPresentFence = std::move(readyFence);
    mFrameRecords[mOffset].actualPresentFence = readyFence;
    mNumFences++;
}

+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public:

    // setActualPresentFence sets the fence that is used to get the time
    // at which the current frame became visible to the user.
    void setActualPresentFence(std::shared_ptr<FenceTime>&& fence);
    void setActualPresentFence(const std::shared_ptr<FenceTime>& fence);

    // setDisplayRefreshPeriod sets the display refresh period in nanoseconds.
    // This is used to compute frame presentation duration statistics relative
Loading