From d11f38f6c5b4c2f9f8cdbcb2a0871bd83415bb52 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Tue, 12 Jan 2021 20:45:29 -1000 Subject: [PATCH] Send input event id to SurfaceFlinger The application receives input events and produces graphic buffers in response. We are interested in measuring the total time that the input event takes to process, from the moment it's received on the device, to the moment that the image is displayed on the screen. To do this, we need to understand which input event produced a specific buffer. In this CL, we are sending the input event id from FrameInfo to SurfaceFlinger. This event id will later be used to identify a specific frame, and provide the frame timing information to inputflinger. Inputflinger will be able to use this information to reconstruct the complete event timeline, and record metrics on the duration of each input / graphics processing stage. This will allow us to optimize end-to-end touch latency. In the current CL, we are using 'NewestInputEvent' as the inputEventId. That's not quite correct. Today, this field contains the timestamp of the input event. Therefore, we will simply pass the truncated timestamp instead of proper input event id. We will fix this in a separate CL by providing input event id to FrameInfo. Design doc: https://docs.google.com/document/d/1G3bLaZYSmbe6AKcL-6ZChvrw_B_LXEz29Z6Ed9QoYXY/edit# Bug: 169866723 Test: printed input event id at the site of SurfaceFrame creation in FrameTimeline.cpp Change-Id: Ia90337bb2f000e9c93a4db04d9dd6ea9ea153520 --- PREUPLOAD.cfg | 1 + core/jni/android_view_SurfaceControl.cpp | 4 +++- libs/hwui/renderthread/CanvasContext.cpp | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg index cdf5df6c6bd32..30ed7de92614d 100644 --- a/PREUPLOAD.cfg +++ b/PREUPLOAD.cfg @@ -8,6 +8,7 @@ clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp cmds/input/ cmds/uinput/ core/jni/ + libs/hwui/ libs/input/ native/ services/core/jni/ diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 4ef63ae930160..522e1422a4bb5 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1619,7 +1620,8 @@ static void nativeSetFrameTimelineVsync(JNIEnv* env, jclass clazz, jlong transac jlong frameTimelineVsyncId) { auto transaction = reinterpret_cast(transactionObj); - transaction->setFrameTimelineVsync(frameTimelineVsyncId); + transaction->setFrameTimelineInfo( + {frameTimelineVsyncId, android::os::IInputConstants::INVALID_INPUT_EVENT_ID}); } class JankDataListenerWrapper : public JankDataListener { diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index eacabfd1dbf9f..633f21ceba071 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -490,9 +490,11 @@ void CanvasContext::draw() { if (mNativeSurface) { // TODO(b/165985262): measure performance impact - if (const auto vsyncId = mCurrentFrameInfo->get(FrameInfoIndex::FrameTimelineVsyncId); - vsyncId != UiFrameInfoBuilder::INVALID_VSYNC_ID) { - native_window_set_frame_timeline_vsync(mNativeSurface->getNativeWindow(), vsyncId); + const auto vsyncId = mCurrentFrameInfo->get(FrameInfoIndex::FrameTimelineVsyncId); + if (vsyncId != UiFrameInfoBuilder::INVALID_VSYNC_ID) { + const auto inputEventId = mCurrentFrameInfo->get(FrameInfoIndex::NewestInputEvent); + native_window_set_frame_timeline_info(mNativeSurface->getNativeWindow(), vsyncId, + inputEventId); } }