Add inputEventId to SurfaceFrame
SurfaceFrame will now be aware of the id of the input event that caused
the current frame.
The flow of input event id is inputflinger -> app -> surfaceflinger.
Here, we are adding the 'inputEventId' parameter to the
'setFrameTimelineVsync' call. This call will now be responsible for
setting two pieces of information: the vsync id, and the input event id.
Since it will no longer be limited to the vsync id, we rename this call
to "setFrameTimelineInfo".
Once the inputEventId is stored in SurfaceFrame, we will add a binder
call to send the frame timing information to inputflinger (separate,
future CL). This will allow input to reconstruct the entire sequence of
events (at what time was input event getting processed in system_server,
app, and surfaceflinger) and will provide the ability to measure
end-to-end touch latency.
In a separate change, we will also add ATRACE calls to allow manual /
script-based latency analysis for local debugging. We will now know
which input event is being processed in surfaceflinger.
Bug: 169866723
Bug: 129481165
Design doc: https://docs.google.com/document/d/1G3bLaZYSmbe6AKcL-6ZChvrw_B_LXEz29Z6Ed9QoYXY/edit#
Test: atest WMShellUnitTests SurfaceParcelable_test libgui_test IPC_test SurfaceFlinger_test
Change-Id: If7e0eee82603b38b396b53ad7ced660973efcb50
Merged-In: If7e0eee82603b38b396b53ad7ced660973efcb50
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 27df232..8d448e0 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3287,7 +3287,7 @@
break;
}
transactions.push_back(transaction);
- applyTransactionState(transaction.frameTimelineVsyncId, transaction.states,
+ applyTransactionState(transaction.frameTimelineInfo, transaction.states,
transaction.displays, transaction.flags,
mPendingInputWindowCommands, transaction.desiredPresentTime,
transaction.isAutoTimestamp, transaction.buffer,
@@ -3367,7 +3367,7 @@
}
status_t SurfaceFlinger::setTransactionState(
- int64_t frameTimelineVsyncId, const Vector<ComposerState>& states,
+ const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states,
const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime,
bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
@@ -3420,7 +3420,7 @@
// if the transaction contains a buffer.
if (!transactionIsReadyToBeApplied(isAutoTimestamp, desiredPresentTime, states, true) ||
pendingTransactions) {
- mTransactionQueues[applyToken].emplace(frameTimelineVsyncId, states, displays, flags,
+ mTransactionQueues[applyToken].emplace(frameTimelineInfo, states, displays, flags,
desiredPresentTime, isAutoTimestamp, uncacheBuffer,
postTime, privileged, hasListenerCallbacks,
listenerCallbacks, originPid, originUid,
@@ -3429,7 +3429,7 @@
return NO_ERROR;
}
- applyTransactionState(frameTimelineVsyncId, states, displays, flags, inputWindowCommands,
+ applyTransactionState(frameTimelineInfo, states, displays, flags, inputWindowCommands,
desiredPresentTime, isAutoTimestamp, uncacheBuffer, postTime, privileged,
hasListenerCallbacks, listenerCallbacks, originPid, originUid,
transactionId, /*isMainThread*/ false);
@@ -3437,7 +3437,7 @@
}
void SurfaceFlinger::applyTransactionState(
- int64_t frameTimelineVsyncId, const Vector<ComposerState>& states,
+ const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states,
const Vector<DisplayState>& displays, uint32_t flags,
const InputWindowCommands& inputWindowCommands, const int64_t desiredPresentTime,
bool isAutoTimestamp, const client_cache_t& uncacheBuffer, const int64_t postTime,
@@ -3478,9 +3478,9 @@
uint32_t clientStateFlags = 0;
for (const ComposerState& state : states) {
clientStateFlags |=
- setClientStateLocked(frameTimelineVsyncId, state, desiredPresentTime,
- isAutoTimestamp, postTime, privileged,
- listenerCallbacksWithSurfaces, originPid, originUid);
+ setClientStateLocked(frameTimelineInfo, state, desiredPresentTime, isAutoTimestamp,
+ postTime, privileged, listenerCallbacksWithSurfaces, originPid,
+ originUid);
if ((flags & eAnimation) && state.state.surface) {
if (const auto layer = fromHandleLocked(state.state.surface).promote(); layer) {
mScheduler->recordLayerHistory(layer.get(),
@@ -3658,7 +3658,7 @@
}
uint32_t SurfaceFlinger::setClientStateLocked(
- int64_t frameTimelineVsyncId, const ComposerState& composerState,
+ const FrameTimelineInfo& frameTimelineInfo, const ComposerState& composerState,
int64_t desiredPresentTime, bool isAutoTimestamp, int64_t postTime, bool privileged,
std::unordered_set<ListenerCallbacks, ListenerCallbacksHash>& listenerCallbacks,
int originPid, int originUid) {
@@ -3916,10 +3916,10 @@
flags |= eTraversalNeeded;
}
}
- if (what & layer_state_t::eFrameTimelineVsyncChanged) {
- layer->setFrameTimelineVsyncForTransaction(s.frameTimelineVsyncId, postTime);
- } else if (frameTimelineVsyncId != ISurfaceComposer::INVALID_VSYNC_ID) {
- layer->setFrameTimelineVsyncForTransaction(frameTimelineVsyncId, postTime);
+ if (what & layer_state_t::eFrameTimelineInfoChanged) {
+ layer->setFrameTimelineInfoForTransaction(s.frameTimelineInfo, postTime);
+ } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) {
+ layer->setFrameTimelineInfoForTransaction(frameTimelineInfo, postTime);
}
if (what & layer_state_t::eFixedTransformHintChanged) {
if (layer->setFixedTransformHint(s.fixedTransformHint)) {
@@ -4255,7 +4255,7 @@
d.width = 0;
d.height = 0;
displays.add(d);
- setTransactionState(ISurfaceComposer::INVALID_VSYNC_ID, state, displays, 0, nullptr,
+ setTransactionState(FrameTimelineInfo{}, state, displays, 0, nullptr,
mPendingInputWindowCommands, systemTime(), true, {}, false, {},
0 /* Undefined transactionId */);
@@ -5006,7 +5006,7 @@
case CAPTURE_LAYERS:
case CAPTURE_DISPLAY:
case SET_DISPLAY_BRIGHTNESS:
- case SET_FRAME_TIMELINE_VSYNC:
+ case SET_FRAME_TIMELINE_INFO:
// This is not sensitive information, so should not require permission control.
case GET_GPU_CONTEXT_PRIORITY: {
return OK;
@@ -6374,21 +6374,21 @@
}));
}
-status_t SurfaceFlinger::setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface,
- int64_t frameTimelineVsyncId) {
+status_t SurfaceFlinger::setFrameTimelineInfo(const sp<IGraphicBufferProducer>& surface,
+ const FrameTimelineInfo& frameTimelineInfo) {
Mutex::Autolock lock(mStateLock);
if (!authenticateSurfaceTextureLocked(surface)) {
- ALOGE("Attempt to set frame timeline vsync on an unrecognized IGraphicBufferProducer");
+ ALOGE("Attempt to set frame timeline info on an unrecognized IGraphicBufferProducer");
return BAD_VALUE;
}
sp<Layer> layer = (static_cast<MonitoredProducer*>(surface.get()))->getLayer();
if (layer == nullptr) {
- ALOGE("Attempt to set frame timeline vsync on a layer that no longer exists");
+ ALOGE("Attempt to set frame timeline info on a layer that no longer exists");
return BAD_VALUE;
}
- layer->setFrameTimelineVsyncForBuffer(frameTimelineVsyncId);
+ layer->setFrameTimelineInfoForBuffer(frameTimelineInfo);
return NO_ERROR;
}