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

Commit 798185e4 authored by Rachel Lee's avatar Rachel Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topic "choreo"

* changes:
  HWUI: use public choreographer api
  Choreographer: new libandroid for CTS.
parents 165b9352 432b6911
Loading
Loading
Loading
Loading
+43 −26
Original line number Diff line number Diff line
@@ -16,8 +16,21 @@

#include "RenderThread.h"

#include <GrContextOptions.h>
#include <android-base/properties.h>
#include <dlfcn.h>
#include <gl/GrGLInterface.h>
#include <gui/TraceUtils.h>
#include <sys/resource.h>
#include <ui/FatVector.h>
#include <utils/Condition.h>
#include <utils/Log.h>
#include <utils/Mutex.h>

#include <thread>

#include "../HardwareBitmapUploader.h"
#include "CacheManager.h"
#include "CanvasContext.h"
#include "DeviceInfo.h"
#include "EglManager.h"
@@ -31,19 +44,6 @@
#include "renderstate/RenderState.h"
#include "utils/TimeUtils.h"

#include <GrContextOptions.h>
#include <gl/GrGLInterface.h>

#include <dlfcn.h>
#include <sys/resource.h>
#include <utils/Condition.h>
#include <utils/Log.h>
#include <utils/Mutex.h>
#include <thread>

#include <android-base/properties.h>
#include <ui/FatVector.h>

namespace android {
namespace uirenderer {
namespace renderthread {
@@ -112,18 +112,31 @@ ASurfaceControlFunctions::ASurfaceControlFunctions() {
                        "Failed to find required symbol ASurfaceTransaction_setZOrder!");
}

void RenderThread::frameCallback(int64_t frameTimeNanos, void* data) {
void RenderThread::extendedFrameCallback(const AChoreographerFrameCallbackData* cbData,
                                         void* data) {
    RenderThread* rt = reinterpret_cast<RenderThread*>(data);
    int64_t vsyncId = AChoreographer_getVsyncId(rt->mChoreographer);
    int64_t frameDeadline = AChoreographer_getFrameDeadline(rt->mChoreographer);
    size_t preferredFrameTimelineIndex =
            AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(cbData);
    int64_t vsyncId = AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
            cbData, preferredFrameTimelineIndex);
    int64_t frameDeadline = AChoreographerFrameCallbackData_getFrameTimelineDeadline(
            cbData, preferredFrameTimelineIndex);
    int64_t frameTimeNanos = AChoreographerFrameCallbackData_getFrameTimeNanos(cbData);
    // TODO(b/193273294): Remove when shared memory in use w/ expected present time always current.
    int64_t frameInterval = AChoreographer_getFrameInterval(rt->mChoreographer);
    rt->mVsyncRequested = false;
    if (rt->timeLord().vsyncReceived(frameTimeNanos, frameTimeNanos, vsyncId, frameDeadline,
            frameInterval) && !rt->mFrameCallbackTaskPending) {
    rt->frameCallback(vsyncId, frameDeadline, frameTimeNanos, frameInterval);
}

void RenderThread::frameCallback(int64_t vsyncId, int64_t frameDeadline, int64_t frameTimeNanos,
                                 int64_t frameInterval) {
    mVsyncRequested = false;
    if (timeLord().vsyncReceived(frameTimeNanos, frameTimeNanos, vsyncId, frameDeadline,
                                 frameInterval) &&
        !mFrameCallbackTaskPending) {
        ATRACE_NAME("queue mFrameCallbackTask");
        rt->mFrameCallbackTaskPending = true;
        nsecs_t runAt = (frameTimeNanos + rt->mDispatchFrameDelay);
        rt->queue().postAt(runAt, [=]() { rt->dispatchFrameCallbacks(); });
        mFrameCallbackTaskPending = true;
        nsecs_t runAt = (frameTimeNanos + mDispatchFrameDelay);
        queue().postAt(runAt, [=]() { dispatchFrameCallbacks(); });
    }
}

@@ -139,8 +152,8 @@ public:
    ChoreographerSource(RenderThread* renderThread) : mRenderThread(renderThread) {}

    virtual void requestNextVsync() override {
        AChoreographer_postFrameCallback64(mRenderThread->mChoreographer,
                                           RenderThread::frameCallback, mRenderThread);
        AChoreographer_postExtendedFrameCallback(
                mRenderThread->mChoreographer, RenderThread::extendedFrameCallback, mRenderThread);
    }

    virtual void drainPendingEvents() override {
@@ -157,12 +170,16 @@ public:

    virtual void requestNextVsync() override {
        mRenderThread->queue().postDelayed(16_ms, [this]() {
            RenderThread::frameCallback(systemTime(SYSTEM_TIME_MONOTONIC), mRenderThread);
            mRenderThread->frameCallback(UiFrameInfoBuilder::INVALID_VSYNC_ID,
                                         std::numeric_limits<int64_t>::max(),
                                         systemTime(SYSTEM_TIME_MONOTONIC), 16_ms);
        });
    }

    virtual void drainPendingEvents() override {
        RenderThread::frameCallback(systemTime(SYSTEM_TIME_MONOTONIC), mRenderThread);
        mRenderThread->frameCallback(UiFrameInfoBuilder::INVALID_VSYNC_ID,
                                     std::numeric_limits<int64_t>::max(),
                                     systemTime(SYSTEM_TIME_MONOTONIC), 16_ms);
    }

private:
+3 −1
Original line number Diff line number Diff line
@@ -211,7 +211,9 @@ private:
    // corresponding callbacks for each display event type
    static int choreographerCallback(int fd, int events, void* data);
    // Callback that will be run on vsync ticks.
    static void frameCallback(int64_t frameTimeNanos, void* data);
    static void extendedFrameCallback(const AChoreographerFrameCallbackData* cbData, void* data);
    void frameCallback(int64_t vsyncId, int64_t frameDeadline, int64_t frameTimeNanos,
                       int64_t frameInterval);
    // Callback that will be run whenver there is a refresh rate change.
    static void refreshRateCallback(int64_t vsyncPeriod, void* data);
    void drainDisplayEventQueue();
+29 −0
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@ void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
    return AChoreographer_routePostFrameCallbackDelayed64(choreographer, callback, data,
                                                          delayMillis);
}
void AChoreographer_postExtendedFrameCallback(AChoreographer* choreographer,
                                              AChoreographer_extendedFrameCallback callback,
                                              void* data) {
    return AChoreographer_routePostExtendedFrameCallback(choreographer, callback, data);
}
void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer,
                                                AChoreographer_refreshRateCallback callback,
                                                void* data) {
@@ -50,3 +55,27 @@ void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer,
                                                  void* data) {
    return AChoreographer_routeUnregisterRefreshRateCallback(choreographer, callback, data);
}
int64_t AChoreographerFrameCallbackData_getFrameTimeNanos(
        const AChoreographerFrameCallbackData* data) {
    return AChoreographerFrameCallbackData_routeGetFrameTimeNanos(data);
}
size_t AChoreographerFrameCallbackData_getFrameTimelinesLength(
        const AChoreographerFrameCallbackData* data) {
    return AChoreographerFrameCallbackData_routeGetFrameTimelinesLength(data);
}
size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(
        const AChoreographerFrameCallbackData* data) {
    return AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(data);
}
int64_t AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
        const AChoreographerFrameCallbackData* data, size_t index) {
    return AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(data, index);
}
int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime(
        const AChoreographerFrameCallbackData* data, size_t index) {
    return AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentTime(data, index);
}
int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadline(
        const AChoreographerFrameCallbackData* data, size_t index) {
    return AChoreographerFrameCallbackData_routeGetFrameTimelineDeadline(data, index);
}
+7 −0
Original line number Diff line number Diff line
@@ -29,6 +29,13 @@ LIBANDROID {
    AChoreographer_postFrameCallbackDelayed64; # introduced=29
    AChoreographer_registerRefreshRateCallback; # introduced=30
    AChoreographer_unregisterRefreshRateCallback; # introduced=30
    AChoreographer_postExtendedFrameCallback;  # introduced=33
    AChoreographerFrameCallbackData_getFrameTimeNanos;  # introduced=33
    AChoreographerFrameCallbackData_getFrameTimelinesLength;  # introduced=33
    AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex;  # introduced=33
    AChoreographerFrameCallbackData_getFrameTimelineVsyncId;  # introduced=33
    AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentTime;  # introduced=33
    AChoreographerFrameCallbackData_getFrameTimelineDeadline;  # introduced=33
    AConfiguration_copy;
    AConfiguration_delete;
    AConfiguration_diff;