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

Commit 308baeb6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[hwui] Update dispatchFrameCallbacks to be called with...

Merge "[hwui] Update dispatchFrameCallbacks to be called with timeUntilDeadline/4 instead of timeUntilDeadline * 0.25f" into udc-dev
parents 38e6707c 9b641682
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -133,12 +133,23 @@ void RenderThread::frameCallback(int64_t vsyncId, int64_t frameDeadline, int64_t
    if (timeLord().vsyncReceived(frameTimeNanos, frameTimeNanos, vsyncId, frameDeadline,
                                 frameInterval) &&
        !mFrameCallbackTaskPending) {
        ATRACE_NAME("queue mFrameCallbackTask");
        mFrameCallbackTaskPending = true;

        nsecs_t timeUntilDeadline = frameDeadline - frameTimeNanos;
        nsecs_t runAt = (frameTimeNanos + (timeUntilDeadline * 0.25f));
        queue().postAt(runAt, [=]() { dispatchFrameCallbacks(); });
        using SteadyClock = std::chrono::steady_clock;
        using Nanos = std::chrono::nanoseconds;
        using toNsecs_t = std::chrono::duration<nsecs_t, std::nano>;
        using toFloatMillis = std::chrono::duration<float, std::milli>;

        const auto frameTimeTimePoint = SteadyClock::time_point(Nanos(frameTimeNanos));
        const auto deadlineTimePoint = SteadyClock::time_point(Nanos(frameDeadline));

        const auto timeUntilDeadline = deadlineTimePoint - frameTimeTimePoint;
        const auto runAt = (frameTimeTimePoint + (timeUntilDeadline / 4));

        ATRACE_FORMAT("queue mFrameCallbackTask to run after %.2fms",
                      toFloatMillis(runAt - SteadyClock::now()).count());
        queue().postAt(toNsecs_t(runAt.time_since_epoch()).count(),
                       [=]() { dispatchFrameCallbacks(); });
    }
}