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

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

Merge "surface_control: handle acquire fence on BLAST callbacks"

parents bc661bfc 62e15f0a
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) {
}

struct ASurfaceControlStats {
    int64_t acquireTime;
    std::variant<int64_t, sp<Fence>> acquireTimeOrFence;
    sp<Fence> previousReleaseFence;
    uint64_t frameNumber;
};
@@ -153,7 +153,7 @@ void ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl* control, int3
                                               const SurfaceStats& surfaceStats) {
        ASurfaceControlStats aSurfaceControlStats;

        aSurfaceControlStats.acquireTime = surfaceStats.acquireTime;
        aSurfaceControlStats.acquireTimeOrFence = surfaceStats.acquireTimeOrFence;
        aSurfaceControlStats.previousReleaseFence = surfaceStats.previousReleaseFence;
        aSurfaceControlStats.frameNumber = surfaceStats.eventStats.frameNumber;

@@ -171,7 +171,15 @@ void ASurfaceControl_unregisterSurfaceStatsListener(void* context,
}

int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
    return stats->acquireTime;
    if (const auto* fence = std::get_if<sp<Fence>>(&stats->acquireTimeOrFence)) {
        // We got a fence instead of the acquire time due to latch unsignaled.
        // Ideally the client could just get the acquire time dericly from
        // the fence instead of calling this function which needs to block.
        (*fence)->waitForever("ASurfaceControlStats_getAcquireTime");
        return (*fence)->getSignalTime();
    }

    return std::get<int64_t>(stats->acquireTimeOrFence);
}

uint64_t ASurfaceControlStats_getFrameNumber(ASurfaceControlStats* stats) {
@@ -250,7 +258,7 @@ int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfa
            aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
            "ASurfaceControl not found");

    return aSurfaceControlStats->second.acquireTime;
    return ASurfaceControlStats_getAcquireTime(&aSurfaceControlStats->second);
}

int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
@@ -294,9 +302,10 @@ void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction,

        auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;

        for (const auto& [surfaceControl, latchTime, acquireTime, presentFence, previousReleaseFence, transformHint, frameEvents] : surfaceControlStats) {
        for (const auto& [surfaceControl, latchTime, acquireTimeOrFence, presentFence,
                          previousReleaseFence, transformHint, frameEvents] : surfaceControlStats) {
            ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
            aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime;
            aSurfaceControlStats[aSurfaceControl].acquireTimeOrFence = acquireTimeOrFence;
            aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence;
        }

@@ -643,13 +652,12 @@ void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* aSurfaceTransaction, v
                aSurfaceTransactionStats.transactionCompleted = false;

                auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
                for (const auto&
                             [surfaceControl, latchTime, acquireTime, presentFence,
                              previousReleaseFence, transformHint,
                              frameEvents] : surfaceControlStats) {
                for (const auto& [surfaceControl, latchTime, acquireTimeOrFence, presentFence,
                                  previousReleaseFence, transformHint, frameEvents] :
                     surfaceControlStats) {
                    ASurfaceControl* aSurfaceControl =
                            reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
                    aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime;
                    aSurfaceControlStats[aSurfaceControl].acquireTimeOrFence = acquireTimeOrFence;
                }

                (*func)(callback_context, &aSurfaceTransactionStats);