From 93d2d0b43ec3e07cfe6b8c32a900f8d433b5f6d5 Mon Sep 17 00:00:00 2001 From: Rachel Lee Date: Fri, 6 Jan 2023 14:06:29 -0800 Subject: [PATCH] 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 --- native/android/libandroid.map.txt | 1 + native/android/surface_control.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt index 987b23fdd1fd1..f258c27aa070c 100644 --- a/native/android/libandroid.map.txt +++ b/native/android/libandroid.map.txt @@ -345,6 +345,7 @@ LIBANDROID_PLATFORM { extern "C++" { ASurfaceControl_registerSurfaceStatsListener*; ASurfaceControl_unregisterSurfaceStatsListener*; + ASurfaceControl_getChoreographer*; ASurfaceControlStats_getAcquireTime*; ASurfaceControlStats_getFrameNumber*; }; diff --git a/native/android/surface_control.cpp b/native/android/surface_control.cpp index ea20c6c9e0b14..b7f359602a5d9 100644 --- a/native/android/surface_control.cpp +++ b/native/android/surface_control.cpp @@ -180,6 +180,18 @@ void ASurfaceControl_unregisterSurfaceStatsListener(void* context, reinterpret_cast(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)); + if (!surfaceControl->isValid()) { + ALOGE("Attempted to get choreographer from invalid surface control"); + return nullptr; + } + SurfaceControl_acquire(surfaceControl); + return reinterpret_cast(surfaceControl->getChoreographer().get()); +} + int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) { if (const auto* fence = std::get_if>(&stats->acquireTimeOrFence)) { // We got a fence instead of the acquire time due to latch unsignaled.