Copy from DisplayEventReceiver.VsyncEventData

Fix for regression.

In the regressing CL, per-frame allocation of new VsyncEventData is
removed. Instead, a single VsyncEventData is written into with new data
each frame.
However, `mLastVsyncEventData` was assigned to reference that single
VsyncEventData, so the data inside can be changed underneath. To fix,
copy the data instead of storing the reference.

Bug: 272123078
Test: ABTD run with ATP from bugs and check metric
Change-Id: I39e51cadad61b5e496effc5c7d87d824ae97438a
This commit is contained in:
Rachel Lee
2023-03-14 13:52:47 -07:00
parent 3d2226d210
commit d483fa5b7f
2 changed files with 18 additions and 4 deletions

View File

@@ -195,7 +195,7 @@ public final class Choreographer {
private boolean mDebugPrintNextFrameTimeDelta;
private int mFPSDivisor = 1;
private DisplayEventReceiver.VsyncEventData mLastVsyncEventData =
private final DisplayEventReceiver.VsyncEventData mLastVsyncEventData =
new DisplayEventReceiver.VsyncEventData();
private final FrameData mFrameData = new FrameData();
@@ -857,7 +857,7 @@ public final class Choreographer {
mFrameScheduled = false;
mLastFrameTimeNanos = frameTimeNanos;
mLastFrameIntervalNanos = frameIntervalNanos;
mLastVsyncEventData = vsyncEventData;
mLastVsyncEventData.copyFrom(vsyncEventData);
}
AnimationUtils.lockAnimationClock(frameTimeNanos / TimeUtils.NANOS_PER_MS);
@@ -1247,7 +1247,7 @@ public final class Choreographer {
private boolean mHavePendingVsync;
private long mTimestampNanos;
private int mFrame;
private VsyncEventData mLastVsyncEventData = new VsyncEventData();
private final VsyncEventData mLastVsyncEventData = new VsyncEventData();
FrameDisplayEventReceiver(Looper looper, int vsyncSource, long layerHandle) {
super(looper, vsyncSource, /* eventRegistration */ 0, layerHandle);
@@ -1287,7 +1287,7 @@ public final class Choreographer {
mTimestampNanos = timestampNanos;
mFrame = frame;
mLastVsyncEventData = vsyncEventData;
mLastVsyncEventData.copyFrom(vsyncEventData);
Message msg = Message.obtain(mHandler, this);
msg.setAsynchronous(true);
mHandler.sendMessageAtTime(msg, timestampNanos / TimeUtils.NANOS_PER_MS);

View File

@@ -164,6 +164,12 @@ public abstract class DisplayEventReceiver {
this.deadline = deadline;
}
void copyFrom(FrameTimeline other) {
vsyncId = other.vsyncId;
expectedPresentationTime = other.expectedPresentationTime;
deadline = other.deadline;
}
// The frame timeline vsync id, used to correlate a frame
// produced by HWUI with the timeline data stored in Surface Flinger.
public long vsyncId = FrameInfo.INVALID_VSYNC_ID;
@@ -203,6 +209,14 @@ public abstract class DisplayEventReceiver {
this.frameInterval = frameInterval;
}
void copyFrom(VsyncEventData other) {
preferredFrameTimelineIndex = other.preferredFrameTimelineIndex;
frameInterval = other.frameInterval;
for (int i = 0; i < frameTimelines.length; i++) {
frameTimelines[i].copyFrom(other.frameTimelines[i]);
}
}
public FrameTimeline preferredFrameTimeline() {
return frameTimelines[preferredFrameTimelineIndex];
}