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

Commit 6beb8eea authored by Alec Mouri's avatar Alec Mouri
Browse files

Fix up GPU completion fence for EGL_ANDROID_get_frame_timestamps.

Ensure that it always comes after certain other timestamps.

Bug: 303385401
Change-Id: I0ea9a6658753d1f1819f32223deb4bbdc8d02e75
parent a4cf4de2
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -342,12 +342,23 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber,

    getFrameTimestamp(outRequestedPresentTime, events->requestedPresentTime);
    getFrameTimestamp(outLatchTime, events->latchTime);
    getFrameTimestamp(outFirstRefreshStartTime, events->firstRefreshStartTime);

    nsecs_t firstRefreshStartTime = NATIVE_WINDOW_TIMESTAMP_INVALID;
    getFrameTimestamp(&firstRefreshStartTime, events->firstRefreshStartTime);
    if (outFirstRefreshStartTime) {
        *outFirstRefreshStartTime = firstRefreshStartTime;
    }

    getFrameTimestamp(outLastRefreshStartTime, events->lastRefreshStartTime);
    getFrameTimestamp(outDequeueReadyTime, events->dequeueReadyTime);

    getFrameTimestampFence(outAcquireTime, events->acquireFence,
    nsecs_t acquireTime = NATIVE_WINDOW_TIMESTAMP_INVALID;
    getFrameTimestampFence(&acquireTime, events->acquireFence,
            events->hasAcquireInfo());
    if (outAcquireTime != nullptr) {
        *outAcquireTime = acquireTime;
    }

    getFrameTimestampFence(outGpuCompositionDoneTime,
            events->gpuCompositionDoneFence,
            events->hasGpuCompositionDoneInfo());
@@ -356,6 +367,16 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber,
    getFrameTimestampFence(outReleaseTime, events->releaseFence,
            events->hasReleaseInfo());

    // Fix up the GPU completion fence at this layer -- eglGetFrameTimestampsANDROID() expects
    // that EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID > EGL_RENDERING_COMPLETE_TIME_ANDROID.
    // This is typically true, but SurfaceFlinger may opt to cache prior GPU composition results,
    // which breaks that assumption, so zero out GPU composition time.
    if (outGpuCompositionDoneTime != nullptr
            && *outGpuCompositionDoneTime > 0 && (acquireTime > 0 || firstRefreshStartTime > 0)
            && *outGpuCompositionDoneTime <= std::max(acquireTime, firstRefreshStartTime)) {
        *outGpuCompositionDoneTime = 0;
    }

    return NO_ERROR;
}