diff options
author | 2021-10-11 15:09:51 -0700 | |
---|---|---|
committer | 2021-12-09 16:27:34 -0800 | |
commit | ed511efbdfac3408cb3ae237016f095fd64cebec (patch) | |
tree | d4c3d5a85a94c90939b74648a7282ccbf1a6d94e | |
parent | 772b32776fb14cce1f03ce87676aacaf9f877565 (diff) |
Add frame timeline method to ASurfaceControl NDK.
Bug: 198192003
Test: atest ASurfaceControlTest
perfetto trace
Change-Id: I04310bd9190cfc227ff5ba892c7187d3b8a20463
-rw-r--r-- | include/android/surface_control.h | 9 | ||||
-rw-r--r-- | libs/gui/FrameTimelineInfo.cpp | 5 | ||||
-rw-r--r-- | libs/gui/Surface.cpp | 3 | ||||
-rw-r--r-- | libs/gui/include/gui/FrameTimelineInfo.h | 3 | ||||
-rw-r--r-- | libs/nativewindow/include/system/window.h | 9 | ||||
-rw-r--r-- | services/surfaceflinger/FrameTimeline/FrameTimeline.cpp | 3 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 2 |
7 files changed, 28 insertions, 6 deletions
diff --git a/include/android/surface_control.h b/include/android/surface_control.h index 059bc41f9a..3a131045e8 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -595,6 +595,15 @@ void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction, bool enableBackPressure) __INTRODUCED_IN(31); +/** + * Sets the frame timeline to use. + * + * \param vsyncId The vsync ID received from AChoreographer, setting the frame's present target to + * the corresponding expected present time and deadline from the frame to be rendered. + */ +void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* transaction, + int64_t vsyncId) __INTRODUCED_IN(33); + __END_DECLS #endif // ANDROID_SURFACE_CONTROL_H diff --git a/libs/gui/FrameTimelineInfo.cpp b/libs/gui/FrameTimelineInfo.cpp index 9231a570fc..3800b88ab0 100644 --- a/libs/gui/FrameTimelineInfo.cpp +++ b/libs/gui/FrameTimelineInfo.cpp @@ -33,12 +33,14 @@ namespace android { status_t FrameTimelineInfo::write(Parcel& output) const { SAFE_PARCEL(output.writeInt64, vsyncId); SAFE_PARCEL(output.writeInt32, inputEventId); + SAFE_PARCEL(output.writeInt64, startTimeNanos); return NO_ERROR; } status_t FrameTimelineInfo::read(const Parcel& input) { SAFE_PARCEL(input.readInt64, &vsyncId); SAFE_PARCEL(input.readInt32, &inputEventId); + SAFE_PARCEL(input.readInt64, &startTimeNanos); return NO_ERROR; } @@ -48,16 +50,19 @@ void FrameTimelineInfo::merge(const FrameTimelineInfo& other) { if (other.vsyncId > vsyncId) { vsyncId = other.vsyncId; inputEventId = other.inputEventId; + startTimeNanos = other.startTimeNanos; } } else if (vsyncId == INVALID_VSYNC_ID) { vsyncId = other.vsyncId; inputEventId = other.inputEventId; + startTimeNanos = other.startTimeNanos; } } void FrameTimelineInfo::clear() { vsyncId = INVALID_VSYNC_ID; inputEventId = IInputConstants::INVALID_INPUT_EVENT_ID; + startTimeNanos = 0; } }; // namespace android diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 353a91d062..20c41460d4 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1846,9 +1846,10 @@ int Surface::dispatchSetFrameTimelineInfo(va_list args) { ATRACE_CALL(); auto frameTimelineVsyncId = static_cast<int64_t>(va_arg(args, int64_t)); auto inputEventId = static_cast<int32_t>(va_arg(args, int32_t)); + auto startTimeNanos = static_cast<int64_t>(va_arg(args, int64_t)); ALOGV("Surface::%s", __func__); - return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId}); + return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId, startTimeNanos}); } bool Surface::transformToDisplayInverse() const { diff --git a/libs/gui/include/gui/FrameTimelineInfo.h b/libs/gui/include/gui/FrameTimelineInfo.h index a23c20248c..255ce568d2 100644 --- a/libs/gui/include/gui/FrameTimelineInfo.h +++ b/libs/gui/include/gui/FrameTimelineInfo.h @@ -36,6 +36,9 @@ struct FrameTimelineInfo { // not directly vendor available. int32_t inputEventId = 0; + // The current time in nanoseconds the application started to render the frame. + int64_t startTimeNanos = 0; + status_t write(Parcel& output) const; status_t read(const Parcel& input); diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index 0bc2b5d312..a319769148 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -1025,10 +1025,11 @@ static inline int native_window_set_frame_rate(struct ANativeWindow* window, flo } static inline int native_window_set_frame_timeline_info(struct ANativeWindow* window, - int64_t frameTimelineVsyncId, - int32_t inputEventId) { - return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, - frameTimelineVsyncId, inputEventId); + int64_t frameTimelineVsyncId, + int32_t inputEventId, + int64_t startTimeNanos) { + return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, frameTimelineVsyncId, + inputEventId, startTimeNanos); } // ------------------------------------------------------------------------------------------------ diff --git a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp index 0c4e1120fc..86e96d769c 100644 --- a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp +++ b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp @@ -667,7 +667,8 @@ void SurfaceFrame::traceActuals(int64_t displayFrameToken) const { packet->set_timestamp( static_cast<uint64_t>(endTime - kPredictionExpiredStartTimeDelta)); } else { - packet->set_timestamp(static_cast<uint64_t>(mPredictions.startTime)); + packet->set_timestamp(static_cast<uint64_t>( + mActuals.startTime == 0 ? mPredictions.startTime : mActuals.startTime)); } auto* event = packet->set_frame_timeline_event(); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 495d585509..c3b2fa598f 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -1253,6 +1253,7 @@ std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransac getSequence(), mName, mTransactionName, /*isBuffer*/ false, getGameMode()); + surfaceFrame->setActualStartTime(info.startTimeNanos); // For Transactions, the post time is considered to be both queue and acquire fence time. surfaceFrame->setActualQueueTime(postTime); surfaceFrame->setAcquireFenceTime(postTime); @@ -1270,6 +1271,7 @@ std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, getSequence(), mName, debugName, /*isBuffer*/ true, getGameMode()); + surfaceFrame->setActualStartTime(info.startTimeNanos); // For buffers, acquire fence time will set during latch. surfaceFrame->setActualQueueTime(queueTime); const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |