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

Commit 93d2d0b4 authored by Rachel Lee's avatar Rachel Lee
Browse files

NDK attached Choreographer from SurfaceControl.

The API to get a native attached choreographer from
ASurfaceControl.

Bug: 255838011
Test: atest ChoreographerTests
Test: atest ChoreographerNativeTest
Change-Id: I7ed0ebea9f735e102f2285edb3a1cc35b338c3c9
parent 18f2966f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ LIBANDROID_PLATFORM {
    extern "C++" {
        ASurfaceControl_registerSurfaceStatsListener*;
        ASurfaceControl_unregisterSurfaceStatsListener*;
        ASurfaceControl_getChoreographer*;
        ASurfaceControlStats_getAcquireTime*;
        ASurfaceControlStats_getFrameNumber*;
    };
+12 −0
Original line number Diff line number Diff line
@@ -180,6 +180,18 @@ void ASurfaceControl_unregisterSurfaceStatsListener(void* context,
            reinterpret_cast<void*>(func));
}

AChoreographer* ASurfaceControl_getChoreographer(ASurfaceControl* aSurfaceControl) {
    LOG_ALWAYS_FATAL_IF(aSurfaceControl == nullptr, "aSurfaceControl should not be nullptr");
    SurfaceControl* surfaceControl =
            ASurfaceControl_to_SurfaceControl(reinterpret_cast<ASurfaceControl*>(aSurfaceControl));
    if (!surfaceControl->isValid()) {
        ALOGE("Attempted to get choreographer from invalid surface control");
        return nullptr;
    }
    SurfaceControl_acquire(surfaceControl);
    return reinterpret_cast<AChoreographer*>(surfaceControl->getChoreographer().get());
}

int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
    if (const auto* fence = std::get_if<sp<Fence>>(&stats->acquireTimeOrFence)) {
        // We got a fence instead of the acquire time due to latch unsignaled.