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

Commit f54181b2 authored by Pascal Muetschard's avatar Pascal Muetschard Committed by Pascal Mütschard
Browse files

Add a flag to callbacks whether to include jank data.

For transaction on-complete callbacks, SurfaceFlinger will now only send the JankData if the flag is set. If the flag is not set on all callbacks on a surface in a transaction, any pending jank data for that surface is now dropped. The client ensures that the flag is set on any callback on surfaces for which a jank listener is registered. Thus, the data now dropped by SurfaceFlinger would have been dropped on the client side anyways.

Bug: 235178314
Bug: 221393601
Test: atest SurfaceFlinger_test
Change-Id: I176d6962f09b587b39c5d106c48949571151f3bd
parent b290a139
Loading
Loading
Loading
Loading
+18 −2
Original line number Original line Diff line number Diff line
@@ -39,6 +39,12 @@ enum class Tag : uint32_t {


} // Anonymous namespace
} // Anonymous namespace


namespace { // Anonymous

constexpr int32_t kSerializedCallbackTypeOnCompelteWithJankData = 2;

} // Anonymous namespace

status_t FrameEventHistoryStats::writeToParcel(Parcel* output) const {
status_t FrameEventHistoryStats::writeToParcel(Parcel* output) const {
    status_t err = output->writeUint64(frameNumber);
    status_t err = output->writeUint64(frameNumber);
    if (err != NO_ERROR) return err;
    if (err != NO_ERROR) return err;
@@ -349,7 +355,11 @@ ListenerCallbacks ListenerCallbacks::filter(CallbackId::Type type) const {


status_t CallbackId::writeToParcel(Parcel* output) const {
status_t CallbackId::writeToParcel(Parcel* output) const {
    SAFE_PARCEL(output->writeInt64, id);
    SAFE_PARCEL(output->writeInt64, id);
    if (type == Type::ON_COMPLETE && includeJankData) {
        SAFE_PARCEL(output->writeInt32, kSerializedCallbackTypeOnCompelteWithJankData);
    } else {
        SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(type));
        SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(type));
    }
    return NO_ERROR;
    return NO_ERROR;
}
}


@@ -357,7 +367,13 @@ status_t CallbackId::readFromParcel(const Parcel* input) {
    SAFE_PARCEL(input->readInt64, &id);
    SAFE_PARCEL(input->readInt64, &id);
    int32_t typeAsInt;
    int32_t typeAsInt;
    SAFE_PARCEL(input->readInt32, &typeAsInt);
    SAFE_PARCEL(input->readInt32, &typeAsInt);
    if (typeAsInt == kSerializedCallbackTypeOnCompelteWithJankData) {
        type = Type::ON_COMPLETE;
        includeJankData = true;
    } else {
        type = static_cast<CallbackId::Type>(typeAsInt);
        type = static_cast<CallbackId::Type>(typeAsInt);
        includeJankData = false;
    }
    return NO_ERROR;
    return NO_ERROR;
}
}


+5 −0
Original line number Original line Diff line number Diff line
@@ -257,6 +257,11 @@ CallbackId TransactionCompletedListener::addCallbackFunction(


    for (const auto& surfaceControl : surfaceControls) {
    for (const auto& surfaceControl : surfaceControls) {
        callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
        callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;

        if (callbackType == CallbackId::Type::ON_COMPLETE &&
            mJankListeners.count(surfaceControl->getLayerId()) != 0) {
            callbackId.includeJankData = true;
        }
    }
    }


    return callbackId;
    return callbackId;
+7 −2
Original line number Original line Diff line number Diff line
@@ -40,10 +40,15 @@ class ListenerCallbacks;
class CallbackId : public Parcelable {
class CallbackId : public Parcelable {
public:
public:
    int64_t id;
    int64_t id;
    enum class Type : int32_t { ON_COMPLETE, ON_COMMIT } type;
    enum class Type : int32_t {
        ON_COMPLETE = 0,
        ON_COMMIT = 1,
        /*reserved for serialization = 2*/
    } type;
    bool includeJankData; // Only respected for ON_COMPLETE callbacks.


    CallbackId() {}
    CallbackId() {}
    CallbackId(int64_t id, Type type) : id(id), type(type) {}
    CallbackId(int64_t id, Type type) : id(id), type(type), includeJankData(false) {}
    status_t writeToParcel(Parcel* output) const override;
    status_t writeToParcel(Parcel* output) const override;
    status_t readFromParcel(const Parcel* input) override;
    status_t readFromParcel(const Parcel* input) override;


+35 −10
Original line number Original line Diff line number Diff line
@@ -734,6 +734,40 @@ bool Layer::isSecure() const {
    return (p != nullptr) ? p->isSecure() : false;
    return (p != nullptr) ? p->isSecure() : false;
}
}


void Layer::transferAvailableJankData(const std::deque<sp<CallbackHandle>>& handles,
                                      std::vector<JankData>& jankData) {
    if (mPendingJankClassifications.empty() ||
        !mPendingJankClassifications.front()->getJankType()) {
        return;
    }

    bool includeJankData = false;
    for (const auto& handle : handles) {
        for (const auto& cb : handle->callbackIds) {
            if (cb.includeJankData) {
                includeJankData = true;
                break;
            }
        }

        if (includeJankData) {
            jankData.reserve(mPendingJankClassifications.size());
            break;
        }
    }

    while (!mPendingJankClassifications.empty() &&
           mPendingJankClassifications.front()->getJankType()) {
        if (includeJankData) {
            std::shared_ptr<frametimeline::SurfaceFrame> surfaceFrame =
                    mPendingJankClassifications.front();
            jankData.emplace_back(
                    JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value()));
        }
        mPendingJankClassifications.pop_front();
    }
}

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// transaction
// transaction
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -2798,16 +2832,7 @@ void Layer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
    }
    }


    std::vector<JankData> jankData;
    std::vector<JankData> jankData;
    jankData.reserve(mPendingJankClassifications.size());
    transferAvailableJankData(mDrawingState.callbackHandles, jankData);
    while (!mPendingJankClassifications.empty() &&
           mPendingJankClassifications.front()->getJankType()) {
        std::shared_ptr<frametimeline::SurfaceFrame> surfaceFrame =
                mPendingJankClassifications.front();
        mPendingJankClassifications.pop_front();
        jankData.emplace_back(
                JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value()));
    }

    mFlinger->getTransactionCallbackInvoker().addCallbackHandles(mDrawingState.callbackHandles,
    mFlinger->getTransactionCallbackInvoker().addCallbackHandles(mDrawingState.callbackHandles,
                                                                 jankData);
                                                                 jankData);
    mDrawingState.callbackHandles = {};
    mDrawingState.callbackHandles = {};
+5 −0
Original line number Original line Diff line number Diff line
@@ -1064,6 +1064,11 @@ private:


    void updateChildrenSnapshots(bool updateGeometry);
    void updateChildrenSnapshots(bool updateGeometry);


    // Fills the provided vector with the currently available JankData and removes the processed
    // JankData from the pending list.
    void transferAvailableJankData(const std::deque<sp<CallbackHandle>>& handles,
                                   std::vector<JankData>& jankData);

    // Cached properties computed from drawing state
    // Cached properties computed from drawing state
    // Effective transform taking into account parent transforms and any parent scaling, which is
    // Effective transform taking into account parent transforms and any parent scaling, which is
    // a transform from the current layer coordinate space to display(screen) coordinate space.
    // a transform from the current layer coordinate space to display(screen) coordinate space.