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 Original line Diff line number Diff line
@@ -345,6 +345,14 @@ FloatRect BufferStateLayer::computeSourceBounds(const FloatRect& parentBounds) c
    return parentBounds;
    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() {
nsecs_t BufferStateLayer::getDesiredPresentTime() {
    // TODO(marissaw): support an equivalent to desiredPresentTime for timestats metrics
    return mDesiredPresentTime;
    return 0;
}
}


std::shared_ptr<FenceTime> BufferStateLayer::getCurrentFenceTime() const {
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->setAcquireFence(layerID, getFrameNumber(), getCurrentFenceTime());
    mFlinger->mTimeStats->setLatchTime(layerID, getFrameNumber(), latchTime);
    mFlinger->mTimeStats->setLatchTime(layerID, getFrameNumber(), latchTime);


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


    Rect getBufferSize(const State& s) const override;
    Rect getBufferSize(const State& s) const override;
    FloatRect computeSourceBounds(const FloatRect& parentBounds) 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;
    bool mReleasePreviousBuffer = false;
    nsecs_t mCallbackHandleAcquireTime = -1;
    nsecs_t mCallbackHandleAcquireTime = -1;


    nsecs_t mDesiredPresentTime = -1;

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


+3 −0
Original line number Original line Diff line number Diff line
@@ -434,6 +434,9 @@ public:
    }
    }
    virtual Rect getCrop(const Layer::State& s) const { return s.crop_legacy; }
    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:
protected:
    virtual bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
    virtual bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
                                    bool useIdentityTransform, Region& clearRegion,
                                    bool useIdentityTransform, Region& clearRegion,
+17 −7
Original line number Original line Diff line number Diff line
@@ -3437,12 +3437,13 @@ bool SurfaceFlinger::flushTransactionQueues() {
        auto& [applyToken, transactionQueue] = *it;
        auto& [applyToken, transactionQueue] = *it;


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


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


    const int64_t postTime = systemTime();

    bool privileged = callingThreadHasUnscopedSurfaceFlingerAccess();
    bool privileged = callingThreadHasUnscopedSurfaceFlingerAccess();


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


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


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


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


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


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


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