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

Commit dd50a3cf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add postTime and desired present time to BufferStateLayer TimeStats"

parents 01b6b4d6 bc6ddb12
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -345,6 +345,14 @@ FloatRect BufferStateLayer::computeSourceBounds(const FloatRect& parentBounds) c
    return parentBounds;
}

void BufferStateLayer::setPostTime(nsecs_t postTime) {
    mFlinger->mTimeStats->setPostTime(getSequence(), getFrameNumber(), getName().c_str(), postTime);
}

void BufferStateLayer::setDesiredPresentTime(nsecs_t desiredPresentTime) {
    mDesiredPresentTime = desiredPresentTime;
}

// -----------------------------------------------------------------------

// -----------------------------------------------------------------------
@@ -359,8 +367,7 @@ bool BufferStateLayer::fenceHasSignaled() const {
}

nsecs_t BufferStateLayer::getDesiredPresentTime() {
    // TODO(marissaw): support an equivalent to desiredPresentTime for timestats metrics
    return 0;
    return mDesiredPresentTime;
}

std::shared_ptr<FenceTime> BufferStateLayer::getCurrentFenceTime() const {
@@ -532,8 +539,6 @@ status_t BufferStateLayer::updateTexImage(bool& /*recomputeVisibleRegions*/, nse
        }
    }

    // TODO(marissaw): properly support mTimeStats
    mFlinger->mTimeStats->setPostTime(layerID, getFrameNumber(), getName().c_str(), latchTime);
    mFlinger->mTimeStats->setAcquireFence(layerID, getFrameNumber(), getCurrentFenceTime());
    mFlinger->mTimeStats->setLatchTime(layerID, getFrameNumber(), latchTime);

+5 −0
Original line number Diff line number Diff line
@@ -89,6 +89,9 @@ public:

    Rect getBufferSize(const State& s) const override;
    FloatRect computeSourceBounds(const FloatRect& parentBounds) const override;

    void setPostTime(nsecs_t postTime) override;
    void setDesiredPresentTime(nsecs_t desiredPresentTime) override;
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
@@ -149,6 +152,8 @@ private:
    bool mReleasePreviousBuffer = false;
    nsecs_t mCallbackHandleAcquireTime = -1;

    nsecs_t mDesiredPresentTime = -1;

    // TODO(marissaw): support sticky transform for LEGACY camera mode
};

+3 −0
Original line number Diff line number Diff line
@@ -434,6 +434,9 @@ public:
    }
    virtual Rect getCrop(const Layer::State& s) const { return s.crop_legacy; }

    virtual void setPostTime(nsecs_t /*postTime*/) {}
    virtual void setDesiredPresentTime(nsecs_t /*desiredPresentTime*/) {}

protected:
    virtual bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
                                    bool useIdentityTransform, Region& clearRegion,
+17 −7
Original line number Diff line number Diff line
@@ -3437,12 +3437,13 @@ bool SurfaceFlinger::flushTransactionQueues() {
        auto& [applyToken, transactionQueue] = *it;

        while (!transactionQueue.empty()) {
            const auto& [states, displays, flags, desiredPresentTime, privileged] =
            const auto& [states, displays, flags, desiredPresentTime, postTime, privileged] =
                    transactionQueue.front();
            if (!transactionIsReadyToBeApplied(desiredPresentTime, states)) {
                break;
            }
            applyTransactionState(states, displays, flags, mPendingInputWindowCommands, privileged);
            applyTransactionState(states, displays, flags, mPendingInputWindowCommands,
                                  desiredPresentTime, postTime, privileged);
            transactionQueue.pop();
        }

@@ -3502,6 +3503,8 @@ void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& states,
                                         int64_t desiredPresentTime) {
    ATRACE_CALL();

    const int64_t postTime = systemTime();

    bool privileged = callingThreadHasUnscopedSurfaceFlingerAccess();

    Mutex::Autolock _l(mStateLock);
@@ -3514,17 +3517,19 @@ void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& states,
    if (mTransactionQueues.find(applyToken) != mTransactionQueues.end() ||
        !transactionIsReadyToBeApplied(desiredPresentTime, states)) {
        mTransactionQueues[applyToken].emplace(states, displays, flags, desiredPresentTime,
                privileged);
                                               postTime, privileged);
        setTransactionFlags(eTransactionNeeded);
        return;
    }

    applyTransactionState(states, displays, flags, inputWindowCommands, privileged);
    applyTransactionState(states, displays, flags, inputWindowCommands, desiredPresentTime,
                          postTime, privileged);
}

void SurfaceFlinger::applyTransactionState(const Vector<ComposerState>& states,
                                           const Vector<DisplayState>& displays, uint32_t flags,
                                           const InputWindowCommands& inputWindowCommands,
                                           const int64_t desiredPresentTime, const int64_t postTime,
                                           bool privileged) {
    uint32_t transactionFlags = 0;

@@ -3550,7 +3555,7 @@ void SurfaceFlinger::applyTransactionState(const Vector<ComposerState>& states,

    uint32_t clientStateFlags = 0;
    for (const ComposerState& state : states) {
        clientStateFlags |= setClientStateLocked(state, privileged);
        clientStateFlags |= setClientStateLocked(state, desiredPresentTime, postTime, privileged);
    }
    // If the state doesn't require a traversal and there are callbacks, send them now
    if (!(clientStateFlags & eTraversalNeeded)) {
@@ -3663,6 +3668,7 @@ bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess() {
}

uint32_t SurfaceFlinger::setClientStateLocked(const ComposerState& composerState,
                                              int64_t desiredPresentTime, int64_t postTime,
                                              bool privileged) {
    const layer_state_t& s = composerState.state;
    sp<Client> client(static_cast<Client*>(composerState.client.get()));
@@ -3905,7 +3911,11 @@ uint32_t SurfaceFlinger::setClientStateLocked(const ComposerState& composerState
        sp<GraphicBuffer> buffer =
                BufferStateLayerCache::getInstance().get(s.cachedBuffer.token,
                                                         s.cachedBuffer.bufferId);
        if (layer->setBuffer(buffer)) flags |= eTraversalNeeded;
        if (layer->setBuffer(buffer)) {
            flags |= eTraversalNeeded;
            layer->setPostTime(postTime);
            layer->setDesiredPresentTime(desiredPresentTime);
        }
    }
    if (layer->setTransactionCompletedListeners(callbackHandles)) flags |= eTraversalNeeded;
    // Do not put anything that updates layer state or modifies flags after
+8 −6
Original line number Diff line number Diff line
@@ -572,6 +572,7 @@ private:
    void applyTransactionState(const Vector<ComposerState>& state,
                               const Vector<DisplayState>& displays, uint32_t flags,
                               const InputWindowCommands& inputWindowCommands,
                               const int64_t desiredPresentTime, const int64_t postTime,
                               bool privileged) REQUIRES(mStateLock);
    bool flushTransactionQueues();
    uint32_t getTransactionFlags(uint32_t flags);
@@ -584,8 +585,8 @@ private:
    bool containsAnyInvalidClientState(const Vector<ComposerState>& states);
    bool transactionIsReadyToBeApplied(int64_t desiredPresentTime,
                                       const Vector<ComposerState>& states);
    uint32_t setClientStateLocked(const ComposerState& composerState, bool privileged)
            REQUIRES(mStateLock);
    uint32_t setClientStateLocked(const ComposerState& composerState, int64_t desiredPresentTime,
                                  int64_t postTime, bool privileged) REQUIRES(mStateLock);
    uint32_t setDisplayStateLocked(const DisplayState& s) REQUIRES(mStateLock);
    uint32_t addInputWindowCommands(const InputWindowCommands& inputWindowCommands)
            REQUIRES(mStateLock);
@@ -1047,18 +1048,19 @@ private:
    struct TransactionState {
        TransactionState(const Vector<ComposerState>& composerStates,
                         const Vector<DisplayState>& displayStates, uint32_t transactionFlags,
                         int64_t desiredPresentTime,
                         bool privileged)
                         int64_t desiredPresentTime, int64_t postTime, bool privileged)
              : states(composerStates),
                displays(displayStates),
                flags(transactionFlags),
                time(desiredPresentTime),
                desiredPresentTime(desiredPresentTime),
                postTime(postTime),
                privileged(privileged) {}

        Vector<ComposerState> states;
        Vector<DisplayState> displays;
        uint32_t flags;
        int64_t time;
        const int64_t desiredPresentTime;
        const int64_t postTime;
        bool privileged;
    };
    std::unordered_map<sp<IBinder>, std::queue<TransactionState>, IBinderHash> mTransactionQueues;