From 6350ff0b3bf73ed651bcbaa001aa53be190edff8 Mon Sep 17 00:00:00 2001 From: Rachel Lee Date: Wed, 1 Sep 2021 13:30:13 -0700 Subject: [PATCH 1/2] Choreographer: new libandroid for CTS. Bug: 198191651 Test: make, atest ChoreographerNativeTest Change-Id: I5fd1bbefc77b45ec953e06b0ed5da8521dc08732 --- native/android/choreographer.cpp | 29 +++++++++++++++++++++++++++++ native/android/libandroid.map.txt | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/native/android/choreographer.cpp b/native/android/choreographer.cpp index 38641de0efb3e..deee5b173c214 100644 --- a/native/android/choreographer.cpp +++ b/native/android/choreographer.cpp @@ -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); +} diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt index f33e11817730b..29c1d8cc1385a 100644 --- a/native/android/libandroid.map.txt +++ b/native/android/libandroid.map.txt @@ -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; From 432b691184f24e938b50a1c0c9c51815224f2010 Mon Sep 17 00:00:00 2001 From: Rachel Lee Date: Wed, 1 Sep 2021 13:21:44 -0700 Subject: [PATCH 2/2] HWUI: use public choreographer api Bug: 198192636 Test: atest hwui_unit_tests Change-Id: Ic8b833d87d2ba381496cfcf7e21bb9557e9ba85f --- libs/hwui/renderthread/RenderThread.cpp | 69 +++++++++++++++---------- libs/hwui/renderthread/RenderThread.h | 4 +- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index f83c0a4926f9f..6755b7c081f44 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -16,8 +16,21 @@ #include "RenderThread.h" +#include +#include +#include +#include #include +#include +#include +#include +#include +#include + +#include + #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 -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - 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(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::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::max(), + systemTime(SYSTEM_TIME_MONOTONIC), 16_ms); } private: diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h index 0b81fc04edf56..c1f6790b25b2a 100644 --- a/libs/hwui/renderthread/RenderThread.h +++ b/libs/hwui/renderthread/RenderThread.h @@ -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();